...
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::db::error::{DbError, DbResult};
|
||||
use crate::db::model::{Model, Storable};
|
||||
use crate::db::model::Model;
|
||||
use crate::db::store::{DbOperations, OurDbStore};
|
||||
use std::any::TypeId;
|
||||
use std::collections::HashMap;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use crate::db::error::{DbError, DbResult};
|
||||
use crate::db::model::Model;
|
||||
use crate::db::model::{Model, Storable};
|
||||
use ourdb::{OurDB, OurDBConfig, OurDBSetArgs};
|
||||
use std::marker::PhantomData;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -51,8 +51,8 @@ impl<T: Model> OurDbStore<T> {
|
||||
/// Inserts or updates a model instance in the database
|
||||
pub fn insert(&mut self, model: &T) -> DbResult<()> {
|
||||
let id = model.get_id();
|
||||
// Use the new method name from the Storable trait
|
||||
let data = T::to_bytes(model)?;
|
||||
// Use the new method name
|
||||
let data = model.to_bytes()?;
|
||||
|
||||
self.db.set(OurDBSetArgs {
|
||||
id: Some(id),
|
||||
@@ -71,7 +71,7 @@ impl<T: Model> OurDbStore<T> {
|
||||
}
|
||||
})?;
|
||||
|
||||
// Use the new method name from the Storable trait
|
||||
// Use the new method name
|
||||
T::from_bytes(&data)
|
||||
}
|
||||
|
||||
@@ -112,13 +112,13 @@ impl<T: Model> OurDbStore<T> {
|
||||
}
|
||||
|
||||
impl<T: Model> DbOperations for OurDbStore<T> {
|
||||
fn delete(&self, id: u32) -> DbResult<()> {
|
||||
fn delete(&self, _id: u32) -> DbResult<()> {
|
||||
// We need to mutably borrow self, but the trait requires &self
|
||||
// This is a design issue that needs to be fixed at the trait level
|
||||
Err(DbError::GeneralError("DbOperations trait needs to be updated to use &mut self".to_string()))
|
||||
}
|
||||
|
||||
fn get(&self, id: u32) -> DbResult<Box<dyn Any>> {
|
||||
fn get(&self, _id: u32) -> DbResult<Box<dyn Any>> {
|
||||
// We need to mutably borrow self, but the trait requires &self
|
||||
// This is a design issue that needs to be fixed at the trait level
|
||||
Err(DbError::GeneralError("DbOperations trait needs to be updated to use &mut self".to_string()))
|
||||
@@ -130,19 +130,19 @@ impl<T: Model> DbOperations for OurDbStore<T> {
|
||||
Ok(Box::new(result))
|
||||
}
|
||||
|
||||
fn insert(&self, model: &dyn Any) -> DbResult<()> {
|
||||
fn insert(&self, _model: &dyn Any) -> DbResult<()> {
|
||||
// We need to mutably borrow self, but the trait requires &self
|
||||
// This is a design issue that needs to be fixed at the trait level
|
||||
Err(DbError::GeneralError("DbOperations trait needs to be updated to use &mut self".to_string()))
|
||||
}
|
||||
|
||||
fn insert_raw(&self, serialized: &[u8]) -> DbResult<()> {
|
||||
fn insert_raw(&self, _serialized: &[u8]) -> DbResult<()> {
|
||||
// We need to mutably borrow self, but the trait requires &self
|
||||
// This is a design issue that needs to be fixed at the trait level
|
||||
Err(DbError::GeneralError("DbOperations trait needs to be updated to use &mut self".to_string()))
|
||||
}
|
||||
|
||||
fn get_history(&self, id: u32, depth: u8) -> DbResult<Vec<Box<dyn Any>>> {
|
||||
fn get_history(&self, _id: u32, _depth: u8) -> DbResult<Vec<Box<dyn Any>>> {
|
||||
// We need to mutably borrow self, but the trait requires &self
|
||||
// This is a design issue that needs to be fixed at the trait level
|
||||
Err(DbError::GeneralError("DbOperations trait needs to be updated to use &mut self".to_string()))
|
||||
|
@@ -132,23 +132,9 @@ impl Committee {
|
||||
|
||||
// Implement Storable trait
|
||||
impl Storable for Committee {
|
||||
fn to_bytes(&self) -> DbResult<Vec<u8>> {
|
||||
bincode::serialize(self).map_err(DbError::SerializationError)
|
||||
}
|
||||
|
||||
fn from_bytes(data: &[u8]) -> DbResult<Self> {
|
||||
bincode::deserialize(data).map_err(DbError::SerializationError)
|
||||
}
|
||||
}
|
||||
|
||||
impl Storable for CommitteeMember {
|
||||
fn to_bytes(&self) -> DbResult<Vec<u8>> {
|
||||
bincode::serialize(self).map_err(DbError::SerializationError)
|
||||
}
|
||||
|
||||
fn from_bytes(data: &[u8]) -> DbResult<Self> {
|
||||
bincode::deserialize(data).map_err(DbError::SerializationError)
|
||||
}
|
||||
}
|
||||
|
||||
// Implement Model trait
|
||||
|
Reference in New Issue
Block a user