Write SqlDbLayer
This commit is contained in:
1 parent
8ec7c8f05d
commit
45830a7985
7 files changed
+150
-19
No files matched your search
@@ -185,7 +185,7 @@ impl CardStatistics {
|
||||
#[derive(Copy)]
|
||||
pub struct EntityHandle<E> {
|
||||
pub(crate) id: Id,
|
||||
index: i32,
|
||||
index: u32,
|
||||
pub(crate) _phantom: PhantomData<E>,
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl<T> EntityHandle<T> {
|
||||
pub fn new(id: Id, index: usize, real: bool) -> Self {
|
||||
Self {
|
||||
id,
|
||||
index: index as i32 | (!real as i32) << 31,
|
||||
index: ((index as u32) << 1 >> 1) | (!real as u32) << 31,
|
||||
_phantom: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ impl<T> EntityHandle<T> {
|
||||
}
|
||||
|
||||
pub fn set_index(&mut self, index: usize) {
|
||||
self.index = self.index >> 31 << 31 | index as i32;
|
||||
self.index = (self.index >> 31 << 31) | ((index as u32) << 1 >> 1);
|
||||
}
|
||||
|
||||
pub fn real(&self) -> bool {
|
||||
@@ -219,7 +219,7 @@ impl<T> EntityHandle<T> {
|
||||
}
|
||||
|
||||
pub fn set_real(&mut self, value: bool) {
|
||||
self.index = self.index << 1 >> 1 | (!value as i32) << 31;
|
||||
self.index = self.index << 1 >> 1 | (!value as u32) << 31;
|
||||
}
|
||||
}
|
||||
impl<T> Eq for EntityHandle<T> {}
|
||||
|
||||
@@ -178,8 +178,8 @@ pub trait BatchedDbLayer<T>
|
||||
where
|
||||
T: EntityData,
|
||||
{
|
||||
fn delete_many_entities(&mut self, ids: &[Id], connection: &Connection) -> MaybeError;
|
||||
fn add_many_entities(&mut self, entity: &mut [T], connection: &Connection) -> MaybeError;
|
||||
fn delete_many_entities(&mut self, ids: &[Id], connection: &mut Connection) -> MaybeError;
|
||||
fn add_many_entities(&mut self, entity: &mut [T], connection: &mut Connection) -> MaybeError;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -414,7 +414,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
});
|
||||
|
||||
self.data_layer
|
||||
.add_many_entities(&mut temp_values, &self.connection.read())?;
|
||||
.add_many_entities(&mut temp_values, &mut self.connection.write())?;
|
||||
|
||||
let start = self.cache.len();
|
||||
|
||||
@@ -456,7 +456,7 @@ impl<T: EntityData + Clone, D: BatchedDbLayer<T> + DbLayer<T>> BatchedRepository
|
||||
!remove
|
||||
});
|
||||
self.data_layer
|
||||
.delete_many_entities(cached.as_slice(), &self.connection.read())?;
|
||||
.delete_many_entities(cached.as_slice(), &mut self.connection.write())?;
|
||||
let len = cached.len();
|
||||
cell = 0;
|
||||
self.cache.retain(|x| {
|
||||
|
||||
Reference in new issue
Block a user