Merge pull request 'reformat custom fields table. will return to this topic later' (#18) from compressed-fields into master
Reviewed-on: https://gitea.micialware.ru/micialware/jap_learn/pulls/18
This commit was merged in pull request #18.
This commit is contained in:
commit
097c3c033c
8 files changed
+50
-46
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
create table custom_fields(
|
create table custom_fields
|
||||||
id INTEGER PRIMARY KEY,
|
(
|
||||||
name TEXT not null
|
id integer primary key,
|
||||||
|
name text not null,
|
||||||
|
custom_fields text not null
|
||||||
);
|
);
|
||||||
+5
-5
@@ -1,9 +1,9 @@
|
|||||||
create table decks
|
create table decks
|
||||||
(
|
(
|
||||||
id INTEGER
|
id integer
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
name TEXT not null,
|
name text not null,
|
||||||
forward TEXT not null,
|
forward text not null,
|
||||||
backward TEXT not null,
|
backward text not null,
|
||||||
filter TEXT not null
|
filter text not null
|
||||||
);
|
);
|
||||||
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
create table history
|
create table history
|
||||||
(
|
(
|
||||||
id INTEGER
|
id integer
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
deck_id INTEGER not null references decks on delete cascade,
|
deck_id integer not null references decks on delete cascade,
|
||||||
word_id INTEGER not null references words on delete cascade,
|
word_id integer not null references words on delete cascade,
|
||||||
timestamp INTEGER not null,
|
timestamp integer not null,
|
||||||
answer INTEGER not null,
|
answer integer not null,
|
||||||
before INTEGER not null,
|
before integer not null,
|
||||||
after INTEGER not null,
|
after integer not null,
|
||||||
fsrs INTEGER not null
|
fsrs integer not null
|
||||||
);
|
);
|
||||||
+8
-8
@@ -1,16 +1,16 @@
|
|||||||
create table states
|
create table states
|
||||||
(
|
(
|
||||||
id INTEGER
|
id integer
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
word_id INTEGER not null
|
word_id integer not null
|
||||||
references words
|
references words
|
||||||
on delete cascade,
|
on delete cascade,
|
||||||
deck_id INTEGER not null
|
deck_id integer not null
|
||||||
references decks
|
references decks
|
||||||
on delete cascade,
|
on delete cascade,
|
||||||
score INTEGER default 1 not null,
|
score integer default 1 not null,
|
||||||
last_opened INTEGER not null,
|
last_opened integer not null,
|
||||||
fsrs_opened INTEGER not null,
|
fsrs_opened integer not null,
|
||||||
fsrs_memory INTEGER not null,
|
fsrs_memory integer not null,
|
||||||
fsrs_open_day INTEGER not null
|
fsrs_open_day integer not null
|
||||||
);
|
);
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
create table word_groups
|
create table word_groups
|
||||||
(
|
(
|
||||||
id INTEGER
|
id integer
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
name TEXT not null
|
name text not null
|
||||||
);
|
);
|
||||||
+5
-5
@@ -1,11 +1,11 @@
|
|||||||
create table words
|
create table words
|
||||||
(
|
(
|
||||||
id INTEGER
|
id integer
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
key TEXT not null,
|
key text not null,
|
||||||
value TEXT not null,
|
value text not null,
|
||||||
tags TEXT not null,
|
tags text not null,
|
||||||
more TEXT,
|
more text,
|
||||||
group_id integer default 1 not null
|
group_id integer default 1 not null
|
||||||
constraint words_word_groups_id_fk
|
constraint words_word_groups_id_fk
|
||||||
references word_groups
|
references word_groups
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ impl CardState {
|
|||||||
pub struct CustomField {
|
pub struct CustomField {
|
||||||
pub id: Id,
|
pub id: Id,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub identifier: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EntityHandle<E> {
|
pub struct EntityHandle<E> {
|
||||||
|
|||||||
@@ -1,41 +1,42 @@
|
|||||||
use crate::data::entities::{CustomField, WordGroup};
|
use crate::data::entities::CustomField;
|
||||||
use crate::data::repositories::DataRepository;
|
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
|
|
||||||
pub type CustomFieldRepository =
|
pub type CustomFieldRepository = DataRepository<CustomField, CustomFieldDbLayer>;
|
||||||
DataRepository<CustomField, SqliteDbLayer<CustomField, CustomFieldsQuerySet>>;
|
pub type CustomFieldRepositoryInner = DataRepositoryInner<CustomField, CustomFieldDbLayer>;
|
||||||
|
pub type CustomFieldDbLayer = SqliteDbLayer<CustomField, CustomFieldsQuerySet>;
|
||||||
pub struct CustomFieldsQuerySet;
|
pub struct CustomFieldsQuerySet;
|
||||||
impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
|
impl TableAccessQuerySet<CustomField> for CustomFieldsQuerySet {
|
||||||
fn load() -> &'static str {
|
fn load() -> &'static str {
|
||||||
"SELECT id, name FROM custom_fields"
|
"SELECT id, name, identifier FROM custom_fields"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save() -> &'static str {
|
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 {
|
fn add() -> &'static str {
|
||||||
"INSERT INTO word_groups (name) VALUES (?1)"
|
"INSERT INTO custom_fields (name, identifier) VALUES (?1, ?2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name() -> &'static str {
|
fn name() -> &'static str {
|
||||||
"custom_fields"
|
"custom_fields"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_sql(row: &Row) -> Result<WordGroup, Error> {
|
fn from_sql(row: &Row) -> Result<CustomField, Error> {
|
||||||
Ok(WordGroup {
|
Ok(CustomField {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
name: row.get(1)?,
|
name: row.get(1)?,
|
||||||
|
identifier: row.get(2)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_params(entity: &WordGroup) -> impl Params {
|
fn insert_params(entity: &CustomField) -> impl Params {
|
||||||
(&entity.name,)
|
(&entity.name, &entity.identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_params(entity: &WordGroup) -> impl Params {
|
fn update_params(entity: &CustomField) -> impl Params {
|
||||||
(&entity.name, entity.id)
|
(&entity.name, &entity.identifier, entity.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user