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