2026-09-09 15:15:47 +03:00
|
|
|
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
|
|
|
|
2026-09-09 15:15:47 +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;
|
2026-09-09 15:15:47 +03:00
|
|
|
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
2026-08-31 11:25:41 +03:00
|
|
|
fn load() -> &'static str {
|
2026-09-09 15:15:47 +03:00
|
|
|
"SELECT id, name, identifier FROM custom_fields"
|
2026-08-31 11:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn save() -> &'static str {
|
2026-09-09 15:15:47 +03:00
|
|
|
"UPDATE custom_fields SET name = ?1, identifier = ?2 WHERE id = ?3"
|
2026-08-31 11:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn add() -> &'static str {
|
2026-09-09 15:15:47 +03:00
|
|
|
"INSERT INTO custom_fields (name, identifier) VALUES (?1, ?2)"
|
2026-08-31 11:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn name() -> &'static str {
|
|
|
|
|
"custom_fields"
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-09 15:15:47 +03:00
|
|
|
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)?,
|
2026-09-09 15:15:47 +03:00
|
|
|
identifier: row.get(2)?,
|
2026-08-31 11:25:41 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-09 15:15:47 +03:00
|
|
|
fn insert_params(entity: &CustomField) -> impl Params {
|
|
|
|
|
(&entity.name, &entity.identifier)
|
2026-08-31 11:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-09 15:15:47 +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
|
|
|
}
|