reformat custom fields table. will return to this topic later #18

Merged
micialware merged 1 commits from compressed-fields into master 2026-09-09 15:16:02 +03:00
8 changed files with 50 additions and 46 deletions
Showing only changes of commit c30be42822 - Show all commits

No files matched your search

+5 -3
View File
@@ -1,4 +1,6 @@
create table custom_fields(
id INTEGER PRIMARY KEY,
name TEXT not null
create table custom_fields
(
id integer primary key,
name text not null,
custom_fields text not null
);
+5 -5
View File
@@ -1,9 +1,9 @@
create table decks
(
id INTEGER
id integer
primary key autoincrement,
name TEXT not null,
forward TEXT not null,
backward TEXT not null,
filter TEXT not null
name text not null,
forward text not null,
backward text not null,
filter text not null
);
+8 -8
View File
@@ -1,12 +1,12 @@
create table history
(
id INTEGER
id integer
primary key autoincrement,
deck_id INTEGER not null references decks on delete cascade,
word_id INTEGER not null references words on delete cascade,
timestamp INTEGER not null,
answer INTEGER not null,
before INTEGER not null,
after INTEGER not null,
fsrs INTEGER not null
deck_id integer not null references decks on delete cascade,
word_id integer not null references words on delete cascade,
timestamp integer not null,
answer integer not null,
before integer not null,
after integer not null,
fsrs integer not null
);
+8 -8
View File
@@ -1,16 +1,16 @@
create table states
(
id INTEGER
id integer
primary key autoincrement,
word_id INTEGER not null
word_id integer not null
references words
on delete cascade,
deck_id INTEGER not null
deck_id integer not null
references decks
on delete cascade,
score INTEGER default 1 not null,
last_opened INTEGER not null,
fsrs_opened INTEGER not null,
fsrs_memory INTEGER not null,
fsrs_open_day INTEGER not null
score integer default 1 not null,
last_opened integer not null,
fsrs_opened integer not null,
fsrs_memory integer not null,
fsrs_open_day integer not null
);
+2 -2
View File
@@ -1,6 +1,6 @@
create table word_groups
(
id INTEGER
id integer
primary key autoincrement,
name TEXT not null
name text not null
);
+5 -5
View File
@@ -1,11 +1,11 @@
create table words
(
id INTEGER
id integer
primary key autoincrement,
key TEXT not null,
value TEXT not null,
tags TEXT not null,
more TEXT,
key text not null,
value text not null,
tags text not null,
more text,
group_id integer default 1 not null
constraint words_word_groups_id_fk
references word_groups
+1
View File
@@ -199,6 +199,7 @@ impl CardState {
pub struct CustomField {
pub id: Id,
pub name: String,
pub identifier: String,
}
pub struct EntityHandle<E> {
+16 -15
View File
@@ -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)
}
}