update dependencies and add rewrite urls

This commit is contained in:
2024-09-24 21:09:06 +02:00
parent c94df04eed
commit deec5840fc
8 changed files with 1468 additions and 540 deletions

View File

@@ -92,9 +92,9 @@ impl<'a> DatabasePole{
let mut statement = builder
.prepare("SELECT date FROM last WHERE id_group = ? order by date desc")
.unwrap();
statement.bind(1, group_id).unwrap();
statement.bind((1, group_id)).unwrap();
statement.next().unwrap();
statement.read::<String>(0)
statement.read::<String, _>(0)
}
pub fn write_points(&self, group_id : &str, user_id: &str, user_name: &str, date: &str, points: i64){
@@ -102,27 +102,27 @@ impl<'a> DatabasePole{
let mut statement = builder
.prepare("SELECT npole FROM poles WHERE user = ? AND id_group = ?")
.unwrap();
statement.bind(1, user_id).unwrap();
statement.bind(2, group_id).unwrap();
statement.bind((1, user_id)).unwrap();
statement.bind((2, group_id)).unwrap();
match statement.next().unwrap() {
State::Row => {
let mut statement2 = builder
.prepare("UPDATE poles SET npole=? WHERE user=? AND id_group=?")
.unwrap();
statement2.bind(1, statement.read::<i64>(0).unwrap()+points).unwrap();
statement2.bind(2, user_id).unwrap();
statement2.bind(3, group_id).unwrap();
statement2.bind((1, statement.read::<i64, _>(0).unwrap()+points)).unwrap();
statement2.bind((2, user_id)).unwrap();
statement2.bind((3, group_id)).unwrap();
statement2.next().unwrap();
}
State::Done => {
let mut statement2 = builder
.prepare("INSERT INTO poles (npole, user, user_name, id_group) VALUES (?,?,?,?)")
.unwrap();
statement2.bind(1, points).unwrap();
statement2.bind(2, user_id).unwrap();
statement2.bind(3, user_name).unwrap();
statement2.bind(4, group_id).unwrap();
statement2.bind((1, points)).unwrap();
statement2.bind((2, user_id)).unwrap();
statement2.bind((3, user_name)).unwrap();
statement2.bind((4, group_id)).unwrap();
statement2.next().unwrap();
}
@@ -131,10 +131,10 @@ impl<'a> DatabasePole{
let mut statement3 = builder
.prepare("INSERT INTO last (date, id_group, user, points) VALUES (?,?,?,?)")
.unwrap();
statement3.bind(1, date).unwrap();
statement3.bind(2, group_id).unwrap();
statement3.bind(3, user_id).unwrap();
statement3.bind(4, points).unwrap();
statement3.bind((1, date)).unwrap();
statement3.bind((2, group_id)).unwrap();
statement3.bind((3, user_id)).unwrap();
statement3.bind((4, points)).unwrap();
statement3.next().unwrap();
//while let State::Row = statement3.next().unwrap() {
// log::info!("name = {}", statement.read::<String>(0).unwrap());
@@ -146,11 +146,11 @@ impl<'a> DatabasePole{
let mut statement = builder
.prepare("SELECT points FROM last WHERE id_group = ? AND user = ? AND date = :date")
.unwrap();
statement.bind(1, group_id).unwrap();
statement.bind(2, user_id).unwrap();
statement.bind_by_name(":date", date).unwrap();
statement.bind((1, group_id)).unwrap();
statement.bind((2, user_id)).unwrap();
statement.bind((3, date)).unwrap();
match statement.next().unwrap() {
State::Row => statement.read::<i64>(0).unwrap(),
State::Row => statement.read::<i64, _>(0).unwrap(),
State::Done => 0,
}
}
@@ -158,12 +158,12 @@ impl<'a> DatabasePole{
pub fn check_group_points(&self, group_id : &str, date: &str) -> i64{
let builder = self.ins_connection.lock().unwrap();
let mut statement = builder
.prepare("SELECT points FROM last WHERE id_group = ? AND date = :date")
.prepare("SELECT points FROM last WHERE id_group = ? AND date = ?")
.unwrap();
statement.bind(1, group_id).unwrap();
statement.bind_by_name(":date", date).unwrap();
statement.bind((1, group_id)).unwrap();
statement.bind((2, date)).unwrap();
match statement.next().unwrap() {
State::Row => statement.read::<i64>(0).unwrap(),
State::Row => statement.read::<i64, _>(0).unwrap(),
State::Done => 0,
}
}
@@ -173,13 +173,13 @@ impl<'a> DatabasePole{
let mut statement = builder
.prepare("SELECT npole, user_name FROM poles where id_group=? order by npole desc limit 10")
.unwrap();
statement.bind(1, group_id).unwrap();
statement.bind((1, group_id)).unwrap();
let mut ret = Vec::new();
for i in 1 .. 10 {
match statement.next().unwrap() {
State::Row => ret.push((
statement.read::<i64>(0).unwrap(),
statement.read::<String>(1).unwrap()
statement.read::<i64, _>(0).unwrap(),
statement.read::<String, _>(1).unwrap()
)),
State::Done => return ret,
}