Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-utils

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-utils

knex.js utils

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
580
decreased by-41.47%
Maintainers
1
Weekly downloads
 
Created
Source

Knex Utils

Common utilities for knex.js

DB migration/seeding example with gulp

const knexUtils = require('knex-utils');

gulp.task('migrateDb', (cb) => { knexUtils.tools.migrateDb('./db/migrations', 'migrations') .then(() => knexUtils.tools.closeConnection().then(() => cb())) .catch(() => knexUtils.tools.closeConnection().then(() => cb())); });

gulp.task('cleanDb', (cb) => { knexUtils.tools.cleanDb(['TABLE_1', 'TABLE_2']) .then(() => knexUtils.tools.closeConnection().then(() => cb())) .catch(() => knexUtils.tools.closeConnection().then(() => cb())); });

gulp.task('seedDb', (cb) => { knexUtils.tools.seedDb('./db/seeds') .then(() => { setTimeout(() => { knexUtils.tools.closeConnection().then(() => cb()); // this totally shouldn't be necessary but otherwise it tries to close connection with unfinished calls }, 5000); }) .catch(() => knexUtils.tools.closeConnection().then(() => cb())); });

##Example of a usage inside actual application

knex.instance.js:

const config = require('../config/config'); const logger = require('./logger'); const knexUtils = require('knex-utils');

const dbConfig = config.get('DB');

knexUtils.config.setLogger(logger); knexUtils.config.setConfig({ client: dbConfig.CLIENT, username: dbConfig.USER, password: dbConfig.PASSWORD, hostname: dbConfig.HOST, database: dbConfig.DATABASE, connectionTimeout: dbConfig.ACQUIRE_CONNECTION_TIMEOUT, minPoolSize: dbConfig.MIN_POOL_SIZE, maxPoolSize: dbConfig.MAX_POOL_SIZE, heartbeatQuery: dbConfig.HEARTBEAT_QUERY });

module.exports = dbUtils.knexHelperFactory.getInstance();

let knex = require('../helpers/knex.instance').getKnexInstance();

FAQs

Package last updated on 23 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc