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
@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.
@opentelemetry/instrumentation-knex
OpenTelemetry instrumentation for `knex` database SQL query builder
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
JavaScript (96.22%)
TypeScript (3.66%)
Shell (0.12%)
Total
320,922,834
Last Day
82,447
Last Week
1,914,062
Last Month
8,102,975
Last Year
88,181,870
19,432 Stars
3,075 Commits
2,136 Forks
209 Watching
31 Branches
616 Contributors
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
Publised On
07 Dec 2023
Cumulative downloads
Total Downloads
Last day
-5%
82,447
Compared to previous day
Last week
5.6%
1,914,062
Compared to previous week
Last month
3.3%
8,102,975
Compared to previous month
Last year
12.8%
88,181,870
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();
Stable Version
1
9.8/10
Summary
SQL Injection in knex
Affected Versions
< 0.19.5
Patched Versions
0.19.5
1
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
license file detected
Details
Reason
no binaries found in the repo
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 19/27 approved changesets -- score normalized to 7
Reason
4 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-12-02
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