knex-env-config
v1.0.1
Published
Create Knex config objects with defaults loaded from the environment.
Downloads
7
Readme
Knex Env Config
Create Knex config objects with defaults loaded from the environment.
Usage
Install
npm install knex-env-config
Example
Create a Knex config object by calling knexEnvConfig
and pass it to the Knex
constructor:
import Knex from 'knex';
import knexEnvConfig from 'knex-env-config';
const knexConfig = knexEnvConfig();
const knex = Knex(knexConfig);
Or override some options:
const knexConfig = knexEnvConfig({
client: 'sqlite3',
connection: {
filename: 'database.sqlite',
},
});
const knex = Knex(knexConfig);
Or pass a custom env
object:
const env = {
DATABASE_USER: 'root'
};
const knexConfig = knexEnvConfig.withEnv({
client: 'pg',
connection: {
host: 'localhost',
},
}, env);
const knex = Knex(knexConfig);
Supported options
See the Knex docs for more info.
|env key|knex option|
|-|-|
|DATABASE_CLIENT
|client
||
|DATABASE_VERSION
|version
||
|DATABASE_DEBUG
|debug
||
|DATABASE_URL
|connection
||
|DATABASE_USER
|connection.user
||
|DATABASE_PASSWORD
|connection.password
||
|DATABASE_HOST
|connection.host
||
|DATABASE_NAME
|connection.database
||
|DATABASE_FILENAME
|connection.filename
||
|DATABASE_SOCKET_PATH
|connection.socketPath
||
|DATABASE_POOL_MIN
|pool.min
||
|DATABASE_POOL_MAX
|pool.max
||
|DATABASE_SEEDS_DIRECTORY
|seeds.directory
||
|DATABASE_MIGRATIONS_DIRECTORY
|migrations.directory
||
|DATABASE_MIGRATIONS_TABLE
|migrations.tableName
||