Migrate to Id type
This commit is contained in:
1 parent
99b3818181
commit
97c76350e1
12 files changed
+106
-62
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::lang::{WordData, WordGroup, INVALID_ID};
|
||||
use rusqlite::{Connection, params};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -20,7 +20,7 @@ pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||
0
|
||||
});
|
||||
|
||||
word.id = index;
|
||||
word.id = index.into();
|
||||
}
|
||||
|
||||
pub fn add_words(words: &mut [WordData], connection: &mut Connection) {
|
||||
@@ -59,12 +59,12 @@ pub fn add_words(words: &mut [WordData], connection: &mut Connection) {
|
||||
let start_index = last_index - (count as u32) + 1;
|
||||
|
||||
for (index, id) in (start_index..=last_index).enumerate() {
|
||||
words[index].id = id;
|
||||
words[index].id = id.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||
if word.id == 0 {
|
||||
if word.id == INVALID_ID {
|
||||
add_word(word, connection);
|
||||
} else {
|
||||
connection
|
||||
@@ -86,7 +86,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||
}
|
||||
|
||||
pub fn delete_word(word: &WordData, connection: &Connection) {
|
||||
if word.id == 0 {
|
||||
if word.id == INVALID_ID {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
@@ -156,11 +156,11 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) {
|
||||
0
|
||||
});
|
||||
|
||||
group.id = index;
|
||||
group.id = index.into();
|
||||
}
|
||||
|
||||
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||
if group.id == 0 {
|
||||
if group.id == INVALID_ID {
|
||||
add_group(group, connection);
|
||||
} else {
|
||||
connection
|
||||
@@ -176,7 +176,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||
}
|
||||
|
||||
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
||||
if group.id == 0 {
|
||||
if group.id == INVALID_ID {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
|
||||
Reference in new issue
Block a user