{"id":13402988,"url":"https://github.com/knex/knex","last_synced_at":"2026-04-01T23:52:07.140Z","repository":{"id":6134752,"uuid":"7363211","full_name":"knex/knex","owner":"knex","description":"A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.","archived":false,"fork":false,"pushed_at":"2026-04-01T07:43:29.000Z","size":18982,"stargazers_count":20255,"open_issues_count":705,"forks_count":2192,"subscribers_count":197,"default_branch":"master","last_synced_at":"2026-04-01T08:37:53.250Z","etag":null,"topics":["javascript","knex","mysql","postgresql","sql","sqlite3"],"latest_commit_sha":null,"homepage":"https://knexjs.org/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2012-12-29T05:18:25.000Z","updated_at":"2026-04-01T07:43:36.000Z","dependencies_parsed_at":"2025-12-11T12:03:20.600Z","dependency_job_id":null,"html_url":"https://github.com/knex/knex","commit_stats":{"total_commits":2667,"total_committers":585,"mean_commits":4.558974358974359,"dds":0.7326584176977877,"last_synced_commit":"176151d8048b2a7feeb89a3d649a5580786d4f4e"},"previous_names":["tgriesser/knex"],"tags_count":189,"template":false,"template_full_name":null,"purl":"pkg:github/knex/knex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knex%2Fknex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knex%2Fknex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knex%2Fknex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knex%2Fknex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knex","download_url":"https://codeload.github.com/knex/knex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knex%2Fknex/sbom","scorecard":{"id":564453,"data":{"date":"2025-08-11","repo":{"name":"github.com/knex/knex","commit":"9bd12999907436c2ef51f786df09a9a7e8931cca"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Code-Review","score":7,"reason":"Found 20/27 approved changesets -- score normalized to 7","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:17","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:18","Info: jobLevel 'contents' permission set to 'read': .github/workflows/coverage.yml:13","Warn: jobLevel 'checks' permission set to 'write': .github/workflows/coverage.yml:12","Info: topLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:12","Info: topLevel 'contents' permission set to 'read': .github/workflows/coverage.yml:7","Warn: no topLevel permission defined: .github/workflows/docs-deploy.yml:1","Info: topLevel 'contents' permission set to 'read': .github/workflows/integration-tests.yml:13","Info: topLevel 'contents' permission set to 'read': .github/workflows/linting.yml:13","Info: topLevel 'contents' permission set to 'read': .github/workflows/unit-tests.yml:13"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/coverage.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/coverage.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/coverage.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/coverage.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/coverage.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/coverage.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs-deploy.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/docs-deploy.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs-deploy.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/docs-deploy.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs-deploy.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/docs-deploy.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/docs-deploy.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/docs-deploy.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration-tests.yml:116: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/integration-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration-tests.yml:120: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/integration-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration-tests.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/integration-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration-tests.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/integration-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/linting.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/linting.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/linting.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/linting.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-tests.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/unit-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-tests.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/knex/knex/unit-tests.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/coverage.yml:40","Warn: npmCommand not pinned by hash: .github/workflows/coverage.yml:43","Warn: npmCommand not pinned by hash: .github/workflows/integration-tests.yml:60","Warn: npmCommand not pinned by hash: .github/workflows/integration-tests.yml:71","Warn: npmCommand not pinned by hash: .github/workflows/integration-tests.yml:131","Warn: npmCommand not pinned by hash: .github/workflows/linting.yml:38","Warn: npmCommand not pinned by hash: .github/workflows/unit-tests.yml:38","Warn: npmCommand not pinned by hash: .github/workflows/unit-tests.yml:41","Info:   0 out of  16 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   1 out of   9 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":0,"reason":"13 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-x7hr-w5r2-h6wg","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g","Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3","Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx","Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6","Warn: Project is vulnerable to: GHSA-x574-m823-4x7w","Warn: Project is vulnerable to: GHSA-4r4m-qw57-chr8","Warn: Project is vulnerable to: GHSA-xcj6-pq6g-qj4x","Warn: Project is vulnerable to: GHSA-356w-63v5-8wf4","Warn: Project is vulnerable to: GHSA-859w-5945-r5v3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 3 commits out of 26 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T14:35:52.986Z","repository_id":6134752,"created_at":"2025-08-20T14:35:52.986Z","updated_at":"2025-08-20T14:35:52.986Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31293124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","knex","mysql","postgresql","sql","sqlite3"],"created_at":"2024-07-30T19:01:23.840Z","updated_at":"2026-04-01T23:52:07.127Z","avatar_url":"https://github.com/knex.png","language":"JavaScript","readme":"# [knex.js](https://knex.github.io/documentation/)\n\n[![npm version](http://img.shields.io/npm/v/knex.svg)](https://npmjs.org/package/knex)\n[![npm downloads](https://img.shields.io/npm/dm/knex.svg)](https://npmjs.org/package/knex)\n![](https://github.com/knex/knex/workflows/CI/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/knex/knex/badge.svg?branch=master)](https://coveralls.io/r/knex/knex?branch=master)\n[![Dependencies Status](https://img.shields.io/librariesio/github/knex/knex)](https://libraries.io/npm/knex)\n[![Gitter chat](https://badges.gitter.im/tgriesser/knex.svg)](https://gitter.im/tgriesser/knex)\n\n\u003e **A SQL query builder that is _flexible_, _portable_, and _fun_ to use!**\n\nA batteries-included, multi-dialect (PostgreSQL, MariaDB, MySQL, CockroachDB, MSSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for\nNode.js, featuring:\n\n- [transactions](https://knexjs.org/guide/transactions.html)\n- [connection pooling](https://knexjs.org/guide/#pool)\n- [streaming queries](https://knexjs.org/guide/interfaces.html#streams)\n- both a [promise](https://knexjs.org/#Interfaces-Promises) and [callback](https://knexjs.org/guide/interfaces.html#callbacks) API\n- a [thorough test suite](https://github.com/knex/knex/actions)\n\nNode.js versions 16+ are supported.\n\n- Take a look at the [full documentation](https://knexjs.org/) to get started!\n- Browse the [list of plugins and tools](https://github.com/knex/knex/blob/master/ECOSYSTEM.md) built for knex\n- Check out our [recipes wiki](https://github.com/knex/knex/wiki/Recipes) to search for solutions to some specific problems\n- In case of upgrading from an older version, see [migration guide](https://github.com/knex/knex/blob/master/UPGRADING.md)\n\nYou can report bugs and discuss features on the [GitHub issues page](https://github.com/knex/knex/issues) or send tweets to [@kibertoad](http://twitter.com/kibertoad).\n\nFor support and questions, join our [Gitter channel](https://gitter.im/tgriesser/knex).\n\nFor knex-based Object Relational Mapper, see:\n\n- https://github.com/Vincit/objection.js\n- https://github.com/mikro-orm/mikro-orm\n- https://bookshelfjs.org\n\nTo see the SQL that Knex will generate for a given query, you can use [Knex Query Lab](https://michaelavila.com/knex-querylab/)\n\n## Local Development Setup\n\n### Prerequisites\n\n- Node.js 16+\n- Python 3.x with `setuptools` installed (required for building native dependencies like `better-sqlite3`)\n\n  Python 3.12+ removed the built-in `distutils` module. If you encounter a `ModuleNotFoundError: No module named 'distutils'` error during `npm install`, install `setuptools` for the Python version used by node-gyp:\n\n  ```bash\n  pip install setuptools\n  ```\n\n- **Windows only:** [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) with the \"Desktop development with C++\" workload\n\n### Install dependencies\n\n```bash\nnpm install\n```\n\n## Examples\n\nWe have several examples [on the website](http://knexjs.org). Here is the first one to get you started:\n\n```js\nconst knex = require('knex')({\n  client: 'sqlite3',\n  connection: {\n    filename: './data.db',\n  },\n});\n\ntry {\n  // Create a table\n  await knex.schema\n    .createTable('users', (table) =\u003e {\n      table.increments('id');\n      table.string('user_name');\n    })\n    // ...and another\n    .createTable('accounts', (table) =\u003e {\n      table.increments('id');\n      table.string('account_name');\n      table.integer('user_id').unsigned().references('users.id');\n    });\n\n  // Then query the table...\n  const insertedRows = await knex('users').insert({ user_name: 'Tim' });\n\n  // ...and using the insert id, insert into the other table.\n  await knex('accounts').insert({\n    account_name: 'knex',\n    user_id: insertedRows[0],\n  });\n\n  // Query both of the rows.\n  const selectedRows = await knex('users')\n    .join('accounts', 'users.id', 'accounts.user_id')\n    .select('users.user_name as user', 'accounts.account_name as account');\n\n  // map over the results\n  const enrichedRows = selectedRows.map((row) =\u003e ({ ...row, active: true }));\n\n  // Finally, add a catch statement\n} catch (e) {\n  console.error(e);\n}\n```\n\n## TypeScript example\n\n```ts\nimport { Knex, knex } from 'knex';\n\ninterface User {\n  id: number;\n  age: number;\n  name: string;\n  active: boolean;\n  departmentId: number;\n}\n\nconst config: Knex.Config = {\n  client: 'sqlite3',\n  connection: {\n    filename: './data.db',\n  },\n  useNullAsDefault: true,\n};\n\nconst knexInstance = knex(config);\n\nknexInstance\u003cUser\u003e('users')\n  .select()\n  .then((users) =\u003e {\n    console.log(users);\n  })\n  .catch((err) =\u003e {\n    console.error(err);\n  })\n  .finally(() =\u003e {\n    knexInstance.destroy();\n  });\n```\n\n## Usage as ESM module\n\nIf 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.\nOtherwise, if you want to use named imports, you'll have to import knex like this:\n\n```js\nimport { knex } from 'knex/knex.mjs';\n```\n\nYou can also just do the default import:\n\n```js\nimport knex from 'knex';\n```\n\nIf you are not using TypeScript and would like the IntelliSense of your IDE to work correctly, it is recommended to set the type explicitly:\n\n```js\n/**\n * @type {Knex}\n */\nconst database = knex({\n  client: 'mysql',\n  connection: {\n    host: '127.0.0.1',\n    user: 'your_database_user',\n    password: 'your_database_password',\n    database: 'myapp_test',\n  },\n});\ndatabase.migrate.latest();\n```\n","funding_links":[],"categories":["JavaScript","Packages","Install from Source","Parallel Systems Learning Resources","JavaScript框架","javascript","ORM","Recently Updated","sql","包"],"sub_categories":["Database","Databases","Parallel Systems Courses \u0026 Tutorials","其他_文本生成、文本对话","Other","[Feb 17, 2025](/content/2025/02/17/README.md)","数据库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknex%2Fknex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknex%2Fknex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknex%2Fknex/lists"}