New repo method
This commit is contained in:
1 parent
18aa748451
commit
8ec7c8f05d
2 files changed
+9
-2
No files matched your search
@@ -3,8 +3,6 @@ use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, OrderMode, WordOpenMode};
|
||||
use crate::data::{INVALID_ID, Id};
|
||||
use chrono::{DateTime, NaiveDate, Utc};
|
||||
use fsrs::MemoryState;
|
||||
use crate::notification::MaybeError;
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::info;
|
||||
use rayon::prelude::*;
|
||||
use rhai::{Engine, Scope};
|
||||
|
||||
@@ -20,6 +20,7 @@ where
|
||||
fn get_mut(&mut self, handle: &mut EntityHandle<T>) -> Option<&mut T>;
|
||||
fn handle_by_id(&self, id: Id) -> EntityHandle<T>;
|
||||
fn create(&mut self, new: T) -> EntityHandle<T>;
|
||||
fn create_now(&mut self, new: T) -> Result<EntityHandle<T>, NotificationData>;
|
||||
fn save(&mut self, entity: &mut EntityHandle<T>) -> MaybeError;
|
||||
fn delete(&mut self, handle: EntityHandle<T>) -> MaybeError;
|
||||
fn init(&mut self) -> MaybeError;
|
||||
@@ -317,6 +318,14 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
|
||||
entity
|
||||
}
|
||||
|
||||
fn create_now(&mut self, mut new: T) -> Result<EntityHandle<T>, NotificationData> {
|
||||
self.data_layer.add_entity(&mut new, &self.connection.read())?;
|
||||
let index = self.cache.len();
|
||||
let handle = EntityHandle::new(new.id(), index, true);
|
||||
self.cache.push(new);
|
||||
Ok(handle)
|
||||
}
|
||||
|
||||
fn save(&mut self, entity: &mut EntityHandle<T>) -> MaybeError {
|
||||
let original_state = entity.clone();
|
||||
if entity.real() {
|
||||
|
||||
Reference in new issue
Block a user