move lib to separate folder

master
Ondřej Hruška 4 years ago
parent 77e1cf023b
commit 57fd444f4e
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 71
      Cargo.lock
  2. 7
      Cargo.toml
  3. 19
      src/main.rs
  4. 20
      yopa/Cargo.toml
  5. 0
      yopa/src/cool.rs
  6. 91
      yopa/src/lib.rs

71
Cargo.lock generated

@ -29,6 +29,15 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "instant"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.0" version = "0.10.0"
@ -56,6 +65,15 @@ version = "0.2.85"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
[[package]]
name = "lock_api"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312"
dependencies = [
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.14"
@ -65,6 +83,31 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "parking_lot"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.24" version = "1.0.24"
@ -95,6 +138,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.123" version = "1.0.123"
@ -137,6 +186,12 @@ dependencies = [
"thread-id", "thread-id",
] ]
[[package]]
name = "smallvec"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.60" version = "1.0.60"
@ -229,10 +284,24 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools", "itertools",
"lazy_static",
"log", "log",
"parking_lot",
"serde", "serde",
"serde_json", "serde_json",
"simple-logging",
"thiserror", "thiserror",
"uuid", "uuid",
] ]
[[package]]
name = "yopa-test"
version = "0.1.0"
dependencies = [
"anyhow",
"log",
"serde",
"serde_json",
"simple-logging",
"thiserror",
"yopa",
]

@ -1,5 +1,5 @@
[package] [package]
name = "yopa" name = "yopa-test"
version = "0.1.0" version = "0.1.0"
authors = ["Ondřej Hruška <ondra@ondrovo.com>"] authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
edition = "2018" edition = "2018"
@ -10,11 +10,10 @@ edition = "2018"
log = "0.4.13" log = "0.4.13"
simple-logging = "2.0.2" simple-logging = "2.0.2"
uuid = { version = "0.8", features = ["serde", "v4"] } yopa = { path = "./yopa" }
serde_json = "1.0.61" serde_json = "1.0.61"
serde = { version = "1.0.120", features = ["derive"] } serde = { version = "1.0.120", features = ["derive"] }
#parking_lot = "0.11.1"
anyhow = "1.0.38" anyhow = "1.0.38"
thiserror = "1.0.23" thiserror = "1.0.23"
itertools = "0.10.0"

@ -2,14 +2,12 @@
use log::LevelFilter; use log::LevelFilter;
mod yopa; use yopa;
use yopa::model; use yopa::model;
use yopa::model::DataType; use yopa::model::DataType;
use crate::yopa::insert::{InsertObj, InsertValue, InsertRel}; use crate::yopa::insert::{InsertObj, InsertValue, InsertRel};
use crate::yopa::data::TypedValue; use crate::yopa::data::TypedValue;
mod cool;
fn main() { fn main() {
simple_logging::log_to_stderr(LevelFilter::Debug); simple_logging::log_to_stderr(LevelFilter::Debug);
@ -89,10 +87,7 @@ fn _main() -> anyhow::Result<()> {
let MyBook1 = store.insert_object(InsertObj { let MyBook1 = store.insert_object(InsertObj {
model_id: Book, model_id: Book,
values: vec![ values: vec![
InsertValue { InsertValue::new(BookName, TypedValue::String("Recipe Book 1".into())),
model_id: BookName,
value: TypedValue::String("Recipe Book 1".into()),
}
], ],
relations: vec![], relations: vec![],
})?; })?;
@ -100,20 +95,14 @@ fn _main() -> anyhow::Result<()> {
store.insert_object(InsertObj { store.insert_object(InsertObj {
model_id: Recipe, model_id: Recipe,
values: vec![ values: vec![
InsertValue { InsertValue::new(RecipeTitle, TypedValue::String("Pancakes".into())),
model_id: RecipeTitle,
value: TypedValue::String("Pancakes".into()),
}
], ],
relations: vec![ relations: vec![
InsertRel { InsertRel {
model_id: BookToRecipe, model_id: BookToRecipe,
related_id: MyBook1, related_id: MyBook1,
values: vec![ values: vec![
InsertValue { InsertValue::new(BookToRecipePage, TypedValue::Integer(123))
model_id: BookToRecipePage,
value: TypedValue::Integer(123),
}
] ]
} }
], ],

@ -0,0 +1,20 @@
[package]
name = "yopa"
version = "0.1.0"
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.13"
uuid = { version = "0.8", features = ["serde", "v4"] }
serde_json = "1.0.61"
serde = { version = "1.0.120", features = ["derive"] }
parking_lot = "0.11.1"
anyhow = "1.0.38"
thiserror = "1.0.23"
itertools = "0.10.0"
lazy_static = "1.4.0"

@ -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")]
Loading…
Cancel
Save