Files
jap_learn/src/data_provider/word_groups.rs
T

43 lines
1.2 KiB
Rust
Raw Normal View History

2026-09-04 17:26:59 +03:00
use crate::data::entities::WordGroup;
use crate::data::repositories::{DataRepository, DataRepositoryInner};
2026-08-31 11:52:54 +03:00
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
2026-08-31 11:26:05 +03:00
use rusqlite::{Error, Params, Row};
2026-08-31 11:52:54 +03:00
2026-09-02 00:19:58 +03:00
pub type WordGroupRepository = DataRepository<WordGroup, WordGroupDataLayer>;
pub type WordGroupRepositoryInner = DataRepositoryInner<WordGroup, WordGroupDataLayer>;
pub type WordGroupDataLayer = SqliteDbLayer<WordGroup, WordGroupQuerySet>;
2026-08-31 11:25:41 +03:00
2026-08-31 12:12:14 +03:00
#[derive(Clone)]
2026-08-31 11:25:41 +03:00
pub struct WordGroupQuerySet;
impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
fn load() -> &'static str {
"SELECT id, name FROM word_groups"
}
fn save() -> &'static str {
"UPDATE word_groups SET name = ?1 WHERE id = ?2"
}
fn add() -> &'static str {
2026-09-07 16:10:10 +03:00
"INSERT INTO word_groups (name) VALUES (?1) RETURNING id"
2026-08-31 11:25:41 +03:00
}
fn name() -> &'static str {
"word_groups"
}
fn from_sql(row: &Row) -> Result<WordGroup, Error> {
Ok(WordGroup {
id: row.get(0)?,
name: row.get(1)?,
})
}
fn insert_params(entity: &WordGroup) -> impl Params {
(&entity.name,)
}
fn update_params(entity: &WordGroup) -> impl Params {
(&entity.name, entity.id)
}
2026-08-31 11:26:05 +03:00
}