Subscribe to our list to receive the latest updates on Node on Fire

Class: Datastore

Datastore

new Datastore(databaseURL)

The datastore module. Communicates with the database. Currently only PostgreSQL is supported.

Parameters:
Name Type Description
databaseURL String

URL to the database.

Methods

addModel(modelName, model)

Adds a table to the model.

The SQL table isn't actually created in the database by this method.

Parameters:
Name Type Description
modelName String

The name of the model.

model Model

The model.

beginTransaction()

Starts a database transaction. This should not be used in the run phase. Only in the build or release phase as it doesn't support concurrent queries.

commitTransaction()

Rolls back the transaction.

installExtensions()

Connects to the database and verifies if the uuid-ossp extension exists.

If the uuid-ossp exists, but is not enabled, a warning is shown and the extension is enabled. If this fails, you may need to connect the database yourself with an admin account and enable the extension by executing CREATE EXTENSION "uuid-ossp";.

If the extension does not exist, an error is thrown.

The uuid-ossp is required because models, by default, have a UUID as primary key. It's currently not possible to change this behaviour.

Returns:
Type
Promise

query(query)

Connects the database and executes query. See Client#query.

Parameters:
Name Type Description
query knex

A knex-constructed query.

Returns:

Result set.

Type
Object

rollbackTransaction()

Commits the transaction.

setupTable(table)

Creates the table in the databse.

Parameters:
Name Type Description
table Table

The table to create.

Do you have any questions or comments on this page? Start a discussion below.

comments powered by Disqus
Subscribe to our list to receive the latest updates on Node on Fire