How to use the faunadb.query.Var function in faunadb

To help you get started, we’ve selected a few faunadb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fauna / fauna-market / src / model.js View on Github external
data : {
                    item : q.Select("ref", q.Var("item")),
                    price : q.Var("itemPrice"),
                    buyer : q.Select("ref", q.Var("buyer")),
                    seller : q.Select("ref", q.Var("seller"))
                  }
                }),
                // Update the balances of the selling player and the purchasing player.
                q.Update(q.Select("ref", q.Var("buyer")), {
                  data : {
                    credits : q.Subtract(q.Var("buyerBalance"), q.Var("itemPrice"))
                  }
                }),
                q.Update(q.Select("ref", q.Var("seller")), {
                  data : {
                    credits : q.Add(q.Select(["data", "credits"], q.Var("seller")), q.Var("itemPrice"))
                  }
                }),
                // Update the item with the new owner.
                q.Update(q.Select("ref", q.Var("item")), {
                  data : {
                    owner : q.Select("ref", q.Var("buyer")),
                    for_sale : false
                  }
                }),
                "purchase success"
              )
            )
          )
         )))
    );
  }
github fauna / fauna-market / src / model.js View on Github external
"purchase failed: insufficient funds",
              // All clear! Preconditions passed.
              q.Do(
                // Write a purchase record.
                q.Create(q.Class("purchases"), {
                  data : {
                    item : q.Select("ref", q.Var("item")),
                    price : q.Var("itemPrice"),
                    buyer : q.Select("ref", q.Var("buyer")),
                    seller : q.Select("ref", q.Var("seller"))
                  }
                }),
                // Update the balances of the selling player and the purchasing player.
                q.Update(q.Select("ref", q.Var("buyer")), {
                  data : {
                    credits : q.Subtract(q.Var("buyerBalance"), q.Var("itemPrice"))
                  }
                }),
                q.Update(q.Select("ref", q.Var("seller")), {
                  data : {
                    credits : q.Add(q.Select(["data", "credits"], q.Var("seller")), q.Var("itemPrice"))
                  }
                }),
                // Update the item with the new owner.
                q.Update(q.Select("ref", q.Var("item")), {
                  data : {
                    owner : q.Select("ref", q.Var("buyer")),
                    for_sale : false
                  }
                }),
                "purchase success"
              )
github fauna / fauna-market / src / model.js View on Github external
for_sale : false
                }
              }),
              "item removed from sale"
            ),
            // Check the credit balance of the purchasing player to ensure
            // they have available funds.
            q.If(q.LT(q.Var("buyerBalance"), q.Var("itemPrice")),
              "purchase failed: insufficient funds",
              // All clear! Preconditions passed.
              q.Do(
                // Write a purchase record.
                q.Create(q.Class("purchases"), {
                  data : {
                    item : q.Select("ref", q.Var("item")),
                    price : q.Var("itemPrice"),
                    buyer : q.Select("ref", q.Var("buyer")),
                    seller : q.Select("ref", q.Var("seller"))
                  }
                }),
                // Update the balances of the selling player and the purchasing player.
                q.Update(q.Select("ref", q.Var("buyer")), {
                  data : {
                    credits : q.Subtract(q.Var("buyerBalance"), q.Var("itemPrice"))
                  }
                }),
                q.Update(q.Select("ref", q.Var("seller")), {
                  data : {
                    credits : q.Add(q.Select(["data", "credits"], q.Var("seller")), q.Var("itemPrice"))
                  }
                }),
                // Update the item with the new owner.
github fauna / fauna-market / src / model.js View on Github external
(row) =>
        q.Let({doc : q.Get(row)}, {
          ref : q.Select(["ref"], q.Var("doc")),
          data : {
            label : q.Select(["data","label"], q.Var("doc")),
            price : q.Select(["data","price"], q.Var("doc")),
            owner : q.Select(["data","owner"], q.Var("doc")),
            owner_name :
              q.Select(["data","name"],
              q.Get(q.Select(["data","owner"], q.Var("doc"))))
          }
        })
      )