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
.idea/
yopa/target

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

@ -6,9 +6,9 @@ use model::{ObjectModel};
use insert::InsertObj;
use itertools::Itertools;
use std::borrow::Cow;
use model::Describe;
use insert::InsertValue;
use data::TypedValue;
mod cool;
@ -34,11 +34,11 @@ pub mod id {
pub type ID = u64;
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 {
let mut m = counter.lock();
let mut m = COUNTER.lock();
let v = *m;
*m += 1;
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_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 values.len() > 1 && !prop.multiple {
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_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 instances.len() > 1 && !relation_model.multiple {
return Err(StorageError::ConstraintViolation(format!("{} of {} cannot be set multiply", relation_model, obj_model).into()));

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

Loading…
Cancel
Save