37 lines
888 B
Rust
37 lines
888 B
Rust
use rusqlite::{Error, Params, Row};
|
|||
|
|
use crate::data::entities::WordGroup;
|
||
|
|
use crate::data_provider::TableAccessQuerySet;
|
||
|
|
|
||
|
|
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 {
|
||
|
|
"INSERT INTO word_groups (name) VALUES (?1)"
|
||
|
|
}
|
||
|
|
|
||
|
|
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)
|
||
|
|
}
|
||
|
|
}
|