mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
fix db errors handle
This commit is contained in:
parent
be30ec660f
commit
57a8b5091f
@ -25,11 +25,16 @@ impl Bookmark {
|
|||||||
let memory = Rc::new(Memory::new());
|
let memory = Rc::new(Memory::new());
|
||||||
|
|
||||||
// Build initial index
|
// Build initial index
|
||||||
for record in database.records(None) {
|
match database.records(None) {
|
||||||
|
Ok(records) => {
|
||||||
|
for record in records {
|
||||||
if memory.add(record.request, record.id).is_err() {
|
if memory.add(record.request, record.id).is_err() {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Err(reason) => todo!("{reason}"),
|
||||||
|
}
|
||||||
|
|
||||||
// Return new `Self`
|
// Return new `Self`
|
||||||
Self { database, memory }
|
Self { database, memory }
|
||||||
|
@ -28,10 +28,10 @@ impl Database {
|
|||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Get bookmark records from database with optional filter by `request`
|
/// Get bookmark records from database with optional filter by `request`
|
||||||
pub fn records(&self, request: Option<&str>) -> Vec<Table> {
|
pub fn records(&self, request: Option<&str>) -> Result<Vec<Table>, Error> {
|
||||||
let readable = self.connection.read().unwrap();
|
let readable = self.connection.read().unwrap();
|
||||||
let tx = readable.unchecked_transaction().unwrap();
|
let tx = readable.unchecked_transaction()?;
|
||||||
select(&tx, *self.profile_id, request).unwrap()
|
select(&tx, *self.profile_id, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
@ -41,10 +41,10 @@ impl Database {
|
|||||||
pub fn add(&self, time: DateTime, request: String) -> Result<i64, Error> {
|
pub fn add(&self, time: DateTime, request: String) -> Result<i64, Error> {
|
||||||
// Begin new transaction
|
// Begin new transaction
|
||||||
let mut writable = self.connection.write().unwrap();
|
let mut writable = self.connection.write().unwrap();
|
||||||
let tx = writable.transaction().unwrap();
|
let tx = writable.transaction()?;
|
||||||
|
|
||||||
// Create new record
|
// Create new record
|
||||||
insert(&tx, *self.profile_id, time, request).unwrap();
|
insert(&tx, *self.profile_id, time, request)?;
|
||||||
|
|
||||||
// Hold insert ID for result
|
// Hold insert ID for result
|
||||||
let id = last_insert_id(&tx);
|
let id = last_insert_id(&tx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user