Create

Create( class_ref, parm_object )
Create( class_ref, param_object )
Create( class_ref, param_object )
Create( class_ref, param_object )
create( class_ref, param_object )
create class_ref, param_object
Create( class_ref, param_object )
Create( class_ref, param_object )

Description

The Create function adds a new instance to a class. The class_ref parameter indicates what class of instance should be created, while param_object contains the instance data and optional metadata.

Parameters

Argument Type Definition and Requirements

class_ref

Reference

A reference type specifying which class the instance should be created within.

param_object

Object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

data

Object

The user’s single, changeable document.

credentials

Object

The permissions for this instance.

delegates

Object

A group or delegates to check security. See delegates in the Security reference.

Returns

An instance object containing both the data and metadata about the results of the operations.

Field Name Field Type Definition and Requirements

ref

Reference

The reference is an automatically generated identifier within the database uniquely identifying the instance created.

data

Object

The data that was inserted with the instance.

ts

Long

The timestamp associated with the creation of the instance.

Examples

The query below executes a create instance by providing a reference to the class "spells" and parameters object with a data field. The data field contains the user data to be inserted for this instance.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "create": { "class": "spells" },
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountainous Thunder",
                  "element": "air",
                  "cost": 15
                }
              }
            }
          }
        }'
client.Query(
  Create(
    Class("spells"),
    Obj(
      "data", Obj(
        "name", "Mountainous Thunder",
        "element", "air",
        "cost", 15
      )
    )));
System.out.println(
   client.query(
      Create(
            Class(Value("spells")),
            Obj(
               "data", Obj(
                          "name", Value("Mountainous Thunder"),
                          "element", Value("air"),
                          "cost", Value(15)
                       )
            ))
   ).get());
result, _ := client.Query(
    f.Create(
        f.Class("spells"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountainous Thunder",
                "element": "air",
                "cost": 15,
            },
        },
    ),
)

fmt.Println(result)
client.query(
  Create(
    Class("spells"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountainous Thunder",
        "element" -> "air",
        "cost" -> 15
      )
    )))
client.query(
  q.create(
    q.class_expr("spells"),
    {
      "data": {"name": "Mountainous Thunder", "element": "air", "cost": 15}
    }
  ))
$client.query do
  create class_('spells'),
         data: { name: 'Mountainous Thunder', element: 'air', cost: 15 }
end
client.query(
    Create(
        at: Class("spells"),
        Obj(
            "data" => Obj(
                "name" => "Mountainous Thunder",
                "element" => "air",
                "cost" => 15
            )
        )
    )
)
client.query(
  q.Create(q.Class("spells"),
    { data: { name: "Mountainous Thunder", element: "air", cost: 15 } }))
.then((ret) => console.log(ret))
HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539709690,
    "data": {
      "name": "Mountainous Thunder",
      "element": "air",
      "cost": 15
    }
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}
{
  ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  ts: 1526674566636715,
  data: {
    name: "Mountainous Thunder",
    element: "air",
    cost: 15
  }
}
map[ref:{181388642581742080 0xc420215ee0 <nil>} ts:1509244539709690 data:map[cost:15 element:air name:Mountainous Thunder]]
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}
{
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}
{ ref:
  Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527274715273882,
  data: { name: 'Mountainous Thunder', element: 'air', cost: 15 } }