43 lines
885 B
Rust
43 lines
885 B
Rust
use owl::prelude::*;
|
|
|
|
#[model]
|
|
pub struct Stock {
|
|
pub id: Id,
|
|
}
|
|
|
|
#[model]
|
|
pub struct Owner {
|
|
pub id: Id,
|
|
}
|
|
|
|
#[relation("owner", Owner, "stock", Stock, RelationKind::Unidirectional)]
|
|
pub struct StockOrder {
|
|
amount: f64,
|
|
}
|
|
|
|
pub fn main() {
|
|
env_logger::init();
|
|
|
|
let db = Database::filesystem("./db");
|
|
|
|
let o = Owner { id: Id::new_ulid() };
|
|
let o = db.save(o);
|
|
|
|
let apl = Stock {
|
|
id: Id::String("APL".to_string()),
|
|
};
|
|
let apl = db.save(apl);
|
|
|
|
StockOrder { amount: 1.0 }.add(&o, &apl, None, &db);
|
|
|
|
for order in StockOrder::get_stock_of(&o, &db) {
|
|
let rel = db.get(order).unwrap();
|
|
|
|
println!(
|
|
"{} has {} {}",
|
|
StockOrder::owner(&rel, &db).read().id.to_string(),
|
|
StockOrder::meta(&rel).unwrap().amount,
|
|
StockOrder::stock(&rel, &db).read().id.to_string()
|
|
);
|
|
}
|
|
}
|