Custom fields table
This commit is contained in:
1 parent
6d363c8148
commit
2fc58fcc2d
4 files changed
+76
-34
No files matched your search
@@ -0,0 +1,37 @@
|
|||||||
|
use rusqlite::{Error, Params, Row};
|
||||||
|
use crate::data::entities::WordGroup;
|
||||||
|
use crate::data_provider::TableAccessQuerySet;
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,8 @@ pub(crate) mod sqlite;
|
|||||||
pub(crate) mod voice;
|
pub(crate) mod voice;
|
||||||
pub(crate) mod web_api;
|
pub(crate) mod web_api;
|
||||||
pub(crate) mod words;
|
pub(crate) mod words;
|
||||||
|
pub mod word_groups;
|
||||||
|
pub mod custom_fields;
|
||||||
|
|
||||||
pub trait TableAccessQuerySet<T> {
|
pub trait TableAccessQuerySet<T> {
|
||||||
fn load() -> &'static str;
|
fn load() -> &'static str;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
use rusqlite::{Error, Params, Row};
|
||||||
|
use crate::data::entities::WordGroup;
|
||||||
|
use crate::data_provider::TableAccessQuerySet;
|
||||||
|
|
||||||
|
pub struct WordGroupQuerySet;
|
||||||
|
impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
|
||||||
|
fn load() -> &'static str {
|
||||||
|
"SELECT id, name FROM word_groups"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save() -> &'static str {
|
||||||
|
"UPDATE word_groups SET name = ?1 WHERE id = ?2"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add() -> &'static str {
|
||||||
|
"INSERT INTO word_groups (name) VALUES (?1)"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name() -> &'static str {
|
||||||
|
"word_groups"
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,40 +58,6 @@ impl TableAccessQuerySet<WordData> for WordQuerySet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WordGroupQuerySet;
|
|
||||||
impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
|
|
||||||
fn load() -> &'static str {
|
|
||||||
"SELECT id, name FROM word_groups"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save() -> &'static str {
|
|
||||||
"UPDATE word_groups SET name = ?1 WHERE id = ?2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add() -> &'static str {
|
|
||||||
"INSERT INTO word_groups (name) VALUES (?1)"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"word_groups"
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_word(word: &mut WordData, connection: &Connection) -> MaybeError {
|
pub fn add_word(word: &mut WordData, connection: &Connection) -> MaybeError {
|
||||||
let index : u32 = connection
|
let index : u32 = connection
|
||||||
.query_row(
|
.query_row(
|
||||||
|
|||||||
Reference in new issue
Block a user