Events

Events( input )
Events( input )
Events( input )
Events( input )
events( input )
events( input )
Events( input )
Events( input )

Description

The Events function returns an array of events for the provided ref. These events represent the history of the ref, and demonstrate when the ref was created, modified, or removed.

The kinds of events vary based on the kind of ref provided:

Singular references
  • create

  • delete

  • update

Set references
  • add

  • remove

Parameter

Argument Type Definition and Requirements

input

Set or Ref

A Set of refs (or SetRef), or a singular reference.

Returns

A set containing the creation, modification, or deletion events related to the provided input. Each event in the set contains the following fields:

Field Name Field Type Definition and Requirements

action

String

The action applied to the instance during the event.

data

Object

Optional: only provided for documents containing user-supplied data. The data involved in the event.

instance

Reference

The reference identifies the document associated with the event.

ts

Long

The timestamp associated with the event.

Examples

The following query fetches the events for a regular document:

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "events": {
            "@ref": "classes/posts/233555580689580553"
          }
        }'
client.Query(
  Events(Ref(Collection("posts"), "233555580689580553"))
)
System.out.println(
    client.query(
        Events(Ref(Collection("posts"), "233555580689580553"))
    ).get()
);
result, err := client.Query(f.Events(f.RefClass(f.Collection("posts"), "233555580689580553")))

fmt.Println(result)
client.query(
    Events(Ref(Collection("posts"), "233555580689580553"))
)
client.query(
  q.events(q.ref(q.collection("posts"), "233555580689580553"))
)
puts $client.query {
  events ref collection("posts"), "233555580689580553"
}
client.query(
  Events(Ref(Collection("posts"), "233555580689580553"))
)
client.query(
  q.Events(q.Ref(q.Collection("posts"), "233555580689580553"))
).then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "@set": {
      "events": { "@ref": "classes/posts/233555580689580553" }
    }
  }
}
{@set = {events: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))}}
{@set = {events: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))}}
{map[events:{233546497131545088 0xc0001bc2e0 <nil>}]}
{@set = {events: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))}}
SetRef({'events': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes)))})
#<Fauna::SetRef:0x00007fc4838a7f10>
{@set = {events: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))}}
SetRef({ events: Ref(Class("posts"), "233555580689580553") })

And again, using Paginate to see the details of each event:

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "events": {
              "@ref": "classes/posts/233555580689580553"
            }
          }
        }'
client.Query(
  Paginate(Events(Ref(Collection("posts"), "233555580689580553")))
)
System.out.println(
    client.query(
        Paginate(Events(Ref(Collection("posts"), "233555580689580553")))
    ).get()
);
result, err := client.Query(
  f.Paginate(f.Events(f.RefClass(f.Collection("posts"),
  "233555580689580553"))))

fmt.Println(result)
client.query(
    Paginate(Events(Ref(Collection("posts"), "233555580689580553"))
)
client.query(
  q.paginate(q.events(q.ref(q.collection("posts"), "233555580689580553")))
)
puts $client.query {
  paginate events ref collection("posts"), "233555580689580553"
}
client.query(
  Paginate(Events(Ref(Collection("posts"), "233555580689580553")))
)
client.query(
  q.Paginate(q.Events(q.Ref(q.Collection("posts"), "233555580689580553")))
).then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1558994808800000,
        "action": "create",
        "resource": { "@ref": "classes/posts/233555580689580553" }
      },
      {
        "ts": 1558994916810000,
        "action": "create",
        "resource": { "@ref": "classes/posts/233555580689580553" }
      },
      {
        "ts": 1558994945460000,
        "action": "delete",
        "resource": { "@ref": "classes/posts/233555580689580553" }
      }
    ]
  }
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "create",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        title: "What I had for breakfast..."
      }
    },
    {
      ts: 1558994916810000,
      action: "update",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        tags: ["eggs", "toast"]
      }
    },
    {
      ts: 1558994945460000,
      action: "delete",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: NullV
    }
  ]
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "create",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        title: "What I had for breakfast..."
      }
    },
    {
      ts: 1558994916810000,
      action: "update",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        tags: ["eggs", "toast"]
      }
    },
    {
      ts: 1558994945460000,
      action: "delete",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: NullV
    }
  ]
}
map[data:[map[action:create data:map[title:What I had for breakfast...] instance:{233555580689580553 0xc0001d22c0 <nil>} ts:1558994808800000] map[action:update data:map[tags:[eggs toast]] instance:{233555580689580553 0xc0001d2600 <nil>} ts:1558994916810000] map[action:delete data:{} instance:{233555580689580553 0xc0001d29a0 <nil>} ts:1558994945460000]]]
{
  data: [
    {
      ts: 1558994808800000,
      action: "create",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        title: "What I had for breakfast..."
      }
    },
    {
      ts: 1558994916810000,
      action: "update",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        tags: ["eggs", "toast"]
      }
    },
    {
      ts: 1558994945460000,
      action: "delete",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: NullV
    }
  ]
}
{
  'data': [
    {
      'ts': 1558994808800000,
      'action': 'create',
      'instance': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes))),
      'data': {
        'title': 'What I had for breakfast...'
      }
    },
    {
      'ts': 1558994916810000,
      'action': 'update',
      'instance': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes))),
      'data': {
        'tags': ['eggs', 'toast']
      }
    },
    {
      'ts': 1558994945460000,
      'action': 'delete',
      'instance': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes))),
      'data': None
    }
  ]
}
{
  :data=>[
    {
      :ts=>1558994808800000,
      :action=>"create",
      :instance=>#<Fauna::Ref:0x00007fbc8e875ad0 @id="233555580689580553", @class_=#<Fauna::Ref:0x00007fbc8e875af8 @id="posts", @class_=#<Fauna::Ref:0x00007fbc90238350 @id="classes">>>,
      :data=>{
        :title=>"What I had for breakfast..."
      }
    },
    {
      :ts=>1558994916810000,
      :action=>"update",
      :instance=>#<Fauna::Ref:0x00007fbc8e8758c8 @id="233555580689580553", @class_=#<Fauna::Ref:0x00007fbc8e8758f0 @id="posts", @class_=#<Fauna::Ref:0x00007fbc90238350 @id="classes">>>,
      :data=>{
        :tags=>["eggs", "toast"]
      }
    },
    {
      :ts=>1558994945460000,
      :action=>"delete",
      :instance=>#<Fauna::Ref:0x00007fbc8e875698 @id="233555580689580553", @class_=#<Fauna::Ref:0x00007fbc8e8756c0 @id="posts", @class_=#<Fauna::Ref:0x00007fbc90238350 @id="classes">>>,
      :data=>nil
    }
  ]
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "create",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        title: "What I had for breakfast..."
      }
    },
    {
      ts: 1558994916810000,
      action: "update",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: {
        tags: ["eggs", "toast"]
      }
    },
    {
      ts: 1558994945460000,
      action: "delete",
      instance: ref(id = "233555580689580553",
      class = ref(id = "posts", class = ref(id = "classes"))),
      data: NullV
    }
  ]
}
{ data:
   [ { ts: 1558994808800000,
       action: 'create',
       instance: Ref(Class("posts"), "233555580689580553"),
       data: [Object] },
     { ts: 1558994916810000,
       action: 'update',
       instance: Ref(Class("posts"), "233555580689580553"),
       data: [Object] },
     { ts: 1558994945460000,
       action: 'delete',
       instance: Ref(Class("posts"), "233555580689580553"),
       data: null } ] }

The following query fetches the events while using Singleton:

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": { "events": { "singleton": {
            "@ref": "classes/posts/233555580689580553"
          }}}
        }'
client.Query(
  Paginate(
    Events(Singleton(Ref(Collection("posts"), "233555580689580553")))
  )
)
System.out.println(
    client.query(
        Paginate(
            Events(
                Singleton(Ref(Collection("posts"), "233555580689580553"))
            )
        )
    ).get()
);
result, err := client.Query(
  f.Paginate(
    f.Events(
      f.Singleton(
        f.RefClass(f.Collection("posts"), "233555580689580553")))))

fmt.Println(result)
client.query(
  Paginate(
    Events(
      Singleton(Ref(Collection("posts"), "233555580689580553"))
    )
  )
)
result = client.query(
  q.paginate(
    q.events(
      q.singleton(q.ref(q.collection("posts"), "233555580689580553"))
    )
  )
)
print(result)
puts $client.query {
  paginate events singleton ref collection("posts"), "233555580689580553"
}
client.query(
  Paginate(
    Events(
      Singleton(Ref(Collection("posts"), "233555580689580553"))
    )
  )
)
client.query(
  q.Paginate(
    q.Events(
      q.Singleton(q.Ref(q.Collection("posts"), "233555580689580553"))
    )
  )
).then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1558994808800000,
        "action": "create",
        "resource": { "@ref": "classes/posts/233555580689580553" }
      },
      {
        "ts": 1558994945460000,
        "action": "delete",
        "resource": { "@ref": "classes/posts/233555580689580553" }
      }
    ]
  }
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "add",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    },
    {
      ts: 1558994945460000,
      action: "remove",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    }
  ]
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "add",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    },
    {
      ts: 1558994945460000,
      action: "remove",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    }
  ]
}
map[data:[map[action:add instance:{233555580689580553 0xc0001e62c0 <nil>} ts:1558994808800000] map[action:remove instance:{233555580689580553 0xc0001e65a0 <nil>} ts:1558994945460000]]]
{
  data: [
    {
      ts: 1558994808800000,
      action: "add",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    },
    {
      ts: 1558994945460000,
      action: "remove",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    }
  ]
}
{
  'data': [
    {
      'ts': 1558994808800000,
      'action': 'add',
      'instance': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes)))
    },
    {
      'ts': 1558994945460000,
      'action': 'remove',
      'instance': Ref(id=233555580689580553, class=Ref(id=posts, class=Ref(id=classes)))
    }
  ]
}
{
  :data=>[
    {
      :ts=>1558994808800000,
      :action=>"add",
      :instance=>#<Fauna::Ref:0x00007fcd440165a8 @id="233555580689580553", @class_=#<Fauna::Ref:0x00007fcd440165f8 @id="posts", @class_=#<Fauna::Ref:0x00007fcd45237ea8 @id="classes">>>
    },
    {
      :ts=>1558994945460000,
      :action=>"remove",
      :instance=>#<Fauna::Ref:0x00007fcd44016468 @id="233555580689580553", @class_=#<Fauna::Ref:0x00007fcd44016490 @id="posts", @class_=#<Fauna::Ref:0x00007fcd45237ea8 @id="classes">>>
    }
  ]
}
{
  data: [
    {
      ts: 1558994808800000,
      action: "add",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    },
    {
      ts: 1558994945460000,
      action: "remove",
      instance: ref(id = "233555580689580553", class = ref(id = "posts", class = ref(id = "classes")))
    }
  ]
}
{ data:
   [ { ts: 1558994808800000,
       action: 'add',
       instance: Ref(Class("posts"), "233555580689580553") },
     { ts: 1558994945460000,
       action: 'remove',
       instance: Ref(Class("posts"), "233555580689580553") } ] }

Was this article helpful?

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

Thank you for your feedback!