You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.9 KiB
79 lines
1.9 KiB
4 years ago
|
#[macro_use] extern crate log;
|
||
|
|
||
|
use log::LevelFilter;
|
||
|
|
||
|
mod yopa;
|
||
|
use yopa::model;
|
||
|
use yopa::model::DataType;
|
||
|
use crate::yopa::model::TypedValue;
|
||
|
use anyhow::Error;
|
||
|
|
||
|
fn main() {
|
||
|
simple_logging::log_to_stderr(LevelFilter::Debug);
|
||
|
|
||
|
if let Err(e) = _main() {
|
||
|
error!("{:?}", e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn _main() -> anyhow::Result<()> {
|
||
|
simple_logging::log_to_stderr(LevelFilter::Debug);
|
||
|
|
||
|
let mut store = yopa::InMemoryStorage::new();
|
||
|
|
||
|
let recipe_tid = store.insert_object_template(model::ObjectTemplate {
|
||
|
id: Default::default(),
|
||
|
name: "recipe".to_string(),
|
||
|
parent_tpl_id: None
|
||
|
})?;
|
||
|
|
||
|
store.insert_property_template(model::PropertyTemplate {
|
||
|
id: Default::default(),
|
||
|
parent_tpl_id: recipe_tid,
|
||
|
name: "title".to_string(),
|
||
|
optional: false,
|
||
|
multiple: false,
|
||
|
data_type: DataType::String,
|
||
|
default: None
|
||
|
})?;
|
||
|
|
||
|
store.insert_property_template(model::PropertyTemplate {
|
||
|
id: Default::default(),
|
||
|
parent_tpl_id: recipe_tid,
|
||
|
name: "prep_hours".to_string(),
|
||
|
optional: true,
|
||
|
multiple: false,
|
||
|
data_type: DataType::Decimal,
|
||
|
default: None
|
||
|
})?;
|
||
|
|
||
|
let book_tid = store.insert_object_template(model::ObjectTemplate {
|
||
|
id: Default::default(),
|
||
|
name: "book".to_string(),
|
||
|
parent_tpl_id: None
|
||
|
})?;
|
||
|
|
||
|
let br_rid = store.insert_relation_template(model::RelationTemplate {
|
||
|
id: Default::default(),
|
||
|
object_tpl_id: recipe_tid,
|
||
|
name: "book reference".to_string(),
|
||
|
optional: false,
|
||
|
multiple: false,
|
||
|
related_tpl_id: book_tid
|
||
|
})?;
|
||
|
|
||
|
store.insert_property_template(model::PropertyTemplate {
|
||
|
id: Default::default(),
|
||
|
parent_tpl_id: br_rid,
|
||
|
name: "page".to_string(),
|
||
|
optional: true,
|
||
|
multiple: false,
|
||
|
data_type: DataType::Integer,
|
||
|
default: None
|
||
|
})?;
|
||
|
|
||
|
debug!("{:#?}", store);
|
||
|
|
||
|
Ok(())
|
||
|
}
|