Gathering detailed insights and metrics for knex
Gathering detailed insights and metrics for knex
Gathering detailed insights and metrics for knex
Gathering detailed insights and metrics for knex
@opentelemetry/instrumentation-knex
OpenTelemetry instrumentation for `knex` database SQL query builder
@mikro-orm/knex
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
knex-paginate
Extension of Knex's query builder with `paginate` method that will help with your pagination tasks.
knex-schema-inspector
Utility for extracting information about existing DB schema
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
npm install knex
Typescript
Module System
Min. Node Version
Node Version
NPM Version
93
Supply Chain
98.6
Quality
81.3
Maintenance
100
Vulnerability
99.3
License
JavaScript (95.24%)
TypeScript (4.63%)
Shell (0.12%)
Total Downloads
371,177,738
Last Day
97,238
Last Week
2,117,107
Last Month
9,566,332
Last Year
98,172,927
MIT License
19,899 Stars
3,082 Commits
2,155 Forks
206 Watchers
33 Branches
614 Contributors
Updated on Jun 30, 2025
Minified
Minified + Gzipped
Latest Version
3.1.0
Package Id
knex@3.1.0
Unpacked Size
853.40 kB
Size
208.67 kB
File Count
191
NPM Version
10.1.0
Node Version
20.9.0
Published on
Dec 07, 2023
Cumulative downloads
Total Downloads
Last Day
-3.7%
97,238
Compared to previous day
Last Week
-8.6%
2,117,107
Compared to previous week
Last Month
-1.1%
9,566,332
Compared to previous month
Last Year
17.2%
98,172,927
Compared to previous year
14
40
A SQL query builder that is flexible, portable, and fun to use!
A batteries-included, multi-dialect (PostgreSQL, MySQL, CockroachDB, MSSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for Node.js, featuring:
Node.js versions 12+ are supported.
You can report bugs and discuss features on the GitHub issues page or send tweets to @kibertoad.
For support and questions, join our Gitter channel.
For knex-based Object Relational Mapper, see:
To see the SQL that Knex will generate for a given query, you can use Knex Query Lab
We have several examples on the website. Here is the first one to get you started:
1const knex = require('knex')({ 2 client: 'sqlite3', 3 connection: { 4 filename: './data.db', 5 }, 6}); 7 8try { 9 // Create a table 10 await knex.schema 11 .createTable('users', (table) => { 12 table.increments('id'); 13 table.string('user_name'); 14 }) 15 // ...and another 16 .createTable('accounts', (table) => { 17 table.increments('id'); 18 table.string('account_name'); 19 table.integer('user_id').unsigned().references('users.id'); 20 }); 21 22 // Then query the table... 23 const insertedRows = await knex('users').insert({ user_name: 'Tim' }); 24 25 // ...and using the insert id, insert into the other table. 26 await knex('accounts').insert({ 27 account_name: 'knex', 28 user_id: insertedRows[0], 29 }); 30 31 // Query both of the rows. 32 const selectedRows = await knex('users') 33 .join('accounts', 'users.id', 'accounts.user_id') 34 .select('users.user_name as user', 'accounts.account_name as account'); 35 36 // map over the results 37 const enrichedRows = selectedRows.map((row) => ({ ...row, active: true })); 38 39 // Finally, add a catch statement 40} catch (e) { 41 console.error(e); 42}
1import { Knex, knex } from 'knex'; 2 3interface User { 4 id: number; 5 age: number; 6 name: string; 7 active: boolean; 8 departmentId: number; 9} 10 11const config: Knex.Config = { 12 client: 'sqlite3', 13 connection: { 14 filename: './data.db', 15 }, 16}; 17 18const knexInstance = knex(config); 19 20try { 21 const users = await knex<User>('users').select('id', 'age'); 22} catch (err) { 23 // error handling 24}
If you are launching your Node application with --experimental-modules
, knex.mjs
should be picked up automatically and named ESM import should work out-of-the-box.
Otherwise, if you want to use named imports, you'll have to import knex like this:
1import { knex } from 'knex/knex.mjs';
You can also just do the default import:
1import knex from 'knex';
If you are not using TypeScript and would like the IntelliSense of your IDE to work correctly, it is recommended to set the type explicitly:
1/** 2 * @type {Knex} 3 */ 4const database = knex({ 5 client: 'mysql', 6 connection: { 7 host: '127.0.0.1', 8 user: 'your_database_user', 9 password: 'your_database_password', 10 database: 'myapp_test', 11 }, 12}); 13database.migrate.latest();
9.8/10
Summary
SQL Injection in knex
Affected Versions
< 0.19.5
Patched Versions
0.19.5
7.5/10
Summary
Knex.js has a limited SQL injection vulnerability
Affected Versions
< 2.4.0
Patched Versions
2.4.0
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 20/27 approved changesets -- score normalized to 7
Reason
SAST tool detected but not run on all commits
Details
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More