Fixes for sqlite data layer
This commit is contained in:
1 parent
7f9aa11d6e
commit
242b56fc21
9 files changed
+73
-67
No files matched your search
@@ -1,4 +1,5 @@
|
||||
use crate::data::entities::{CardState, DeckSettings};
|
||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
@@ -7,10 +8,11 @@ use fsrs::MemoryState;
|
||||
use log::info;
|
||||
use rusqlite::{Connection, Error, Params, Row, params};
|
||||
use std::time::Instant;
|
||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||
|
||||
pub type CardStateRepository = DataRepository<CardState, SqliteDbLayer<CardState, CardStatesQuerySet>>;
|
||||
pub type CardStateRepositoryInner = DataRepositoryInner<CardState, SqliteDbLayer<CardState, CardStatesQuerySet>>;
|
||||
pub type CardStateRepository =
|
||||
DataRepository<CardState, SqliteDbLayer<CardState, CardStatesQuerySet>>;
|
||||
pub type CardStateRepositoryInner =
|
||||
DataRepositoryInner<CardState, SqliteDbLayer<CardState, CardStatesQuerySet>>;
|
||||
#[derive(Clone)]
|
||||
pub struct CardStatesQuerySet;
|
||||
impl TableAccessQuerySet<CardState> for CardStatesQuerySet {
|
||||
@@ -19,11 +21,11 @@ impl TableAccessQuerySet<CardState> for CardStatesQuerySet {
|
||||
}
|
||||
|
||||
fn save() -> &'static str {
|
||||
"UPDATE states SET score = ?1, last_opened = ?2 WHERE id = ?3"
|
||||
"UPDATE states SET score = ?1, last_opened = ?2, fsrs_opened = ?3, fsrs_memory = ?4, fsrs_open_day = ?5 WHERE id = ?6"
|
||||
}
|
||||
|
||||
fn add() -> &'static str {
|
||||
"INSERT INTO states (word_id, deck_id, score, last_opened, fsrs_opened, fsrs_memory, fsrs_open_day) VALUES (?1, ?2, ?3, ?4) RETURNING id"
|
||||
"INSERT INTO states (word_id, deck_id, score, last_opened, fsrs_opened, fsrs_memory, fsrs_open_day) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)"
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
@@ -58,7 +60,14 @@ impl TableAccessQuerySet<CardState> for CardStatesQuerySet {
|
||||
}
|
||||
|
||||
fn update_params(entity: &CardState) -> impl Params {
|
||||
(entity.score, entity.last_open.timestamp(), entity.id)
|
||||
(
|
||||
entity.score,
|
||||
entity.last_open.timestamp(),
|
||||
entity.id,
|
||||
entity.fsrs_opened,
|
||||
memory_to_i64(&entity.fsrs_memory),
|
||||
entity.fsrs_open_day,
|
||||
)
|
||||
}
|
||||
}
|
||||
pub fn load_stats_of_deck(
|
||||
|
||||
Reference in new issue
Block a user