|
|
|
@ -10,9 +10,47 @@ use model::Describe; |
|
|
|
|
use insert::InsertValue; |
|
|
|
|
use data::TypedValue; |
|
|
|
|
|
|
|
|
|
/// Common identifier type
|
|
|
|
|
#[allow(non_camel_case_types)] |
|
|
|
|
pub type ID = uuid::Uuid; |
|
|
|
|
mod cool; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
pub mod id { |
|
|
|
|
/// Common identifier type
|
|
|
|
|
#[allow(non_camel_case_types)] |
|
|
|
|
pub type ID = uuid::Uuid; |
|
|
|
|
|
|
|
|
|
pub fn next_id() -> ID { |
|
|
|
|
uuid::Uuid::new_v4() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn zero_id() -> ID { |
|
|
|
|
uuid::Uuid::nil() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
pub mod id { |
|
|
|
|
/// Common identifier type
|
|
|
|
|
#[allow(non_camel_case_types)] |
|
|
|
|
pub type ID = u64; |
|
|
|
|
|
|
|
|
|
lazy_static::lazy_static! { |
|
|
|
|
static ref counter: parking_lot::Mutex<u64> = parking_lot::Mutex::new(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn next_id() -> ID { |
|
|
|
|
let mut m = counter.lock(); |
|
|
|
|
let v = *m; |
|
|
|
|
*m += 1; |
|
|
|
|
v |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn zero_id() -> ID { |
|
|
|
|
0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub use id::ID; |
|
|
|
|
use id::next_id; |
|
|
|
|
|
|
|
|
|
/// Data model structs and enums
|
|
|
|
|
pub mod model { |
|
|
|
@ -111,11 +149,11 @@ pub mod model { |
|
|
|
|
/// Data value structs
|
|
|
|
|
pub mod data { |
|
|
|
|
use serde::{Serialize, Deserialize}; |
|
|
|
|
use super::ID; |
|
|
|
|
use crate::ID; |
|
|
|
|
use std::borrow::Cow; |
|
|
|
|
use super::StorageError; |
|
|
|
|
use crate::StorageError; |
|
|
|
|
use std::num::ParseIntError; |
|
|
|
|
use crate::yopa::model::DataType; |
|
|
|
|
use crate::model::DataType; |
|
|
|
|
|
|
|
|
|
/// Value of a particular type
|
|
|
|
|
#[derive(Debug,Clone,Serialize,Deserialize,PartialEq)] |
|
|
|
@ -185,8 +223,8 @@ pub mod data { |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|
mod tests { |
|
|
|
|
use super::TypedValue; |
|
|
|
|
use crate::yopa::model::DataType; |
|
|
|
|
use crate::TypedValue; |
|
|
|
|
use crate::model::DataType; |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_cast_to_bool() { |
|
|
|
@ -315,6 +353,15 @@ pub mod insert { |
|
|
|
|
pub value: TypedValue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl InsertValue { |
|
|
|
|
pub fn new(model_id : ID, value : TypedValue) -> Self { |
|
|
|
|
Self { |
|
|
|
|
model_id, |
|
|
|
|
value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Info for inserting a relation
|
|
|
|
|
#[derive(Debug,Clone,Serialize,Deserialize)] |
|
|
|
|
pub struct InsertRel { |
|
|
|
@ -323,6 +370,16 @@ pub mod insert { |
|
|
|
|
pub values: Vec<InsertValue> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl InsertRel { |
|
|
|
|
pub fn new(model_id : ID, related_id: ID, values : Vec<InsertValue>) -> Self { |
|
|
|
|
Self { |
|
|
|
|
model_id, |
|
|
|
|
related_id, |
|
|
|
|
values |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Info for inserting a relation
|
|
|
|
|
#[derive(Debug,Clone,Serialize,Deserialize)] |
|
|
|
|
pub struct InsertObj { |
|
|
|
@ -330,6 +387,16 @@ pub mod insert { |
|
|
|
|
pub values: Vec<InsertValue>, |
|
|
|
|
pub relations: Vec<InsertRel>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl InsertObj { |
|
|
|
|
pub fn new(model_id : ID, values : Vec<InsertValue>, relations: Vec<InsertRel>) -> Self { |
|
|
|
|
Self { |
|
|
|
|
model_id, |
|
|
|
|
values, |
|
|
|
|
relations |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default)] |
|
|
|
@ -343,14 +410,6 @@ pub struct InMemoryStorage { |
|
|
|
|
properties: HashMap<ID, data::Value>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn next_id() -> ID { |
|
|
|
|
uuid::Uuid::new_v4() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn zero_id() -> ID { |
|
|
|
|
uuid::Uuid::nil() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug,Error)] |
|
|
|
|
pub enum StorageError { |
|
|
|
|
#[error("Referenced {0} does not exist")] |