Package Exports
- knex
- knex/bin/cli
- 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/migrate/Migrator.js
- knex/src/query/builder
- knex/src/query/compiler
- knex/src/query/string
- knex/src/raw
- knex/src/schema/builder
- knex/src/seed/Seeder.js
- knex/src/util/noop.js
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)) query builder for Node.js, featuring:
- transactions
- connection pooling
- streaming queries
- both a promise and callback API
- a thorough test suite
- the ability to run in the Browser
Node.js versions 8+ are supported.
Read the full documentation to get started!
Or check out our Recipes wiki to search for solutions to some specific problems
If upgrading from older version, see Upgrading instructions
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:
const 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('users').insert({ user_name: 'Tim' });
})
// ...and using the insert id, insert into the other table.
.then(function(rows) {
return knex('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);
});