How to use the faunadb.query.Create 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 / todomvc-fauna-spa / src / Login.js View on Github external
["doSign Up"] () {
    console.log(this.state)
    publicClient.query(
      q.Create(q.Class("users"), {
        credentials : {
          password : this.state.password
        },
        // permissions : {
          // read : q.Select("ref", q.Get(q.Ref("classes/users/self")))
        // }
        data : {
          login : this.state.login
        }
    })).then(() => publicClient.query(
      q.Login(q.Match(q.Index("users_by_login"), this.state.login), {
        password : this.state.password
    }))).then((key) => {
      saveTokens(key.secret);
      this.authorized(true);
    });
github fauna / fauna-market / src / model.js View on Github external
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.
            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"))