Events

Copied!
( input )

Description

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

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

Singular references
  • create

  • delete

  • update

Set references
  • add

  • remove

Parameter

Argument Type Definition and Requirements

input

A Set of references (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

The action applied to the instance during the event.

data

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

instance

The reference identifies the document associated with the event.

ts

The timestamp, with microsecond resolution, associated with the event.

Examples

The following query fetches the events for a regular document:

Copied!
client.query(
  q.(q.(q.('posts'), '233555580689580553'))
).then((ret) => console.log(ret))
SetRef({ events: (("posts"), "233555580689580553") })

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

Copied!
client.query(
  q.(q.(q.(q.('posts'), '233555580689580553')))
).then((ret) => console.log(ret))
{ data:
   [ { ts: 1558994808800000,
       action: 'create',
       instance: (("posts"), "233555580689580553"),
       data: [Object] },
     { ts: 1558994916810000,
       action: 'update',
       instance: (("posts"), "233555580689580553"),
       data: [Object] },
     { ts: 1558994945460000,
       action: 'delete',
       instance: (("posts"), "233555580689580553"),
       data: null } ] }

The following query fetches the events while using Singleton:

Copied!
client.query(
  q.(
    q.(
      q.(q.(q.('posts'), '233555580689580553'))
    )
  )
).then((ret) => console.log(ret))
{ data:
   [ { ts: 1558994808800000,
       action: 'add',
       instance: (("posts"), "233555580689580553") },
     { ts: 1558994945460000,
       action: 'remove',
       instance: (("posts"), "233555580689580553") } ] }

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!