master
Ondřej Hruška 4 years ago
parent 444800b5a6
commit be70c7f497
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      .gitignore
  2. 10
      yopa/src/data.rs
  3. 12
      yopa/src/lib.rs
  4. 2
      yopa/src/model.rs

1
.gitignore vendored

@ -1,2 +1,3 @@
/target /target
.idea/ .idea/
yopa/target

@ -3,8 +3,8 @@
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use crate::ID; use crate::ID;
use std::borrow::Cow; use std::borrow::Cow;
use crate::StorageError;
use std::num::ParseIntError;
use crate::model::DataType; use crate::model::DataType;
/// Value of a particular type /// Value of a particular type
@ -66,16 +66,14 @@ impl TypedValue {
(TypedValue::Integer(i), DataType::Boolean) => Ok(TypedValue::Boolean(i != 0)), (TypedValue::Integer(i), DataType::Boolean) => Ok(TypedValue::Boolean(i != 0)),
(e @ TypedValue::Decimal(_), DataType::Boolean) => Err(e), (e @ TypedValue::Decimal(_), DataType::Boolean) => Err(e),
(b @ TypedValue::Boolean(_), DataType::Boolean) => Ok(b), (b @ TypedValue::Boolean(_), DataType::Boolean) => Ok(b),
(s, _) => { //(s, _) => Err(s)
Err(s)
}
} }
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::TypedValue; use crate::data::TypedValue;
use crate::model::DataType; use crate::model::DataType;
#[test] #[test]

@ -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()));

@ -1,7 +1,7 @@
//! Data model structs and enums //! Data model structs and enums
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use std::borrow::Cow;
use super::ID; use super::ID;
use super::data::TypedValue; use super::data::TypedValue;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};

Loading…
Cancel
Save