Files
jap_learn/src/data_provider/custom_fields.rs
T

41 lines
1.1 KiB
Rust
Raw Normal View History

2026-08-31 11:52:54 +03:00
use crate::data::entities::{CustomField, WordGroup};
use crate::data::repositories::DataRepository;
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
2026-08-31 11:26:05 +03:00
use rusqlite::{Error, Params, Row};
2026-08-31 11:25:41 +03:00
2026-09-09 15:00:52 +03:00
pub type CustomFieldRepository =
DataRepository<CustomField, SqliteDbLayer<CustomField, CustomFieldsQuerySet>>;
2026-08-31 11:52:54 +03:00
2026-08-31 11:25:41 +03:00
pub struct CustomFieldsQuerySet;
impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
fn load() -> &'static str {
"SELECT id, name FROM custom_fields"
}
fn save() -> &'static str {
"UPDATE custom_fields SET name = ?1 WHERE id = ?2"
}
fn add() -> &'static str {
2026-09-08 00:09:13 +03:00
"INSERT INTO word_groups (name) VALUES (?1)"
2026-08-31 11:25:41 +03:00
}
fn name() -> &'static str {
"custom_fields"
}
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
}