Package Exports
- knex
- knex/bin/cli
- knex/lib/client
- knex/lib/dialects/mssql
- knex/lib/dialects/mssql/transaction.js
- knex/lib/dialects/mysql
- knex/lib/dialects/mysql/index
- knex/lib/dialects/mysql/index.js
- knex/lib/dialects/mysql/query/compiler
- knex/lib/dialects/mysql/schema/columncompiler
- knex/lib/dialects/mysql/schema/compiler
- knex/lib/dialects/mysql/schema/tablecompiler
- knex/lib/dialects/mysql2
- knex/lib/dialects/oracle
- knex/lib/dialects/oracledb/utils
- knex/lib/dialects/postgres
- knex/lib/dialects/postgres/query/compiler
- knex/lib/dialects/postgres/schema/tablecompiler.js
- knex/lib/dialects/sqlite3
- knex/lib/dialects/sqlite3/index
- knex/lib/dialects/sqlite3/index.js
- knex/lib/dialects/sqlite3/query/compiler
- knex/lib/dialects/sqlite3/schema/columncompiler
- knex/lib/dialects/sqlite3/schema/compiler
- knex/lib/dialects/sqlite3/schema/ddl
- knex/lib/dialects/sqlite3/schema/tablecompiler
- knex/lib/dialects/websql/index.js
- knex/lib/formatter
- knex/lib/functionhelper
- knex/lib/helpers
- knex/lib/index
- knex/lib/interface
- knex/lib/migrate
- knex/lib/migrate/index.js
- knex/lib/query/builder
- knex/lib/query/compiler
- knex/lib/query/joinclause
- knex/lib/query/methods
- knex/lib/query/string
- knex/lib/raw
- knex/lib/runner
- knex/lib/schema/builder
- knex/lib/schema/columnbuilder
- knex/lib/schema/columncompiler
- knex/lib/schema/compiler
- knex/lib/schema/tablebuilder
- knex/lib/schema/tablecompiler
- knex/lib/schema/tablecompiler.js
- knex/lib/seed
- knex/lib/seed/index.js
- knex/lib/transaction
- knex/lib/transaction.js
- knex/lib/util/make-knex
- knex/lib/util/noop.js
- knex/lib/util/parse-connection
- knex/package
- knex/package.json
- knex/src/client
- knex/src/dialects/mssql
- knex/src/dialects/mysql
- knex/src/dialects/mysql/index
- knex/src/dialects/mysql2
- knex/src/dialects/oracle
- knex/src/dialects/postgres
- knex/src/dialects/postgres/query/compiler
- knex/src/dialects/sqlite3
- knex/src/formatter
- knex/src/query/builder
- knex/src/query/compiler
- knex/src/query/string
- knex/src/raw
- knex/src/schema/builder
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (knex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
knex.js
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:
- transactions
- connection pooling
- streaming queries
- both a promise and callback API
- a thorough test suite
- the ability to run in the Browser
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);
});