Server Data Store
A Server Data Store stores Entities in a database. Its class has only static methods, which you call as This.<ServerDataStoreName>.<method>() to load, save, update and delete the Entities it stores.
Availability: Both¹
How to reach it
Section titled “How to reach it”This.<ServerDataStoreName> is the Server Data Store class. It is not grouped under a $ namespace.
It is declared in server-side and client-side code, but not in shared code (serverAndClient or calculation). On the client, each method sends the call to the server, where Access Control decides whether it may run.
In the signatures below, EntityClasses stands for the union of the Entity classes this Server Data Store stores, including their subset classes, for example typeof This.Order | typeof This.Order.Summary | typeof This.Customer. The real declaration spells out that union. type parameters take one of these classes, and the result has the type of its instances, InstanceType<C>.
Functions
Section titled “Functions”loadById()
Section titled “loadById()”loadById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>): Promise<InstanceType<C> | null>Loads the record with the given id.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
id | IdType<InstanceType<C>> | The record’s id. If it is null or undefined, the result is null. |
findOptions | Omit<FindManyOptions<InstanceType<C>>, 'where'> | Optional. Further options, for example relations. See FindManyOptions under Types. |
Returns: Promise<InstanceType<C> | null>, null if no record is found or Access Control hides it · Availability: Both¹
loadByIdOrFail()
Section titled “loadByIdOrFail()”loadByIdOrFail<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>): Promise<InstanceType<C>>Loads the record with the given id, and throws an error if there is none.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
id | IdType<InstanceType<C>> | The record’s id. |
findOptions | Omit<FindManyOptions<InstanceType<C>>, 'where'> | Optional. Further options. |
Returns: Promise<InstanceType<C>> · Availability: Both¹
loadByIds()
Section titled “loadByIds()”loadByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[], findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>, removeEmptyResults?: boolean): Promise<InstanceType<C>[]>Loads the records with the given ids. Unless findOptions sets an order, the results are in the order of ids.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
ids | IdType<InstanceType<C>>[] | The records’ ids. |
findOptions | Omit<FindManyOptions<InstanceType<C>>, 'where'> | Optional. Further options. |
removeEmptyResults | boolean | Optional. If true, ids without a record are left out of the result. Default: false. |
Returns: Promise<InstanceType<C>[]> · Availability: Both¹
Note
Unless removeEmptyResults is true, the result has null at the position of each id for which no record was found, although the declared type has no null.
loadByCondition()
Section titled “loadByCondition()”loadByCondition<C extends EntityClasses>(type: C, findOptions?: FindManyOptions<InstanceType<C>>): Promise<InstanceType<C>[]>Loads the records that match findOptions.where, or all records if there is no condition. Without an order, the records are sorted by id.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. Condition, sorting, relations to load and paging. See FindManyOptions under Types. |
This example loads the ten largest orders over 1000, then changes and saves the first one:
const largeOrders = await This.MyDataStore.loadByCondition(This.Order, { where: { amount: This.MyDataStore.MoreThan(1000) }, order: { amount: 'DESC' }, take: 10,})
const order = largeOrders[0]order.amount = 900await This.MyDataStore.saveOne(order)Returns: Promise<InstanceType<C>[]> · Availability: Both¹
loadPageByCondition()
Section titled “loadPageByCondition()”loadPageByCondition<C extends EntityClasses>(type: C, paging: PagingDefinition, findOptions?: FindManyOptions<InstanceType<C>>): Promise<PagedData<InstanceType<C>>>Loads one page of the records that match findOptions.where, together with the total number of matching records.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
paging | PagingDefinition | The page size and the zero-based page index. It replaces any take and skip in findOptions. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. Condition, sorting and relations to load. |
Returns: Promise<PagedData<InstanceType<C>>> · Availability: Both¹
loadByQuery()
Section titled “loadByQuery()”loadByQuery<C extends EntityClasses>(type: C, query: DataQuery<InstanceType<C>>, findOptions?: FindManyOptions<InstanceType<C>>): Promise<InstanceType<C>[]>Loads the records that match a search text, such as what an End user typed into a search field. The condition in findOptions.where must match too.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
query | DataQuery<InstanceType<C>> | The search text and the properties to search in. See DataQuery under Types. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. Further condition, sorting and relations to load. |
Returns: Promise<InstanceType<C>[]> · Availability: Both¹
loadPageByQuery()
Section titled “loadPageByQuery()”loadPageByQuery<C extends EntityClasses>(type: C, paging: PagingDefinition, query: DataQuery<InstanceType<C>>, findOptions?: FindManyOptions<InstanceType<C>>): Promise<PagedData<InstanceType<C>>>Loads one page of the records that match a search text, together with the total number of matching records.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
paging | PagingDefinition | The page size and the zero-based page index. |
query | DataQuery<InstanceType<C>> | The search text and the properties to search in. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. Further condition, sorting and relations to load. |
Returns: Promise<PagedData<InstanceType<C>>> · Availability: Both¹
loadByVectorDistance()
Section titled “loadByVectorDistance()”loadByVectorDistance<C extends EntityClasses>(type: C, vectorPropertyName: keyof InstanceType<C> & string, searchVector: number[], operator?: DbVectorOperator, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'order'>, order?: 'ASC' | 'DESC'): Promise<InstanceType<C>[]>Loads records sorted by the distance between a vector property and a search vector, for example to find the texts most similar to an embedding. The database must be PostgreSQL with the pgvector extension.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
vectorPropertyName | keyof InstanceType<C> & string | The property that holds each record’s vector. |
searchVector | number[] | The vector to compare with. |
operator | DbVectorOperator | Optional. How the distance is computed. Default: 'l2Distance'. |
findOptions | Omit<FindManyOptions<InstanceType<C>>, 'order'> | Optional. Condition, number of records (take) and relations to load. |
order | 'ASC' | 'DESC' | Optional. Sort direction of the computed value. Default: 'ASC'. With 'l1Distance' and 'l2Distance', 'ASC' returns the closest records first; with 'innerProduct' and 'cosineDistance' the value grows with similarity, so use 'DESC'. |
Returns: Promise<InstanceType<C>[]> · Availability: Both¹
loadByVectorDistanceIncludingDistance()
Section titled “loadByVectorDistanceIncludingDistance()”loadByVectorDistanceIncludingDistance<C extends EntityClasses>(type: C, vectorPropertyName: keyof InstanceType<C> & string, searchVector: number[], operator?: DbVectorOperator, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'order'>, order?: 'ASC' | 'DESC'): Promise<{ data: InstanceType<C>, distance: number }[]>Works like loadByVectorDistance(), and also returns each record’s distance.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
vectorPropertyName | keyof InstanceType<C> & string | The property that holds each record’s vector. |
searchVector | number[] | The vector to compare with. |
operator | DbVectorOperator | Optional. How the distance is computed. Default: 'l2Distance'. |
findOptions | Omit<FindManyOptions<InstanceType<C>>, 'order'> | Optional. Condition, number of records and relations to load. |
order | 'ASC' | 'DESC' | Optional. Sort direction of the computed value, as for loadByVectorDistance(). Default: 'ASC'. |
Returns: Promise<{ data: InstanceType<C>, distance: number }[]> · Availability: Both¹
aggregate()
Section titled “aggregate()”aggregate<C extends EntityClasses, G extends keyof InstanceType<C>, A extends typeof allowedAggregationFunctions[number], K extends keyof InstanceType<C>, O extends string>(type: C, groupBy: G[], aggregations: AggregationInput<InstanceType<C>, A, K, O>[], findOptions?: FindManyOptions<InstanceType<C>>): Promise<AggregationOutput<InstanceType<C>, A, G, K, O>[]>Groups the matching records by the given properties and computes sums, counts, minimums, maximums or averages per group.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to aggregate. |
groupBy | G[] | The properties to group by. Pass [] for one result over all records. |
aggregations | AggregationInput<InstanceType<C>, A, K, O>[] | The values to compute. See AggregationInput under Types. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. The condition the records must match. |
Returns: Promise<AggregationOutput<InstanceType<C>, A, G, K, O>[]>, one object per group · Availability: Both¹
count()
Section titled “count()”count<C extends EntityClasses, G extends keyof InstanceType<C>>(type: C, groupBy?: G[], findOptions?: FindManyOptions<InstanceType<C>>): Promise<GroupedCount<InstanceType<C>, G>[]>Counts the matching records, optionally per group.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to count. |
groupBy | G[] | Optional. The properties to group by. Without it, the result has one object. |
findOptions | FindManyOptions<InstanceType<C>> | Optional. The condition the records must match. |
Returns: Promise<GroupedCount<InstanceType<C>, G>[]>, one object per group with the count in $count · Availability: Both¹
updateById()
Section titled “updateById()”updateById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>Changes properties of the record with the given id. Lowgile loads the record, applies the changes and saves it, so the Entity’s change Triggers run.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
id | IdType<InstanceType<C>> | The record’s id. |
updateProperties | Partial<InstanceType<C>> or a function | The new property values, or a function that receives the current record and returns them. Client-side code can only pass an object. |
Returns: Promise<number | null>, the number of updated records · Availability: Both¹
updateByIds()
Section titled “updateByIds()”updateByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[], updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>Changes properties of the records with the given ids, one record at a time, so the Entity’s change Triggers run.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
ids | IdType<InstanceType<C>>[] | The records’ ids. |
updateProperties | Partial<InstanceType<C>> or a function | The new property values, or a function that receives each record and returns them. Client-side code can only pass an object. |
Returns: Promise<number | null>, the number of updated records · Availability: Both¹
updateByCondition()
Section titled “updateByCondition()”updateByCondition<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*', updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>Changes properties of every record that matches a condition, one record at a time, so the Entity’s change Triggers run.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
where | FindOptionsWhere<…>, an array of them, or '*' | The condition, written like where in FindManyOptions. '*' matches all records. |
updateProperties | Partial<InstanceType<C>> or a function | The new property values, or a function that receives each record and returns them. Client-side code can only pass an object. |
Returns: Promise<number | null>, the number of updated records · Availability: Both¹
bulkUpdateByConditionWithoutTriggering()
Section titled “bulkUpdateByConditionWithoutTriggering()”bulkUpdateByConditionWithoutTriggering<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*', updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>Changes properties of every record that matches a condition directly in the database, without running the Entity’s change Triggers. Access Control restrictions still apply.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
where | FindOptionsWhere<…>, an array of them, or '*' | The condition. '*' matches all records. |
updateProperties | Partial<InstanceType<C>> or a function | The new property values, or a function that receives each record and returns them. |
Returns: Promise<number | null>, the number of updated records · Availability: Server
upsert()
Section titled “upsert()”upsert<C extends EntityClasses>(type: C, objs: InstanceType<C>[], propertiesToMatchBy: [keyof InstanceType<C>, ...(keyof InstanceType<C>)[]]): Promise<SavedIds<InstanceType<C>>[]>Saves objects, updating the existing record where one has the same values in propertiesToMatchBy and inserting a new record otherwise. Lowgile sets the id of each matched object before saving.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
objs | InstanceType<C>[] | The objects to save. |
propertiesToMatchBy | [keyof InstanceType<C>, ...(keyof InstanceType<C>)[]] | At least one property that identifies an existing record, such as an external number. |
Returns: Promise<SavedIds<InstanceType<C>>[]>, one per object · Availability: Both¹
saveOne()
Section titled “saveOne()”saveOne<C extends EntityClasses>(obj: InstanceType<C>): Promise<SavedIds<InstanceType<C>>>Inserts the object as a new record if it has no id, or updates the record with its id. Afterwards, the object and its related objects carry the ids the database assigned.
| Parameter | Type | Description |
|---|---|---|
obj | InstanceType<C> | The object to save. |
On the client, Lowgile first calls the object’s own beforeUpdate method (if the object has an id) or beforeInsert method (if not), or else its beforeSave method, if the Entity defines one that is available on the client.
Returns: Promise<SavedIds<InstanceType<C>>> · Availability: Both¹
saveOneAndTransferAuditTrail()
Section titled “saveOneAndTransferAuditTrail()”saveOneAndTransferAuditTrail<C extends EntityClasses>(obj: InstanceType<C>, auditTrailUuid: string): Promise<SavedIds<InstanceType<C>>>Inserts a new record and moves the audit trail entries recorded under auditTrailUuid to it. Use it when audit trail entries were written before the record existed.
| Parameter | Type | Description |
|---|---|---|
obj | InstanceType<C> | The object to insert. It must not have an id, otherwise the call throws an error. |
auditTrailUuid | string | The UUID under which the audit trail entries were recorded. |
Returns: Promise<SavedIds<InstanceType<C>>> · Availability: Both¹
saveMany()
Section titled “saveMany()”saveMany<C extends EntityClasses>(objs: InstanceType<C>[]): Promise<SavedIds<InstanceType<C>>[]>Saves several objects in one transaction, inserting or updating each like saveOne().
| Parameter | Type | Description |
|---|---|---|
objs | InstanceType<C>[] | The objects to save. They can be of different Entities stored by this Server Data Store. |
Returns: Promise<SavedIds<InstanceType<C>>[]>, one per object · Availability: Both¹
deleteOne()
Section titled “deleteOne()”deleteOne<C extends EntityClasses>(obj: InstanceType<C>): Promise<number | null>Deletes the record of the given object, identified by its id.
| Parameter | Type | Description |
|---|---|---|
obj | InstanceType<C> | The object whose record to delete. |
Returns: Promise<number | null>, the number of deleted records · Availability: Both¹
deleteMany()
Section titled “deleteMany()”deleteMany<C extends EntityClasses>(objs: InstanceType<C>[]): Promise<number | null>Deletes the records of the given objects, identified by their id.
| Parameter | Type | Description |
|---|---|---|
objs | InstanceType<C>[] | The objects whose records to delete. |
Returns: Promise<number | null>, the number of deleted records · Availability: Both¹
deleteById()
Section titled “deleteById()”deleteById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>): Promise<number | null>Deletes the record with the given id.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
id | IdType<InstanceType<C>> | The record’s id. |
Returns: Promise<number | null>, the number of deleted records · Availability: Both¹
deleteByIds()
Section titled “deleteByIds()”deleteByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[]): Promise<number | null>Deletes the records with the given ids.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
ids | IdType<InstanceType<C>>[] | The records’ ids. |
Returns: Promise<number | null>, the number of deleted records · Availability: Both¹
deleteByCondition()
Section titled “deleteByCondition()”deleteByCondition<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*'): Promise<number | null>Deletes every record that matches a condition.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
where | FindOptionsWhere<…>, an array of them, or '*' | The condition. '*' matches all records. |
Returns: Promise<number | null>, the number of deleted records · Availability: Both¹
bulkDeleteByConditionWithoutTriggering()
Section titled “bulkDeleteByConditionWithoutTriggering()”bulkDeleteByConditionWithoutTriggering<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*'): Promise<number | null>Deletes every record that matches a condition without running the Entity’s change Triggers. Access Control restrictions still apply.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class. |
where | FindOptionsWhere<…>, an array of them, or '*' | The condition. '*' matches all records. |
Returns: Promise<number | null>, the number of deleted records · Availability: Server
loadAndStreamByCondition()
Section titled “loadAndStreamByCondition()”loadAndStreamByCondition<C extends EntityClasses, R>(type: C, findOptions?: FindManyOptions<C>, whatToReturn?: (baseResult: InstanceType<C>) => R): AsyncGenerator<R>loadAndStreamByCondition<C extends EntityClasses>(type: C, findOptions?: FindManyOptions<C>): AsyncGenerator<InstanceType<C>>Loads the matching records one by one instead of all at once, for processing large numbers of records. Read the result with for await.
| Parameter | Type | Description |
|---|---|---|
type | C | The Entity class to load. |
findOptions | FindManyOptions<C> | Optional. Condition, sorting and relations to load. |
whatToReturn | (baseResult: InstanceType<C>) => R | Optional. A function that turns each record into the value the generator yields. |
for await (const order of This.MyDataStore.loadAndStreamByCondition(This.Order, { where: { amount: This.MyDataStore.MoreThan(1000) } })) { // process one order at a time}Returns: AsyncGenerator<R> or AsyncGenerator<InstanceType<C>> · Availability: Server
createQueryBuilder()
Section titled “createQueryBuilder()”createQueryBuilder<T extends EntityClasses, A extends string>(type: T, alias: A): QueryBuilder<EntityClasses, T, A>Creates a query builder for queries that the other methods can’t express, such as joins across Entities. The query builder has methods to add joins (join()), conditions (condition(), conditionRaw()), sorting and paging (order(), skip(), take()), and to run the query (selectOne(), selectMany(), selectCount(), selectManyAndCount(), their selectRaw…() variants, insert(), update() and delete()).
| Parameter | Type | Description |
|---|---|---|
type | T | The main Entity class of the query. |
alias | A | The name under which the main Entity appears in the query and its results. |
Returns: QueryBuilder<EntityClasses, T, A> · Availability: Server
Note
Queries built with createQueryBuilder() are not restricted by Access Control. The query builder’s update() and delete() return before the database has finished, and errors they cause are not reported to your code.
AndMerge()
Section titled “AndMerge()”AndMerge<T>(...whereConditions: (FindOptionsWhere<T> | FindOptionsWhere<T>[])[]): FindOptionsWhere<T>[]Combines several where conditions so that a record must match all of them. Conditions that are arrays (alternatives) are expanded, so the result is one array of alternatives.
| Parameter | Type | Description |
|---|---|---|
whereConditions | (FindOptionsWhere<T> | FindOptionsWhere<T>[])[] | The conditions to combine. undefined entries are ignored. |
Returns: FindOptionsWhere<T>[] · Availability: Server
Properties
Section titled “Properties”TypeORM operators
Section titled “TypeORM operators”readonly And: typeof typeorm['And']readonly Any: typeof typeorm['Any']readonly ArrayContainedBy: typeof typeorm['ArrayContainedBy']readonly ArrayContains: typeof typeorm['ArrayContains']readonly ArrayOverlap: typeof typeorm['ArrayOverlap']readonly Between: typeof typeorm['Between']readonly Equal: typeof typeorm['Equal']readonly ILike: typeof typeorm['ILike']readonly In: typeof typeorm['In']readonly IsNull: typeof typeorm['IsNull']readonly LessThan: typeof typeorm['LessThan']readonly LessThanOrEqual: typeof typeorm['LessThanOrEqual']readonly Like: typeof typeorm['Like']readonly MoreThan: typeof typeorm['MoreThan']readonly MoreThanOrEqual: typeof typeorm['MoreThanOrEqual']readonly Not: typeof typeorm['Not']readonly Or: typeof typeorm['Or']The find operators of TypeORM 1.1.1, re-exported unchanged, for use as values in where conditions. See the TypeORM documentation for each operator.
const orders = await This.MyDataStore.loadByCondition(This.Order, { where: { status: This.MyDataStore.In(['open', 'approved']), deletedOn: This.MyDataStore.IsNull() },})Type: TypeORM find operator functions · Availability: Both
FindManyOptions
Section titled “FindManyOptions”interface FindManyOptions<T> { select?: FindOptionsSelect<EntityRecord<T>> where?: FindOptionsWhere<EntityRecord<T>>[] | FindOptionsWhere<EntityRecord<T>> relations?: FindOptionsRelations<EntityRecord<T>> order?: FindOptionsOrder<EntityRecord<T>> cache?: boolean | number | { id: any; milliseconds: number } lock?: { mode: 'optimistic'; version: number | Date } | { mode: 'pessimistic_read' | 'pessimistic_write' | 'dirty_read' | 'for_no_key_update' | 'for_key_share'; tables?: string[]; onLocked?: 'nowait' | 'skip_locked' } transaction?: boolean skip?: number take?: number}Options for loading records. The select, where, relations and order types are TypeORM’s, applied to the Entity’s properties.
FindManyOptions fields
| Field | Type | Required | Description |
|---|---|---|---|
select | FindOptionsSelect<…> | Optional | The properties to load, as { propertyName: true }. |
where | FindOptionsWhere<…> or an array of them | Optional | The condition, as { propertyName: value }. A value can be a TypeORM operator such as This.<ServerDataStoreName>.MoreThan(5); null matches empty values. Properties of a related Entity are written as a nested object. An array of conditions matches records that fulfil any of them. |
relations | FindOptionsRelations<…> | Optional | The related Entities to load with each record, as { relationName: true }, nested for deeper levels. |
order | FindOptionsOrder<…> | Optional | The sort order, as { propertyName: 'ASC' } or 'DESC'. |
cache | boolean | number | { id: any; milliseconds: number } | Optional | Caches the query result, for the given number of milliseconds if a number is given. |
lock | an object with mode | Optional | Locks the loaded rows. 'optimistic' needs a version; the other modes accept the tables to lock and what to do with locked rows. |
transaction | boolean | Optional | If true, runs the query in a transaction. |
skip | number | Optional | The number of records to skip. |
take | number | Optional | The maximum number of records to load. |
Availability: Both
PagingDefinition
Section titled “PagingDefinition”interface PagingDefinition { pageSize: number pageIndex: number}Which page of records to load.
| Field | Type | Required | Description |
|---|---|---|---|
pageSize | number | Required | The number of records per page. |
pageIndex | number | Required | The page to load, starting at 0. |
Availability: Both
PagedData
Section titled “PagedData”interface PagedData<T> extends PagingDefinition { list: T[] length: number pageStartIndex: number pageEndIndex: number}One page of records, with the paging information.
| Field | Type | Required | Description |
|---|---|---|---|
list | T[] | Required | The records on this page. |
length | number | Required | The total number of matching records on all pages. |
pageStartIndex | number | Required | The zero-based position of the page’s first record among all matching records. |
pageEndIndex | number | Required | The zero-based position of the page’s last record among all matching records. |
pageSize | number | Required | The page size. |
pageIndex | number | Required | The page index. |
Availability: Both
DataQuery
Section titled “DataQuery”interface DataQuery<T> { query: string searchInProperties?: string[] caseSensitive?: boolean}A search text for loadByQuery() and loadPageByQuery().
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Required | The search text. Each word must match. A word on its own matches if any searched property contains it. A word can also name a property and an operator, such as name:smith or amount>100. Put text with spaces in double quotes. |
searchInProperties | string[] | Optional | The properties to search in. Default: the Entity properties marked as searchable by default. |
caseSensitive | boolean | Optional | If true, upper and lower case must match. Default: false. |
Availability: Both
AggregationInput
Section titled “AggregationInput”interface AggregationInput<T, A extends 'count' | 'sum' | 'min' | 'max' | 'avg', K extends keyof T, O extends string> { aggregationFunction: A column: '*' | K outputName: O}One value for aggregate() to compute per group.
| Field | Type | Required | Description |
|---|---|---|---|
aggregationFunction | 'count' | 'sum' | 'min' | 'max' | 'avg' | Required | The function to apply. |
column | '*' | K | Required | The property to apply it to, or '*' for all records (with 'count'). |
outputName | O | Required | The name of the field that holds the result. |
Availability: Both
AggregationOutput
Section titled “AggregationOutput”type AggregationOutput<T, A, G extends keyof T, K extends keyof T, O extends string> = { [P in G]: T[P] } & { [P in O]: A extends 'count' ? number : T[K] }One result of aggregate(): the group-by properties with the group’s values, plus one field per outputName.
Availability: Both
GroupedCount
Section titled “GroupedCount”type GroupedCount<T, G extends keyof T> = { [P in G]: T[P] } & { $count: number }One result of count(): the group-by properties with the group’s values, plus the number of records in $count.
Availability: Both
SavedIds
Section titled “SavedIds”type SavedIds<T> = { id: T['id'] <oneToManyRelation>: (number | string)[] <manyToOneRelation>: number | string}The ids a save assigned: the record’s id, and the ids of the related records saved with it, per relation.
Availability: Both
DbVectorOperator
Section titled “DbVectorOperator”type DbVectorOperator = 'l1Distance' | 'l2Distance' | 'innerProduct' | 'cosineDistance'How loadByVectorDistance() compares two vectors: 'l1Distance' (Manhattan distance), 'l2Distance' (Euclidean distance), 'innerProduct' (inner product) or 'cosineDistance'.
Availability: Both
Note
'cosineDistance' computes 1 minus the cosine distance, which is the cosine similarity: larger values mean more similar vectors.
Related
Section titled “Related”- Server Data Store
- Entity API
- Transactional Entities
- Access Control
¹ On the client, the call is sent to the server and is subject to access control.