Insert

Insert( Ref, ts, Action, Param_Object )
Insert( Ref, ts, Action, Param_Object )
Insert( Ref, ts, Action, Param_Object )
Insert( Ref, ts, Action, Param_Object )
insert( Ref, ts, Action, Param_Object )
insert Ref, ts, Action, Param_Object
Insert( Ref, ts, Action, Param_Object )
Insert( Ref, ts, Action, Param_Object )

Description

The Insert function adds an event to an instance’s history at a specified timestamp.

Parameters

Argument Type Definition and Requirements

ref

Reference

A reference must refer to a user-defined class or a key to be modified. A reference to any other class results in an "invalid argument" error.

ts

Long

The time within the instance’s history that should be modified. Can be expressed as either a number of UNIX microseconds or as a time value.

action

String

The type of action (create, delete, update) to be inserted.

param_object

Object

The param_object is an object which can contain many items.

param_object

Field Name Field Type Definition and Requirements

data

Object

The instance’s user data to be modified.

credentials

Object

The instance’s credentials to be modified.

delegates

Object

The instance’s delegates to be modified.

Returns

An object containing the metadata about the insert operations.

Field Name Field Type Definition and Requirements

ts

Long

The time when the instance’s history was modified.

action

String

The timestamp associated with the removal of the data.

instance

Reference

The reference which identifies the instance’s history was updated.

data

Object

A copy of the instance data which was removed.

Examples

The query modifies the history of the "spells" class for the instance at id 181388642581742080, adding an instance create operation at timestamp 1 with the associated user data.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "insert": { "@ref": "classes/spells/181388642581742080" },
          "ts": 1,
          "action": "create",
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountain's Thunder",
                  "cost": 10,
                  "element": [ "air", "earth" ]
                }
              }
            }
          }
        }'
client.Query(
  Insert(
    Ref("classes/spells/181388642581742080"),
    ts: 1,
    action: "create",
    @params: Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "cost", 10,
        "element", Arr("air", "earth")
      )
    )));
System.out.println(
    client.query(
       Insert(
           Ref(Class("spells"), Value(181388642581742080L)),
           Value(1),
           Action.CREATE,
           Obj(
              "data", Obj(
                      "name", Value("Mountain's Thunder"),
                      "cost", Value(10),
                      "element", Arr(Value("air"), Value("earth"))
                      )
           )
       )
    ).get());
result, _ := client.Query(
    f.Insert(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        1,
        f.ActionCreate,
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "cost": 10,
                "element": f.Arr{"air", "earth"},
            },
        },
    ),
)

fmt.Println(result)
client.query(
  Insert(
    Ref("classes/spells/181388642581742080"),
    ts = 1,
    action = "create",
    params = Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "cost" -> 10,
        "element" -> Arr("air", "earth")
      )
    )))
client.query(
  q.insert(
    Ref("classes/spells/181388642581742080"),
    ts=1,
    action="create",
    params={
      "data": {
        "name": "Mountain's Thunder",
        "cost": 10,
        "element": ["air", "earth"]
      }
    }
  ))
$client.query do
  insert ref('classes/spells/181388642581742080'),
         1,
         'create',
         data: {
           name: "Mountain's Thunder",
           cost: 10,
           element: ['air', 'earth']
         }
end
client.query(
    Insert(
        ref: Ref("classes/spells/181388642581742080"),
        ts: 1,
        action: "create",
        params: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "cost" => 10,
                "element" => Arr("air", "earth")
            )
        )
    )
)
client.query(
  q.Insert(q.Ref(q.Class("spells"), "181388642581742080"), 1, "create", { data: {
    name: "Mountain's Thunder",
    cost: 10,
    element: ["air", "earth"]
  }}))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "ts": 1,
    "action": "create",
    "resource": { "@ref": "classes/spells/181388642581742080" }
  }
}
{
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}
{
  ts: 1,
  action: "create"
  instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  data: {
    name: "Mountain's Thunder",
    cost: 10,
    element: ["air", "earth"]
  }
}
map[ts:1 action:create instance:{181388642581742080 0xc420254480 <nil>} data:map[name:Mountain's Thunder cost:10 element:[air earth]]]
{
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}
{
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}
{
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}
{
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}
{ ts: 1,
  action: 'create',
  instance:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  data:
   { name: 'Mountain\'s Thunder',
     cost: 10,
     element: [ 'air', 'earth' ] } }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!