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-08-31 11:52:54 +03:00
|
|
|
type CustomFieldRepository = DataRepository<CustomField, SqliteDbLayer<CustomField, CustomFieldsQuerySet>>;
|
|
|
|
|
|
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 {
|
|
|
|
|
"INSERT INTO word_groups (name) VALUES (?1)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|