reformat custom fields table. will return to this topic later
This commit is contained in:
1 parent
ace54b10e1
commit
c30be42822
8 files changed
+50
-46
No files matched your search
@@ -1,41 +1,42 @@
|
||||
use crate::data::entities::{CustomField, WordGroup};
|
||||
use crate::data::repositories::DataRepository;
|
||||
use crate::data::entities::CustomField;
|
||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||
use rusqlite::{Error, Params, Row};
|
||||
|
||||
pub type CustomFieldRepository =
|
||||
DataRepository<CustomField, SqliteDbLayer<CustomField, CustomFieldsQuerySet>>;
|
||||
|
||||
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
|
||||
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
|
||||
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
|
||||
pub struct CustomFieldsQuerySet;
|
||||
impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
|
||||
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
||||
fn load() -> &'static str {
|
||||
"SELECT id, name FROM custom_fields"
|
||||
"SELECT id, name, identifier FROM custom_fields"
|
||||
}
|
||||
|
||||
fn save() -> &'static str {
|
||||
"UPDATE custom_fields SET name = ?1 WHERE id = ?2"
|
||||
"UPDATE custom_fields SET name = ?1, identifier = ?2 WHERE id = ?3"
|
||||
}
|
||||
|
||||
fn add() -> &'static str {
|
||||
"INSERT INTO word_groups (name) VALUES (?1)"
|
||||
"INSERT INTO custom_fields (name, identifier) VALUES (?1, ?2)"
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
"custom_fields"
|
||||
}
|
||||
|
||||
fn from_sql(row: &Row) -> Result<WordGroup, Error> {
|
||||
Ok(WordGroup {
|
||||
fn from_sql(row: &Row) -> Result<CustomField, Error> {
|
||||
Ok(CustomField {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
identifier: row.get(2)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn insert_params(entity: &WordGroup) -> impl Params {
|
||||
(&entity.name,)
|
||||
fn insert_params(entity: &CustomField) -> impl Params {
|
||||
(&entity.name, &entity.identifier)
|
||||
}
|
||||
|
||||
fn update_params(entity: &WordGroup) -> impl Params {
|
||||
(&entity.name, entity.id)
|
||||
fn update_params(entity: &CustomField) -> impl Params {
|
||||
(&entity.name, &entity.identifier, entity.id)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user