Querying The Database
To extract data from the database, use the datasetQuery function.
The function takes a class and a (optional) filter as parameters and returns an object containing entities that are not cancelled, that you have access rights to, and that fit the requested parameters.
An file containing different querying examples can be downloaded here.
Below is the datasetQuery interface:
export interface DatasetQuery {
eClass?: string;
view?: string;
collection?: string;
alias?: string;
entity?: string;
filters?: Filter[];
sortings?: Sorting[];
fetch?: number;
offset?: number;
operations?: any[];
}
Although marked as optional, the eClass
parameter is necessary to complete the query. So is having either a collection
, alias
, or an entity
parameter.
The eclass
parameter marks the class of the queried entity.
The collection
/alias
/entity
marks the name and type of the output.
The filters
parameter is a list of filters that can be applied to the query. Below is the Filter
interface:
export interface Filter {
field: string;
values?: string[];
value?: any;
in?: any[] | string;
op?: 'contains' | 'startswith' | 'endswith' | 'neq' | 'not_in'
}
field
marks the value key on which to filter. value
is a single accepted string while values
is a list of accepted strings. in
allows for iteration through an object. Finally, the op
parameter allows for advanced searches. For instance, entities can be filteret by the first few letters of their name, or entities not made in a specific year can be found.
The sortings
parameter is a list of Sorting
objects and sorts the returned object. The Sorting
interface can be seen below.
export interface Sorting {
field: string;
direction?: 'asc' | 'desc';
}
Each Sorting
contains the name of the field on which to sort and a direction: 'asc'
for ascending order, and 'desc'
for descending order.