Zenkit/Knex


License: MIT

Language: JavaScript


knex.js Build Status Coverage Status

Gitter chat Gitter chat

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

A batteries-included, multi-dialect (MySQL, PostgreSQL, SQLite3, WebSQL, Oracle) 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

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

Project Statistics

Sourcerank 3
Repository Size 2.9 MB
Stars 1
Forks 0
Watchers 1
Open issues 0
Dependencies 0
Contributors 87
Tags 84
Created
Last updated
Last pushed

Top Contributors See all

Tim Griesser Ben Drucker Vincent Schoettke Noah Santorello Calvin Metcalf Stephan Schneider Nikhil Benesch Tyler Kellen Hung Tran Vaughan Rouesnel Nicolas Stepien Brian Delahunty David H. Bronke Johannes Lumpe Sohum Banerjea Petr Kobalicek jblebrun Luigy Leon Elliot Foster Michael Demmer

Recent Tags See all

0.8.6 May 20, 2015
0.8.5 May 14, 2015
0.8.4 May 13, 2015
0.8.3 May 02, 2015
0.8.2 May 01, 2015
0.8.1 May 01, 2015
0.8.0 April 30, 2015
0.7.6 March 13, 2015
0.6.23 March 13, 2015
0.7.5 March 10, 2015
0.7.4 February 25, 2015
0.7.3 October 03, 2014
0.7.2 October 01, 2014
0.7.1 October 01, 2014
0.7.0 October 01, 2014

Something wrong with this page? Make a suggestion

Last synced: 2016-07-29 08:19:57 UTC

Login to resync this repository