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
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
npm install knex
85.6
Supply Chain
98.6
Quality
82.2
Maintenance
100
Vulnerability
99.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
19,400 Stars
3,075 Commits
2,131 Forks
209 Watching
31 Branches
616 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (96.22%)
TypeScript (3.66%)
Shell (0.12%)
Cumulative downloads
Total Downloads
Last day
-10.8%
341,310
Compared to previous day
Last week
-0.6%
1,999,898
Compared to previous week
Last month
10.1%
8,327,146
Compared to previous month
Last year
13.7%
88,228,363
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();
The latest stable version of the package.
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-11-18
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