How to use the faunadb.query.Get 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
transactItem(item, player) {
    return this.client.query(
      q.Let({
        // Load the current player and item based on their refs.
        buyer : q.Get(player.ref),
        item : q.Get(item.ref)
      }, q.Let({
        // Load the seller account and set the transaction price.
        isForSale : q.Select(["data", "for_sale"], q.Var("item")),
        itemPrice : q.Select(["data", "price"], q.Var("item")),
        buyerBalance : q.Select(["data", "credits"], q.Var("buyer")),
        seller : q.Get(q.Select(["data", "owner"], q.Var("item")))
      },
        // Check that the item is for sale.
        q.If(q.Not(q.Var("isForSale")),
          "purchase failed: item not for sale",
          q.If(q.Equals(q.Select("ref", q.Var("buyer")), q.Select("ref", q.Var("seller"))),
            // Attempting to buy an item you are selling, removes it from sale
            q.Do(
              q.Update(q.Select("ref", q.Var("item")), {
                data : {
                  for_sale : false
github fauna / fauna-market / src / model.js View on Github external
transactItem(item, player) {
    return this.client.query(
      q.Let({
        // Load the current player and item based on their refs.
        buyer : q.Get(player.ref),
        item : q.Get(item.ref)
      }, q.Let({
        // Load the seller account and set the transaction price.
        isForSale : q.Select(["data", "for_sale"], q.Var("item")),
        itemPrice : q.Select(["data", "price"], q.Var("item")),
        buyerBalance : q.Select(["data", "credits"], q.Var("buyer")),
        seller : q.Get(q.Select(["data", "owner"], q.Var("item")))
      },
        // Check that the item is for sale.
        q.If(q.Not(q.Var("isForSale")),
          "purchase failed: item not for sale",
          q.If(q.Equals(q.Select("ref", q.Var("buyer")), q.Select("ref", q.Var("seller"))),
            // Attempting to buy an item you are selling, removes it from sale
            q.Do(
              q.Update(q.Select("ref", q.Var("item")), {
                data : {
github fauna / fauna-market / src / model.js View on Github external
transactItem(item, player) {
    return this.client.query(
      q.Let({
        // Load the current player and item based on their refs.
        buyer : q.Get(player.ref),
        item : q.Get(item.ref)
      }, q.Let({
        // Load the seller account and set the transaction price.
        isForSale : q.Select(["data", "for_sale"], q.Var("item")),
        itemPrice : q.Select(["data", "price"], q.Var("item")),
        buyerBalance : q.Select(["data", "credits"], q.Var("buyer")),
        seller : q.Get(q.Select(["data", "owner"], q.Var("item")))
      },
        // Check that the item is for sale.
        q.If(q.Not(q.Var("isForSale")),
          "purchase failed: item not for sale",
          q.If(q.Equals(q.Select("ref", q.Var("buyer")), q.Select("ref", q.Var("seller"))),
            // Attempting to buy an item you are selling, removes it from sale
            q.Do(
              q.Update(q.Select("ref", q.Var("item")), {
                data : {
                  for_sale : false
                }
              }),
              "item removed from sale"
            ),
            // Check the credit balance of the purchasing player to ensure
            // they have available funds.
github fauna / fauna-market / src / model.js View on Github external
(row) => q.Let({row:q.Get(row)},
          q.Let({
            buyer : q.Get(q.Select(["data","buyer"], q.Var("row"))),
            seller : q.Get(q.Select(["data","seller"], q.Var("row"))),
            price : q.Select(["data","price"], q.Var("row")),
            item : q.Get(q.Select(["data","item"], q.Var("row")))
          },
          {
            buyer : q.Select(["data","name"], q.Var("buyer")),
            seller : q.Select(["data","name"], q.Var("seller")),
            price : q.Var("price"),
            label : q.Select(["data","label"], q.Var("item")),
            key : q.Select(["ref"], q.Var("row"))
          }
        ))
      )