[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3158":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":22,"topics":23,"createdAt":9,"pushedAt":9,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":15,"starSnapshotCount":15,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},3158,"knex","knex\u002Fknex","A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.","https:\u002F\u002Fknexjs.org\u002F",null,"JavaScript",20286,2198,197,572,0,5,27,45,"MIT License",false,"master",true,[24,5,25,26,27,28],"javascript","mysql","postgresql","sql","sqlite3","2026-06-12 02:00:46","# [knex.js](https:\u002F\u002Fknex.github.io\u002Fdocumentation\u002F)\n\n[![npm version](http:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fknex.svg)](https:\u002F\u002Fnpmjs.org\u002Fpackage\u002Fknex)\n[![npm downloads](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdm\u002Fknex.svg)](https:\u002F\u002Fnpmjs.org\u002Fpackage\u002Fknex)\n![](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Fworkflows\u002FCI\u002Fbadge.svg)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fknex\u002Fknex\u002Fgraph\u002Fbadge.svg?token=bH39w8lIA9)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fknex\u002Fknex)\n[![Dependencies Status](https:\u002F\u002Fimg.shields.io\u002Flibrariesio\u002Fgithub\u002Fknex\u002Fknex)](https:\u002F\u002Flibraries.io\u002Fnpm\u002Fknex)\n[![Gitter chat](https:\u002F\u002Fbadges.gitter.im\u002Ftgriesser\u002Fknex.svg)](https:\u002F\u002Fgitter.im\u002Ftgriesser\u002Fknex)\n\n> **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:\u002F\u002Fknexjs.org\u002Fguide\u002Ftransactions.html)\n- [connection pooling](https:\u002F\u002Fknexjs.org\u002Fguide\u002F#pool)\n- [streaming queries](https:\u002F\u002Fknexjs.org\u002Fguide\u002Finterfaces.html#streams)\n- both a [promise](https:\u002F\u002Fknexjs.org\u002F#Interfaces-Promises) and [callback](https:\u002F\u002Fknexjs.org\u002Fguide\u002Finterfaces.html#callbacks) API\n- a [thorough test suite](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Factions)\n\nNode.js versions 16+ are supported.\n\n- Take a look at the [full documentation](https:\u002F\u002Fknexjs.org\u002F) to get started!\n- Browse the [list of plugins and tools](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Fblob\u002Fmaster\u002FECOSYSTEM.md) built for knex\n- Check out our [recipes wiki](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Fwiki\u002FRecipes) to search for solutions to some specific problems\n- In case of upgrading from an older version, see [migration guide](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Fblob\u002Fmaster\u002FUPGRADING.md)\n\nYou can report bugs and discuss features on the [GitHub issues page](https:\u002F\u002Fgithub.com\u002Fknex\u002Fknex\u002Fissues) or send tweets to [@kibertoad](http:\u002F\u002Ftwitter.com\u002Fkibertoad).\n\nFor support and questions, join our [Gitter channel](https:\u002F\u002Fgitter.im\u002Ftgriesser\u002Fknex).\n\nFor knex-based Object Relational Mapper, see:\n\n- https:\u002F\u002Fgithub.com\u002FVincit\u002Fobjection.js\n- https:\u002F\u002Fgithub.com\u002Fmikro-orm\u002Fmikro-orm\n- https:\u002F\u002Fbookshelfjs.org\n\nTo see the SQL that Knex will generate for a given query, you can use [Knex Query Lab](https:\u002F\u002Fmichaelavila.com\u002Fknex-querylab\u002F)\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:\u002F\u002Fvisualstudio.microsoft.com\u002Fvisual-cpp-build-tools\u002F) 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:\u002F\u002Fknexjs.org). Here is the first one to get you started:\n\n```js\nconst knex = require('knex')({\n  client: 'sqlite3',\n  connection: {\n    filename: '.\u002Fdata.db',\n  },\n});\n\ntry {\n  \u002F\u002F Create a table\n  await knex.schema\n    .createTable('users', (table) => {\n      table.increments('id');\n      table.string('user_name');\n    })\n    \u002F\u002F ...and another\n    .createTable('accounts', (table) => {\n      table.increments('id');\n      table.string('account_name');\n      table.integer('user_id').unsigned().references('users.id');\n    });\n\n  \u002F\u002F Then query the table...\n  const insertedRows = await knex('users').insert({ user_name: 'Tim' });\n\n  \u002F\u002F ...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  \u002F\u002F 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  \u002F\u002F map over the results\n  const enrichedRows = selectedRows.map((row) => ({ ...row, active: true }));\n\n  \u002F\u002F 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: '.\u002Fdata.db',\n  },\n  useNullAsDefault: true,\n};\n\nconst knexInstance = knex(config);\n\nknexInstance\u003CUser>('users')\n  .select()\n  .then((users) => {\n    console.log(users);\n  })\n  .catch((err) => {\n    console.error(err);\n  })\n  .finally(() => {\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\u002Fknex.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\u002F**\n * @type {Knex}\n *\u002F\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","knex.js 是一个适用于 PostgreSQL、MySQL、CockroachDB、SQL Server、SQLite3 和 Oracle 的 SQL 查询构建器，旨在提供灵活性、可移植性和易用性。其核心功能包括事务处理、连接池管理、流式查询以及支持 Promise 和回调两种 API 方式。此外，它还具有全面的测试套件以保证代码质量。由于其多数据库支持和灵活的接口设计，knex 非常适合需要跨多种数据库类型进行开发的应用场景，尤其是那些基于 Node.js 构建的企业级应用或数据密集型服务。",2,"2026-06-11 02:52:42","top_language"]