Files
jap_learn/src/data_provider/custom_fields.rs
T

43 lines
1.4 KiB
Rust
Raw Normal View History

use crate::data::entities::CustomField;
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:25:41 +03:00
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
2026-09-11 13:28:23 +03:00
#[derive(Clone)]
2026-08-31 11:25:41 +03:00
pub struct CustomFieldsQuerySet;
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
2026-08-31 11:25:41 +03:00
fn load() -> &'static str {
"SELECT id, name, identifier FROM custom_fields"
2026-08-31 11:25:41 +03:00
}
fn save() -> &'static str {
"UPDATE custom_fields SET name = ?1, identifier = ?2 WHERE id = ?3"
2026-08-31 11:25:41 +03:00
}
fn add() -> &'static str {
"INSERT INTO custom_fields (name, identifier) VALUES (?1, ?2)"
2026-08-31 11:25:41 +03:00
}
fn name() -> &'static str {
"custom_fields"
}
fn from_sql(row: &Row) -> Result<CustomField, Error> {
Ok(CustomField {
2026-08-31 11:25:41 +03:00
id: row.get(0)?,
name: row.get(1)?,
identifier: row.get(2)?,
2026-08-31 11:25:41 +03:00
})
}
fn insert_params(entity: &CustomField) -> impl Params {
(&entity.name, &entity.identifier)
2026-08-31 11:25:41 +03:00
}
fn update_params(entity: &CustomField) -> impl Params {
(&entity.name, &entity.identifier, entity.id)
2026-08-31 11:25:41 +03:00
}
2026-08-31 11:26:05 +03:00
}