Closed Oyelowo closed 1 year ago
Purposes:
block
queries
Example usage:
// Queries begin_transaction() .query(queries!( let balance = create(Balance { balance: amount_to_transfer, ..Default::default() }); create(Account { id: id1.clone(), balance: 135_605.16, }); create(Account { id: id2.clone(), balance: 91_031.31, }); update::<Account>(id1).set(acc.balance.increment_by(balance.with_path::<Balance>(E).balance)); update::<Account>(id2).set(acc.balance.decrement_by(amount_to_transfer)); )) .commit_transaction() .run(db.clone()) .await?; // Block block! { BEGIN TRANSACTION; let acc1 = create(Account { id: id1.clone(), balance: 135_605.16, }); let acc2 = create(Account { id: id2.clone(), balance: 91_031.31, }); let updated1 = update::<Account>(id1).set(acc.balance.increment_by(amount_to_transfer)); let update2 = update::<Account>(id2).set(acc.balance.decrement_by(amount_to_transfer)); COMMIT TRANSACTION; } .run(db.clone()) .await?; let created_stats_statement = create::<WeaponStats>(averageStrength.equal_to(block! { let strengths = select_value(strength).from(weapon); let total = math::sum!(strengths); let count = count!(strengths); return total.divide(count); }));
Purposes:
block
andqueries
macros for more complex type-checked combinations of queries.Example usage: