Events
Events( 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
-
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 |
---|---|---|
|
The action applied to the |
|
|
Optional: only provided for documents containing user-supplied data. The data involved in the event. |
|
|
The reference identifies the document associated with the event. |
|
|
The timestamp, with microsecond resolution, associated with the event. |
Examples
The following query fetches the events for a regular document:
client.query(
q.Events(q.Ref(q.Collection('posts'), '233555580689580553'))
).then((ret) => console.log(ret))
SetRef({ events: Ref(Class("posts"), "233555580689580553") })
And again, using Paginate
to see the
details of each event:
client.query(
q.Paginate(q.Events(q.Ref(q.Collection('posts'), '233555580689580553')))
).then((ret) => console.log(ret))
{ 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
:
client.query(
q.Paginate(
q.Events(
q.Singleton(q.Ref(q.Collection('posts'), '233555580689580553'))
)
)
).then((ret) => console.log(ret))
{ data:
[ { ts: 1558994808800000,
action: 'add',
instance: Ref(Class("posts"), "233555580689580553") },
{ ts: 1558994945460000,
action: 'remove',
instance: Ref(Class("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!