|
|
@ -6,9 +6,9 @@ use model::{ObjectModel}; |
|
|
|
use insert::InsertObj; |
|
|
|
use insert::InsertObj; |
|
|
|
use itertools::Itertools; |
|
|
|
use itertools::Itertools; |
|
|
|
use std::borrow::Cow; |
|
|
|
use std::borrow::Cow; |
|
|
|
use model::Describe; |
|
|
|
|
|
|
|
use insert::InsertValue; |
|
|
|
use insert::InsertValue; |
|
|
|
use data::TypedValue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod cool; |
|
|
|
mod cool; |
|
|
|
|
|
|
|
|
|
|
@ -34,11 +34,11 @@ pub mod id { |
|
|
|
pub type ID = u64; |
|
|
|
pub type ID = u64; |
|
|
|
|
|
|
|
|
|
|
|
lazy_static::lazy_static! { |
|
|
|
lazy_static::lazy_static! { |
|
|
|
static ref counter: parking_lot::Mutex<u64> = parking_lot::Mutex::new(0); |
|
|
|
static ref COUNTER: parking_lot::Mutex<u64> = parking_lot::Mutex::new(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn next_id() -> ID { |
|
|
|
pub fn next_id() -> ID { |
|
|
|
let mut m = counter.lock(); |
|
|
|
let mut m = COUNTER.lock(); |
|
|
|
let v = *m; |
|
|
|
let v = *m; |
|
|
|
*m += 1; |
|
|
|
*m += 1; |
|
|
|
v |
|
|
|
v |
|
|
@ -219,7 +219,7 @@ impl InMemoryStorage { |
|
|
|
let mut values_by_id = values.into_iter().into_group_map_by(|iv| iv.model_id); |
|
|
|
let mut values_by_id = values.into_iter().into_group_map_by(|iv| iv.model_id); |
|
|
|
let mut values_to_insert = vec![]; |
|
|
|
let mut values_to_insert = vec![]; |
|
|
|
|
|
|
|
|
|
|
|
for (id, prop) in self.prop_models.iter().filter(|(id, p)| p.parent_tpl_id == parent_id) { |
|
|
|
for (id, prop) in self.prop_models.iter().filter(|(_id, p)| p.parent_tpl_id == parent_id) { |
|
|
|
if let Some(values) = values_by_id.remove(id) { |
|
|
|
if let Some(values) = values_by_id.remove(id) { |
|
|
|
if values.len() > 1 && !prop.multiple { |
|
|
|
if values.len() > 1 && !prop.multiple { |
|
|
|
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot have multiple values", prop, obj_model).into())); |
|
|
|
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot have multiple values", prop, obj_model).into())); |
|
|
@ -258,7 +258,7 @@ impl InMemoryStorage { |
|
|
|
let mut relations_by_id = insobj.relations.into_iter().into_group_map_by(|ir| ir.model_id); |
|
|
|
let mut relations_by_id = insobj.relations.into_iter().into_group_map_by(|ir| ir.model_id); |
|
|
|
let mut relations_to_insert = vec![]; |
|
|
|
let mut relations_to_insert = vec![]; |
|
|
|
|
|
|
|
|
|
|
|
for (relation_model_id, relation_model) in self.rel_models.iter().filter(|(id, r)| r.object_tpl_id == obj_model_id) { |
|
|
|
for (relation_model_id, relation_model) in self.rel_models.iter().filter(|(_id, r)| r.object_tpl_id == obj_model_id) { |
|
|
|
if let Some(instances) = relations_by_id.remove(relation_model_id) { |
|
|
|
if let Some(instances) = relations_by_id.remove(relation_model_id) { |
|
|
|
if instances.len() > 1 && !relation_model.multiple { |
|
|
|
if instances.len() > 1 && !relation_model.multiple { |
|
|
|
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot be set multiply", relation_model, obj_model).into())); |
|
|
|
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot be set multiply", relation_model, obj_model).into())); |
|
|
|