commit
6c54873ca2
34 changed files with 5502 additions and 0 deletions
43
examples/stock.rs
Normal file
43
examples/stock.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
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()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue