2026-09-09 15:00:52 +03:00
|
|
|
use crate::data::entities::WordData;
|
2026-09-04 17:26:59 +03:00
|
|
|
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
2026-08-31 11:52:54 +03:00
|
|
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
2026-09-09 15:00:52 +03:00
|
|
|
use rusqlite::{Error, Params, Row};
|
2026-08-31 11:52:54 +03:00
|
|
|
|
2026-09-04 17:26:59 +03:00
|
|
|
pub type WordRepository = DataRepository<WordData, WordDataLayer>;
|
|
|
|
|
pub type WordRepositoryInner = DataRepositoryInner<WordData, WordDataLayer>;
|
2026-09-02 00:19:58 +03:00
|
|
|
pub type WordDataLayer = SqliteDbLayer<WordData, WordQuerySet>;
|
2026-08-31 12:12:14 +03:00
|
|
|
#[derive(Clone)]
|
2026-08-30 22:15:03 +03:00
|
|
|
pub struct WordQuerySet;
|
|
|
|
|
impl TableAccessQuerySet<WordData> for WordQuerySet {
|
|
|
|
|
fn load() -> &'static str {
|
|
|
|
|
"SELECT id, key, value, tags, more, group_id FROM words"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn save() -> &'static str {
|
|
|
|
|
"UPDATE words SET key = ?1, value = ?2, tags = ?3, more = ?4 WHERE id = ?5"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn add() -> &'static str {
|
2026-09-08 00:09:13 +03:00
|
|
|
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5)"
|
2026-08-30 22:15:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn name() -> &'static str {
|
|
|
|
|
"words"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_sql(row: &Row) -> Result<WordData, Error> {
|
|
|
|
|
let additional: String = row.get(4)?;
|
|
|
|
|
Ok(WordData {
|
|
|
|
|
id: row.get(0)?,
|
|
|
|
|
key: row.get(1)?,
|
|
|
|
|
value: row.get(2)?,
|
|
|
|
|
tags: row.get(3)?,
|
2026-08-31 11:26:05 +03:00
|
|
|
additional: serde_json::from_str(&additional).unwrap_or_default(),
|
2026-08-30 22:15:03 +03:00
|
|
|
group_id: row.get(5)?,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn insert_params(entity: &WordData) -> impl Params {
|
|
|
|
|
(
|
|
|
|
|
&entity.key,
|
|
|
|
|
&entity.value,
|
|
|
|
|
&entity.tags,
|
|
|
|
|
serde_json::to_string(&entity.additional).unwrap_or_default(),
|
|
|
|
|
entity.group_id,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_params(entity: &WordData) -> impl Params {
|
|
|
|
|
(
|
|
|
|
|
&entity.key,
|
|
|
|
|
&entity.value,
|
|
|
|
|
&entity.tags,
|
|
|
|
|
serde_json::to_string(&entity.additional).unwrap_or_default(),
|
|
|
|
|
entity.id,
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-09-09 15:00:52 +03:00
|
|
|
}
|