Setup and start
Setup DataStore

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 DataStore implementations ActiveQL provides you want to you use or
  • provide your own DataStore implementation.
  • Provide configuration to the actual DataStore implementation

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

ConfigType DefaultDescription
filePathstringdbfolder 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

ConfigTypeDescription
userstringuser account of the Postgres database
databasestringdatabase name
passwordstring|(() => string|Promise<string>)password to connect to Postgres database
portnumberport to connect to Postgres database
hoststringhost on which the Postgres database runs
sslboolean|ConnectionOptionswhether to use ssl when connecting
 indexAttributesstring[]  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']})
};