Connects to SQL databases through the Knex Query Builder module.
const { knexService } = require('cukelib');
... or standalone ...
const knexService = require('cukelib/lib/knex_service');
config
is an object that can be passed toknex(...)
to create a knex client with a few additional parameters and conventions.config.name
can be specified as an explicit name for thecukelib
service identifier, otherwise the service name defaults to the database name fromconfig.connection.database
or a sequentially named identifier.- If
config.migrations.directory
orconfig.seeds.directory
are specified the respective migrations or seeds are applied to the database when the service is launched, and the migrations are rolled back when the service stops. config
is merged with the following via_.defaultdDeep
, so be sure to specify these values explicitly as neededconfig.debug
Set this totrue
to get a dump of attempted SQL commands
{
client: 'sqlite3',
connection: {
filename: ':memory:',
},
useNullAsDefault: true,
}
-
Sets universe variable
_cukelib.currentDatabase
to the name from the config. -
Returns a promise for a
cukelib
service object:
{
name: <name from the config>,
dbConn: <knex database connection object>,
stop: <stop Function>,
config: <merged config object>
}
Convenience method that wraps serviceControl.initialize()
Returns the service object created by knexService.launch