Setup DataStore
DataStore Factory Method
You set up a DataStore by providing the RuntimeConfig with a factory method that returns a DataStore implementation. This is the place to
- decide which of the
DataStoreimplementations ActiveQL provides you want to you use or - provide your own
DataStoreimplementation. - Provide configuration to the actual
DataStoreimplementation
These are the DataStore implementations included in ActiveQL.
NeDB DataStore Factory Method (default)
The NeDB DataStore uses NeDB (opens in a new tab) a NoSQL, lightweight, file-based database with a MongoDB-like syntax and works with zero-setup and is therefore the default implementation.
The following configuration would result in the same Runtime as leaving the dataStore value empty.
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
dataStore: ()) => NedbDataStore.create({filePath: 'db'})
};Config
| Config | Type | Default | Description |
|---|---|---|---|
filePath | string | db | folder where to store the data files |
Postgres PgDataStore Factory Method
The PgDataStore connects to a Postgres instance and is suitable for production.
const options = { host: 'localhost' };
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
dataStore: () => PgDataStore.create( options )
};The options object is of type ClientConfig.
Selection of config options
| Config | Type | Description |
|---|---|---|
user | string | user account of the Postgres database |
database | string | database name |
password | string|(() => string|Promise<string>) | password to connect to Postgres database |
port | number | port to connect to Postgres database |
host | string | host on which the Postgres database runs |
ssl | boolean|ConnectionOptions | whether to use ssl when connecting |
indexAttributes | string[] | creation of indexes for these attributes |
For further config options see: https://node-postgres.com/apis/client (opens in a new tab)
Indexed Attributes
This option parameter is not from the PostgresClient but instructs the PgDataStore to add indexes for these attributes to the entities table at startup. This can dramatically improve performance when using filter queries with these attributes.
In this example we want to have an indexed query when using licence as filter.
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
dataStore: () => PgDataStore.create({indexAttributes: ['licence']})
};