fix: edit + order
This commit is contained in:
1 parent
311f2fe7b4
commit
dbdce75996
3 files changed
+12
-11
No files matched your search
@@ -53,7 +53,7 @@ pub trait WordSource {
|
||||
fn find_by_word_and_lang(&self, word: &str, lang: &str) -> Vec<Word>;
|
||||
fn insert_word(&self, word: Word) -> Result<(), ()>;
|
||||
fn remove_word(&self, word_key: &str) -> Result<(), ()>;
|
||||
fn edit_word(&self, word: Word) -> Result<Word, ()>;
|
||||
fn edit_word(&self, word: Word, key: &str) -> Result<Word, ()>;
|
||||
fn normalize_word_key(word_key: &str) -> String;
|
||||
fn normalize_lang_key(word_key: &str) -> String;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ impl WordSource for FileDatabase {
|
||||
fn get_all_words(&self) -> Vec<Word> {
|
||||
let statement = self
|
||||
.connection
|
||||
.prepare("select key, description, lang from word");
|
||||
.prepare("select key, description, lang from word ORDER BY key ASC");
|
||||
let mut word_list: Vec<Word> = vec![];
|
||||
|
||||
// TODO: make this pretty with functional programming
|
||||
@@ -94,7 +94,7 @@ impl WordSource for FileDatabase {
|
||||
fn find_by_word(&self, word: &str) -> Vec<Word> {
|
||||
let statement = self
|
||||
.connection
|
||||
.prepare("SELECT key, description, lang FROM word");
|
||||
.prepare("SELECT key, description, lang FROM word ORDER BY key ASC");
|
||||
let mut word_list: Vec<Word> = vec![];
|
||||
|
||||
if let Ok(mut query) = statement {
|
||||
@@ -118,7 +118,7 @@ impl WordSource for FileDatabase {
|
||||
fn find_by_lang(&self, lang: &str) -> Vec<Word> {
|
||||
let statement = self
|
||||
.connection
|
||||
.prepare("select key, description, lang from word where lang = ?1");
|
||||
.prepare("select key, description, lang from word where lang = ?1 ORDER BY key ASC");
|
||||
let mut word_list: Vec<Word> = vec![];
|
||||
|
||||
// TODO: make this pretty with functional programming
|
||||
@@ -142,7 +142,7 @@ impl WordSource for FileDatabase {
|
||||
fn find_by_word_and_lang(&self, word: &str, lang: &str) -> Vec<Word> {
|
||||
let statement = self
|
||||
.connection
|
||||
.prepare("SELECT key, description, lang FROM word where lang = ?1");
|
||||
.prepare("SELECT key, description, lang FROM word where lang = ?1 ORDER BY key ASC");
|
||||
let mut word_list: Vec<Word> = vec![];
|
||||
|
||||
if let Ok(mut query) = statement {
|
||||
@@ -180,13 +180,14 @@ impl WordSource for FileDatabase {
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn edit_word(&self, word: Word) -> Result<Word, ()> {
|
||||
fn edit_word(&self, word: Word, key: &str) -> Result<Word, ()> {
|
||||
let result = self.connection.execute(
|
||||
"UPDATE word SET key = ?1, description = ?2, lang = ?3 WHERE key = ?1",
|
||||
"UPDATE word SET key = ?1, description = ?2, lang = ?3 WHERE key = ?4",
|
||||
(
|
||||
&Self::normalize_word_key(&word.key),
|
||||
&word.description,
|
||||
&Self::normalize_lang_key(&word.lang),
|
||||
key,
|
||||
),
|
||||
);
|
||||
match result {
|
||||
|
||||
Reference in new issue
Block a user