2020-12-28 00:09:58 +02:00
2020-12-25 21:02:20 +02:00
2020-12-26 19:29:46 +02:00
2020-12-22 10:28:58 +02:00
2020-08-16 19:22:26 +03:00
2020-12-25 20:48:40 +02:00
2020-12-27 22:50:29 +02:00
2020-12-26 19:17:31 +02:00
2019-07-10 23:48:43 +02:00
2016-08-09 13:33:47 -04:00
2020-12-27 16:30:40 +02:00
2020-12-27 16:30:40 +02:00
2020-12-26 19:29:46 +02:00

knex.js

npm version npm downloads Coverage Status Dependencies Status Gitter chat Language Grade: JavaScript

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:

Node.js versions 10+ are supported.

You can report bugs and discuss features on the GitHub issues page or send tweets to @kibertoad.

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

For knex-based 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')({
  client: 'sqlite3',
  connection: {
    filename: './data.db',
  },
});

try {

  // Create a table
  await knex.schema
    .createTable('users', table => {
      table.increments('id');
      table.string('user_name');
    })
    // ...and another
    .createTable('accounts', table => {
      table.increments('id');
      table.string('account_name');
      table
        .integer('user_id')
        .unsigned()
        .references('users.id');
    })

  // Then query the table...
  const insertedRows = await knex('users').insert({ user_name: 'Tim' })

  // ...and using the insert id, insert into the other table.
  await knex('accounts').insert({ account_name: 'knex', user_id: insertedRows[0] })

  // Query both of the rows.
  const selectedRows = await knex('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account')

  // map over the results
  const enrichedRows = selectedRows.map(row => ({ ...row, active: true }))

  // Finally, add a catch statement
} catch(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 59 MiB
Languages
JavaScript 95.3%
TypeScript 4.6%
Shell 0.1%