Rename database tables to use plural names

This commit is contained in:
Manuel Vögele
2024-01-22 16:45:21 +01:00
parent 97ca239ee1
commit d338f89a15
6 changed files with 42 additions and 35 deletions

View File

@@ -102,8 +102,9 @@ async fn main() {
let now = Utc::now();
let next_appointment = db.lock().await.transaction(|db| {
use schema::chat::dsl::*;
chat.select(next_appointment_start)
use schema::chats::dsl::*;
chats
.select(next_appointment_start)
.filter(next_appointment_start.is_not_null())
.filter(next_appointment_start.gt(now.timestamp()))
.order(next_appointment_start.asc())
@@ -149,19 +150,19 @@ struct Reminder<Tz: TimeZone> {
// Additionally, checks if it is time for a reminder and sends that reminder if necessary
async fn check_task(bot: &Throttle<Bot>, config: &Config, db: &Database) -> Result<()> {
let chats = db.lock().await.transaction::<_, Error, _>(|db| {
use schema::chat::dsl::*;
use schema::reminder::dsl::*;
let chats = chat.load::<DbChat>(db)?;
use schema::chats::dsl::*;
use schema::reminders::dsl::*;
let db_chats = chats.load::<DbChat>(db)?;
let reminders: Vec<DbReminder> = DbReminder::belonging_to(&chats)
let db_reminders: Vec<DbReminder> = DbReminder::belonging_to(&db_chats)
.select(DbReminder::as_select())
.order(days_ahead.asc())
.load(db)?;
let reminders_per_chat = reminders
.grouped_by(&chats)
let reminders_per_chat = db_reminders
.grouped_by(&db_chats)
.into_iter()
.zip(chats)
.zip(db_chats)
.collect::<Vec<_>>();
Ok(reminders_per_chat)
@@ -241,8 +242,8 @@ async fn check_task(bot: &Throttle<Bot>, config: &Config, db: &Database) -> Resu
.await?;
db.lock().await.transaction(|db| {
use schema::chat::dsl::*;
diesel::update(chat.filter(telegram_id.eq(chat_info.id)))
use schema::chats::dsl::*;
diesel::update(chats.filter(telegram_id.eq(chat_info.id)))
.set((last_reminder.eq(now.timestamp()),))
.execute(db)
})?;