Skip to content

d-band/sk2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sk2

NPM version NPM downloads Dependency Status Build Status Coverage Status Greenkeeper badge

sk2 is used for extend sequelize with knex.

Installation

npm install sk2

Example

const sk2 = require('sk2');
const Sequelize = require('sequelize');

const sequelize = new Sequelize('db_name', 'root', 'password', {
  dialect: 'mysql'
});

async function main() {
  const knex = sk2(sequelize);

  await knex.schema
    .createTable('users', function(table) {
      table.increments('id');
      table.string('user_name');
    })
    .createTable('accounts', function(table) {
      table.increments('id');
      table.string('account_name');
      table
        .integer('user_id')
        .unsigned()
        .references('users.id');
    });

  const rows = knex('users').insert({ user_name: 'Tim' });

  await knex('accounts').insert({
    account_name: 'sk2',
    user_id: rows[0]
  });

  const users = await knex('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account');

  console.log(users);
  // [{ user: 'Tim', account: 'sk2' }]
}

main().then(() => {
  sequelize.close();
});

License

MIT

About

Knex with sequelize query.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published