Igor Savin 1f8567393c Fix ES6 support (#2821)
* Add polyfills for Node 6
2018-09-27 00:41:00 +03:00
2018-07-09 08:10:34 -04:00
2018-09-19 01:25:58 +03:00
2018-07-09 08:10:34 -04:00
2018-07-09 15:58:22 -04:00
2018-07-09 08:10:34 -04:00
2018-07-13 09:26:46 -04:00
2018-09-26 23:11:30 +03:00
2018-09-26 23:11:30 +03:00
2018-09-27 00:41:00 +03:00
2016-08-09 13:33:47 -04:00
2018-09-27 00:41:00 +03:00
2018-06-18 22:36:02 +03:00

knex.js

npm version Build Status Coverage Status Dependencies Status Gitter chat

A SQL query builder that is flexible, portable, and fun to use!

A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle(including Oracle Wallet Authentication)) query builder for Node.js and the Browser, featuring:

Node.js versions 6+ are supported.

Read the full documentation to get started!

For support and questions, join the #bookshelf channel on freenode IRC

For an Object Relational Mapper, see:

To see the SQL that Knex will generate for a given query, see: Knex Query Lab

Examples

We have several examples on the website. Here is the first one to get you started:

var knex = require('knex')({
  dialect: 'sqlite3',
  connection: {
    filename: './data.db'
  }
});

// Create a table
knex.schema.createTable('users', function(table) {
  table.increments('id');
  table.string('user_name');
})

// ...and another
.createTable('accounts', function(table) {
  table.increments('id');
  table.string('account_name');
  table.integer('user_id').unsigned().references('users.id');
})

// Then query the table...
.then(function() {
  return knex.insert({user_name: 'Tim'}).into('users');
})

// ...and using the insert id, insert into the other table.
.then(function(rows) {
  return knex.table('accounts').insert({account_name: 'knex', user_id: rows[0]});
})

// Query both of the rows.
.then(function() {
  return knex('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account');
})

// .map over the results
.map(function(row) {
  console.log(row);
})

// Finally, add a .catch handler for the promise chain
.catch(function(e) {
  console.error(e);
});
Description
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
Readme MIT 57 MiB
Languages
JavaScript 95.3%
TypeScript 4.6%
Shell 0.1%