MCPcopy
hub / github.com/knex/knex

github.com/knex/knex @016.5 sqlite

repository ↗ · DeepWiki ↗ · release 016.5 ↗
1,112 symbols 2,811 edges 191 files 3 documented · 0%
README

knex.js

npm version Build Status 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 6+ 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: - http://bookshelfjs.org - https://github.com/Vincit/objection.js

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

Extension points exported contracts — how you extend this code

Transaction (Interface)
(no doc) [3 implementers]
types/knex.d.ts
Sqlite3ConnectionConfig (Interface)
Used with SQLite3 adapter
types/knex.d.ts
Migrator (Interface)
(no doc) [1 implementers]
types/knex.d.ts
Knex (Interface)
(no doc)
types/knex.d.ts
QueryInterface (Interface)
(no doc)
types/knex.d.ts

Core symbols most depended-on inside this repo

toSQL
called by 545
types/knex.d.ts
table
called by 460
types/knex.d.ts
qb
called by 377
test/unit/query/builder.js
testsql
called by 300
test/unit/query/builder.js
knex
called by 226
src/util/make-knex.js
string
called by 207
types/knex.d.ts
createTable
called by 157
types/knex.d.ts
wrap
called by 135
types/knex.d.ts

Shape

Function 768
Method 245
Interface 65
Class 34

Languages

TypeScript100%

Modules by API surface

types/knex.d.ts222 symbols
src/query/builder.js118 symbols
src/query/compiler.js58 symbols
src/client.js36 symbols
src/query/joinclause.js28 symbols
src/migrate/Migrator.js27 symbols
src/dialects/mssql/index.js24 symbols
src/util/make-knex.js21 symbols
src/dialects/postgres/index.js21 symbols
src/dialects/mysql/schema/columncompiler.js20 symbols
src/formatter.js18 symbols
src/dialects/oracle/index.js18 symbols

Dependencies from manifests, versioned

@babel/cli7.4.3 · 1×
@babel/core7.4.3 · 1×
@babel/polyfill7.4.3 · 1×
@babel/preset-env7.4.3 · 1×
@types/bluebird3.5.26 · 1×
@types/node11.11.3 · 1×
JSONStream1.3.5 · 1×
async2.6.2 · 1×
babel-eslint10.0.1 · 1×
babel-plugin-add-module-exports1.0.0 · 1×
bluebird3.5.4 · 1×
chai4.2.0 · 1×

Datastores touched

(mysql)Database · 1 repos
dbnameDatabase · 1 repos
testdbDatabase · 1 repos
knex_testDatabase · 1 repos
postgresDatabase · 1 repos
testdbDatabase · 1 repos

For agents

$ claude mcp add knex \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact