knex 0,6,3,0,6,8,1,0 travis-ci npm

A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

2 years after MIT

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), WebSQL) query builder for Node.js and the Browser, featuring:

Read the full documentation to get started!

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

For an Object Relational Mapper, see: http://bookshelfjs.org

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);
});

Related Repositories

knex-postgis

knex-postgis

postgis extension for knex ...

knex-orm

knex-orm

Knex-based object-relational mapping for JavaScript. ...

knex-schema-builder

knex-schema-builder

A schema builder module for knex.js, handles schema initialization and migration ...

connect-session-knex

connect-session-knex

A knex.js session store for express-session, supporting PostgreSQL, MySQL, Maria ...

graphql-knex-resolver

graphql-knex-resolver

Knex Resolver for GraphQL. Allows you to define GraphQL schemas and run queries ...


Top Contributors

tgriesser wubzz rhys-vdw elhigu bendrucker vschoettke jurko-gospodnetic Grimace1975 nsantorello harriha calvinmetcalf blah238 funnylookinhat bblack beppu byronmwong danieltdt vellotis jevakallio sandorfr oohnoitz benesch zcei tkellen gmichael225 briandela whitelynx atiertant johanneslumpe luigy

Dependencies

package version
babel-runtime ^6.23.0
bluebird ^3.4.6
chalk ^1.0.0
commander ^2.2.0
debug ^2.1.3
generic-pool ^2.4.2
inherits ~2.0.1
interpret ^0.6.5
liftoff ~2.2.0
lodash ^4.6.0
minimist ~1.1.0
mkdirp ^0.5.0
pg-connection-string ^0.1.3
readable-stream ^1.1.12
safe-buffer ^5.0.1
tildify ~1.0.0
uuid ^3.0.0
v8flags ^2.0.2
dev JSONStream ^1.0.3
async ^0.9.0
babel-cli ^6.11.4
babel-eslint ^5.0.0
babel-plugin-add-module-exports ^0.2.1
babel-plugin-lodash 3.2.9
babel-plugin-transform-runtime ^6.12.0
babel-preset-es2015 ^6.13.2
chai ^3.5.0
coveralls ~2.11.1
dockerode ^2.4.3
eslint 2.2.0
eslint-plugin-import ^1.8.0
istanbul ^0.4.5
json-loader ^0.5.4
mariasql ^0.2.3
mocha ^3.1.2
mock-fs ^4.4.1
mssql ^4.0.0
mysql ^2.6.2
mysql2 ^1.1.1
pg ^6.1.0
pg-query-stream ^1.0.0
rimraf 2.x
sinon ^1.10.0
sinon-chai ^2.5.0
source-map-support ^0.4.0
sqlite3 ^3.0.5
tap-spec ^4.0.0
tape ^4.0.0
through ^2.3.4

Releases

-   0.12.2 zip tar
-   0.12.1 zip tar
-   0.12.0 zip tar
-   0.11.10 zip tar
-   0.11.9 zip tar
-   0.11.8 zip tar
-   0.11.7 zip tar
-   0.11.6 zip tar
-   0.11.5 zip tar
-   0.11.4 zip tar
-   0.11.3 zip tar
-   0.11.2 zip tar
-   0.11.1 zip tar
-   0.11.0 zip tar
-   0.10.0 zip tar
-   0.10.0-rc1 zip tar
-   0.9.0 zip tar
-   0.8.6 zip tar
-   0.8.5 zip tar
-   0.8.4 zip tar
-   0.8.3 zip tar
-   0.8.2 zip tar
-   0.8.1 zip tar
-   0.8.0 zip tar
-   0.7.6 zip tar
-   0.7.5 zip tar
-   0.7.4 zip tar
-   0.7.3 zip tar
-   0.7.2 zip tar
-   0.7.1 zip tar