Include Time Series with Raw Queries
-
Use
include timeseries
in your RQL expression in order to include time series data when making
a raw query via session.advanced.rawQuery. -
The included time series data is stored within the session and can be provided instantly when requested
without any additional server calls. -
In this page:
Include time series when making a raw query
In this example, we use a raw query to retrieve a document
and include entries from the document's "HeartRates" time series.
const baseTime = new Date();
const from = baseTime;
const to = new Date(baseTime.getTime() + 60_000 * 5);
// Define the Raw Query:
const rawQuery = session.advanced
// Use 'include timeseries' in the RQL
.rawQuery("from users include timeseries('HeartRates', $from, $to)")
// Pass optional parameters
.addParameter("from", from)
.addParameter("to", to);
// Execute the query:
// For each document in the query results,
// the time series entries will be 'loaded' to the session along with the document
const userDocuments = await rawQuery.all();
const numberOfRequests1 = session.advanced.numberOfRequests;
// The following call to 'get' will Not trigger a server request,
// the entries will be retrieved from the session's cache.
const entries = await session.timeSeriesFor(userDocuments[0], "HeartRates")
.get(from, to);
const entryValue = entries[0].value;
const numberOfRequests2 = session.advanced.numberOfRequests;
assert.equal(numberOfRequests1, numberOfRequests2);
Syntax
advanced.rawQuery
rawQuery(query, documentType?);
Parameter | Type | Description |
---|---|---|
query | string |
The raw RQL query. |
documentType | object |
The document class type (an optional param). |