Decks rewritten
This commit is contained in:
1 parent
c9ccacc2d1
commit
9a5b64a4fe
1 file changed
+47
-2
@@ -1,9 +1,54 @@
|
|||||||
use crate::core::srs::OrderMode;
|
use crate::core::srs::OrderMode;
|
||||||
use crate::data::entities::DeckSettings;
|
use crate::data::entities::{CardState, DeckSettings};
|
||||||
|
use crate::data_provider::TableAccessQuerySet;
|
||||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||||
use crate::notification::{MaybeError, NotificationData};
|
use crate::notification::{MaybeError, NotificationData};
|
||||||
use rusqlite::Connection;
|
use chrono::NaiveDate;
|
||||||
|
use rusqlite::{Connection, Error, Params, Row};
|
||||||
|
|
||||||
|
pub struct DeckQuerySet;
|
||||||
|
impl TableAccessQuerySet<DeckSettings> for DeckQuerySet {
|
||||||
|
fn load() -> &'static str {
|
||||||
|
"SELECT id, name, forward, backward, filter FROM decks"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save() -> &'static str {
|
||||||
|
"UPDATE decks SET name = ?1, forward = ?2, backward = ?3, filter = ?4 WHERE id = ?5"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add() -> &'static str {
|
||||||
|
"INSERT INTO states (word_id, set_id, score, last_opened, fsrs_opened, fsrs_memory, fsrs_open_day) VALUES (?1, ?2, ?3, ?4)"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name() -> &'static str {
|
||||||
|
"decks"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_sql(row: &Row) -> Result<DeckSettings, Error> {
|
||||||
|
Ok(DeckSettings {
|
||||||
|
id: row.get(0)?,
|
||||||
|
name: row.get(1)?,
|
||||||
|
forward: row.get(2)?,
|
||||||
|
backward: row.get(3)?,
|
||||||
|
filter: row.get(4)?,
|
||||||
|
count: None,
|
||||||
|
open_mode: OrderMode::Default,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_params(entity: &DeckSettings) -> impl Params {
|
||||||
|
(
|
||||||
|
&entity.name,
|
||||||
|
&entity.forward,
|
||||||
|
&entity.backward,
|
||||||
|
&entity.filter,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_params(entity: &DeckSettings) -> impl Params {
|
||||||
|
(&entity.name, &entity.forward, &entity.backward, &entity.filter, entity.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, NotificationData> {
|
pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, NotificationData> {
|
||||||
let mut stmt = connection
|
let mut stmt = connection
|
||||||
|
|||||||
Reference in new issue
Block a user