diff --git a/Cargo.lock b/Cargo.lock index 871c1ab..8bc44a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3082,9 +3082,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", "getrandom 0.4.1", diff --git a/Cargo.toml b/Cargo.toml index 33c8c8a..bf66a10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,14 +5,14 @@ edition = "2024" [dependencies] iced = { version = "0.14.0", features = ["tokio"]} -rand = "0.10.0" +rand = "0.10.1" dirs = "6.0.0" -serde = { version = "1.0.144", features = ["derive"] } +serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.149" rhai = "1.24.0" chrono = "0.4.44" rusqlite = { version = "0.39.0", features = ["chrono"] } -reqwest = { version = "0.12", features = ["json", "stream"] } +reqwest = { version = "0", features = ["json", "stream"] } rodio = "0.22.2" sha2 = "0.11.0" hex = "0.4.3" diff --git a/src/data_provider/words.rs b/src/data_provider/words.rs index af20a0b..5063965 100644 --- a/src/data_provider/words.rs +++ b/src/data_provider/words.rs @@ -17,51 +17,68 @@ pub fn create_db() { fn create_tables(conn: &Connection) { conn.execute( - " - CREATE TABLE word_group ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL - ); - - insert into word_group (name) - values (\"Слова\"); - - CREATE TABLE words ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - key TEXT NOT NULL, - value TEXT NOT NULL, - tags TEXT NOT NULL, - more TEXT, - group_id INTEGER NOT NULL DEFAULT 1, - FOREIGN KEY(group_id) REFERENCES word_group(id) - ); - - CREATE TABLE card_stats ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - word_id INTEGER NOT NULL, - set_id TEXT NOT NULL, - score INTEGER NOT NULL DEFAULT 1, - last_opened INTEGER NOT NULL, - FOREIGN KEY (word_id) REFERENCES words (id) ON DELETE CASCADE, - FOREIGN KEY (set_id) REFERENCES card_set (id) ON DELETE CASCADE - ); - - - - CREATE TABLE card_set ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - forward TEXT NOT NULL, - backward TEXT NOT NULL, - filter TEXT NOT NULL - ); - ", + "create table card_set +( + id INTEGER + primary key autoincrement, + name TEXT not null, + forward TEXT not null, + backward TEXT not null, + filter TEXT not null +);", (), ) - .unwrap_or_else(|e| { - println!("{}", e); - 0 - }); + .unwrap(); + conn.execute( + "create table word_group +( + id INTEGER + primary key autoincrement, + name TEXT not null +);", + (), + ) + .unwrap(); + conn.execute( + "create table words +( + id INTEGER + primary key autoincrement, + key TEXT not null, + value TEXT not null, + tags TEXT not null, + more TEXT, + group_id integer default 1 not null + constraint words_word_group_id_fk + references word_group + on update cascade on delete cascade +);", + (), + ) + .unwrap(); + conn.execute( + "create table card_stats +( + id INTEGER + primary key autoincrement, + word_id INTEGER not null + references words + on delete cascade, + set_id TEXT not null + references card_set + on delete cascade, + score INTEGER default 1 not null, + last_opened integer not null +);", + (), + ) + .unwrap(); + conn.execute( + "insert into word_group (name) +values (\"Слова\");", + (), + ) + .unwrap(); } pub fn add_word(word: &mut WordData, connection: &Connection) { @@ -171,9 +188,7 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) { let index = connection .query_row( "INSERT INTO word_group (name) VALUES (?1) RETURNING id", - ( - &group.name, - ), + (&group.name,), |row| row.get(0), ) .unwrap_or_else(|e| { @@ -191,10 +206,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) { connection .execute( "UPDATE word_group SET name = ?1 WHERE id = ?5", - ( - &group.name, - &group.id, - ), + (&group.name, &group.id), ) .unwrap_or_else(|e| { println!("{}", e); @@ -213,4 +225,4 @@ pub fn delete_group(group: &WordGroup, connection: &Connection) { println!("{}", e); 0 }); -} \ No newline at end of file +}