Oyelowo / oyestack

Foundation for highly scalable distributed web application with `Rustlang` for apps, `Typescript` and Kubernetes for Infra
https://codebreather.com
Apache License 2.0
0 stars 0 forks source link

380: Dont give up #381

Closed Oyelowo closed 1 year ago

Oyelowo commented 1 year ago

Purposes:

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);
    }));