cargo fmt

This commit is contained in:
Elnu 2023-04-26 18:27:54 -07:00
parent ed11799bf5
commit c4eece7ffd
8 changed files with 113 additions and 53 deletions

View file

@ -1,8 +1,8 @@
use crate::word::Word;
use derive_more::From;
use rusqlite::{params, Connection, Result};
use std::path::PathBuf;
use rusqlite::{Connection, Result, params};
pub struct Database {
conn: Connection,
@ -46,10 +46,11 @@ impl Database {
.prepare("SELECT id FROM word ORDER BY id DESC LIMIT 1")?
.query_map(params![], |row| row.get(0))?
.collect::<Result<Vec<i64>>>()?
.first() {
Some(id) => *id,
None => 0, // first database entry is id 1
};
.first()
{
Some(id) => *id,
None => 0, // first database entry is id 1
};
Ok(Self { conn, last_word_id })
}
@ -70,10 +71,7 @@ impl Database {
pub fn add_word(&mut self, word: &Word) -> Result<()> {
self.conn.execute(
"INSERT INTO word (word, reading) VALUES (?1, ?2)",
params![
word.word,
word.reading,
],
params![word.word, word.reading,],
)?;
self.last_word_id += 1;
Ok(())