Skip to content

Knex utilities to interact with Postgres database 🗄

License

Notifications You must be signed in to change notification settings

smooth-code/knex-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knex Scripts

Build Status

Knex utilities to interact with Postgres database.

npm install knex-scripts

Command Line Usage

  Usage: knex-scripts [options] [command]


  Options:

    -V, --version      output the version number
    --docker           Use docker.
    --knexfile [path]  Specify the knexfile path.
    --cwd [path]       Specify the working directory.
    --env [name]       environment, default: process.env.NODE_ENV || development
    -h, --help         output usage information


  Commands:

    create    Create database.
    drop      Drop database.
    dump      Dump database.
    load      Load database.
    truncate  Truncate all tables.

Node API Usage

import knex from 'knex'
import { truncate } from 'knex-scripts'
import config from './knexfile'

// Truncate all database
truncate({ getKnex: () => knex(config) })
  .then(() => console.log('Truncated'))
  .catch(console.error)

Configuration

// knexfile.js
const config = {
  knexScripts: {
    docker: false,
    structurePath: 'db/structure.sql',
  },
  development: {
    client: 'postgresql',
    connection: {
      user: 'postgres',
      database: 'development',
      timezone: 'utc',
    },
  },
}

module.exports = config

License

MIT