For demonstration purposes, let’s create a collection named temporal
:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.CreateCollection({ name: 'temporal' })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
ref: Collection("temporal"),
ts: 1649181192120000,
history_days: 30,
name: 'temporal'
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Create(
q.Ref(q.Collection('temporal'), '1'),
{
data: {
test: 'temporality',
},
}
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
ref: Ref(Collection("temporal"), "1"),
ts: 1648840223890000,
data: { test: 'temporality' }
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
Next, create an index which includes the ts
field in its
values:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.CreateIndex({
name: 'temporal',
source: q.Collection('temporal'),
values: [
{ field: ['data', 'test'] },
{ field: ['ts'] },
{ field: ['ref'] },
],
})
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
ref: Index("temporal"),
ts: 1649201845600000,
active: true,
serialized: true,
name: 'temporal',
source: Collection("temporal"),
values: [
{ field: [ 'data', 'test' ] },
{ field: [ 'ts' ] },
{ field: [ 'ref' ] }
],
partitions: 8
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
You can use the Paginate
function to read out the contents of the
temporal
index:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Map(
q.Paginate(q.Match(q.Index('temporal'))),
q.Lambda(
['test', 'ts', 'ref'],
{
test: q.Var('test'),
ts: q.Var('ts'),
ref: q.Var('ref'),
}
)
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
data: [
{
test: 'temporality',
ts: 1649201894950000,
ref: Ref(Collection("temporal"), "1")
}
]
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
In this case, we’ve used a custom result object to label each field in
the index’s values
definition.
Now let’s insert an event into the document’s history with a specific
timestamp. The following example uses the Epoch
function to
construct a timestamp 1000 seconds after the Unix epoch date
(1970-01-01T00:00:00Z) and the Insert
function to add a create
event to the document’s history.
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Insert(
q.Ref(q.Collection('temporal'), '1'),
q.Epoch(1000, 'seconds'),
'create',
{
data: {
test: 'time travel',
},
}
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
ts: 1000000000,
action: 'create',
document: Ref(Collection("temporal"), "1"),
data: { test: 'time travel' }
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
If you read out the contents of the index again you can see that the
original version of the document still exists, with its original
timestamp. The Match
function, which reads documents from the
temporal
index, retrieves the most recent version of the document; when
we added a create
event to the document we gave it an earlier
timestamp, so its the original version we see now:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Map(
q.Paginate(q.Match(q.Index('temporal'))),
q.Lambda(
['test', 'ts', 'ref'],
{
test: q.Var('test'),
ts: q.Var('ts'),
ref: q.Var('ref'),
}
)
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
data: [
{
test: 'temporality',
ts: 1649201894950000,
ref: Ref(Collection("temporal"), "1")
}
]
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
You can use the At
function to retrieve the document with the
earlier timestamp. The following example looks for documents created at
or before one day after the Unix epoch date plus 1,000 seconds:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.At(
q.TimeAdd(q.Epoch(1000, 'seconds'), 1, 'day'),
q.Paginate(q.Match(q.Index('temporal')))
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
data: [ [ 'time travel', 1000000000, Ref(Collection("temporal"), "1") ] ]
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
The document’s event history is a record of all events in the life of
the document. The following example updates our document, adding an
update
event to the document’s history:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Update(
q.Ref(q.Collection('temporal'), '1'),
{
data: {
test: 'current time',
},
}
)
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
ref: Ref(Collection("temporal"), "1"),
ts: 1649181444450000,
data: { test: 'current time' }
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
The document now has three events in its history. The following example
uses the Events
function to display them in order by timestamp:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
client.query(
q.Paginate(q.Events(q.Ref(q.Collection('temporal'), '1')))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
'Error: [%s] %s: %s',
err.name,
err.message,
err.errors()[0].description,
))
{
data: [
{
ts: 1000000000,
action: 'create',
document: Ref(Collection("temporal"), "1"),
data: { test: 'time travel' }
},
{
ts: 1649181443630000,
action: 'update',
document: Ref(Collection("temporal"), "1"),
data: { test: 'temporality' }
},
{
ts: 1649181444450000,
action: 'update',
document: Ref(Collection("temporal"), "1"),
data: { test: 'current time' }
}
]
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.