interface ds.DataStore

Abstraction around data storage in the form of document style records.

Eventicle contains a built in InMemoryDatastore. Others can be imported as needed.

Methods

createEntity(workspaceId, type, content)

Create a new entity in the datastore.

Parameters
Name Type Description

workspaceId

string

Tenant

type

string

Entity type or "table" name

content

any

Returns

Promise<ds.Record_2>

Signature
createEntity(workspaceId: string, type: string, content: any): Promise<Record>;

deleteEntity(workspaceId, type, id)

Remove a single Record by its ID

Parameters
Name Type Description

workspaceId

string

The tenant

type

string

the record type

id

string

the id of the entity.

Returns

Promise<void>

Signature
deleteEntity(workspaceId: string, type: string, id: string): Promise<void>;

deleteMany(workspaceId, type, query)

Delete multiple from the Datastore via a result

Parameters
Name Type Description

workspaceId

string

the tenant

type

string

the Record type

query

ds.Query

The query, any matching Records will be deleted.

Returns

Promise<void>

Signature
deleteMany(workspaceId: string, type: string, query: Query): Promise<void>;

findEntity(workspaceId, type, query, sorting)

Find using a given , and optionally sort the results using a

Parameters
Name Type Description

workspaceId

string

type

any

Entity type or "table" name

query

ds.Query

Json object to match fields

sorting

ds.DataSorting

Returns

Promise<ds.Record_2[]>

Signature
findEntity(workspaceId: string, type: any, query: Query, sorting?: DataSorting): Promise<Record[]>;

findEntityPaginated(workspaceId, type, query, sorting, page, pageSize)

Find using a given , and optionally sort the results using a , with pagination information provided in

Parameters
Name Type Description

workspaceId

string

The tenant id.

type

string

Entity type or "table" name

query

ds.Query

Json object to match fields

sorting

ds.DataSorting

How to sort the results

page

number

page count

pageSize

number

page size

Returns

Promise<ds.PagedRecords>

Signature
findEntityPaginated(workspaceId: string, type: string, query: Query, sorting: DataSorting, page: number, pageSize: number): Promise<PagedRecords>;

getEntity(workspaceId, type, id)

Look up a single by its ID

Parameters
Name Type Description

workspaceId

string

when running on a multi-tenant Datastore, selects the tenant.

type

string

The type of the Record

id

string

The record ID

Returns

Promise<ds.Record_2>

Signature
getEntity(workspaceId: string, type: string, id: string): Promise<Record>;

getTransactionData()

Bag of data associated with the current transaction

Signature
getTransactionData(): TransactionData;

hasTransactionData()

Whether transaction data currently exists in this context.

Signature
hasTransactionData(): boolean;

on(event, listener)

Parameters
Name Type Description

event

'transaction.start'

listener

(name: string, data: ds.TransactionData) => void

Returns

this

Signature
on(event: 'transaction.start', listener: (name: string, data: TransactionData) => void): this;

on(event, listener)

Parameters
Name Type Description

event

'transaction.commit'

listener

(name: string, data: ds.TransactionData) => void

Returns

this

Signature
on(event: 'transaction.commit', listener: (name: string, data: TransactionData) => void): this;

saveEntity(workspaceId, type, item)

Save updates an existing entity

Parameters
Name Type Description

workspaceId

string

The tenant

type

string

the record type

item

ds.Record_2

The existing Record. Must have come from or

Returns

Promise<ds.Record_2>

Signature
saveEntity(workspaceId: string, type: string, item: Record): Promise<Record>;

transaction(exec, options)

Open a transaction (or optionally join one if it exists)

Parameters
Name Type Description

exec

() => Promise<T>

transaction is open within this execution. Once this function promise resolves, the transaction is committed or rolled back If exec Promise rejects, then the transaction is rolled back.

options

ds.TransactionOptions

if exists, controls if the trnasction should be new, or an existing on can be used.

Returns

Promise<T>

Signature
transaction<T>(exec: () => Promise<T>, options?: TransactionOptions): Promise<T>;