init
Some checks failed
ci/woodpecker/push/test Pipeline failed

This commit is contained in:
JMARyA 2025-04-28 18:53:21 +02:00
commit 6c54873ca2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
34 changed files with 5502 additions and 0 deletions

43
examples/stock.rs Normal file
View 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()
);
}
}