网页
综合
更新时间 2026-06-26 14:59:48
Installation | Knex.js
自动蜘蛛
knexjs.org
正文约 2684 字
acquireConnectionTimeout
defaultDateTimePrecision
only (knex/from option) PG only
withRecursive MYCRRS
withMaterialized PG+SQ only
withNotMaterialized PG+SQ only
forUpdate PG+MY only
forNoKeyUpdate PG only
skipLocked PG+MY only
hintComment MY+OR only
Extending Query Builder
whereJsonSupersetOf SQMSORRS
whereJsonSubsetOf SQMSORRS
crossJoin conditions MY+SQ only
createViewOrReplace ~SQ
createMaterializedView MYSQMS
refreshMaterializedView MYSQMS
dropMaterializedView MYSQMS
dropMaterializedViewIfExists MYSQMS
createSchema PG only
createSchemaIfNotExists PG only
dropSchemaIfExists PG only
localCheckOption SQMSORCR
cascadedCheckOption SQMSORCR
Named bindings with array values
Environment configuration
Custom migration name
Generated migration extension
Knexfile in other languages
Transactions in migrations
Webpack migration source example
ECMAScript modules (ESM) Interoperability
Knex can be used as an SQL query builder in both Node.JS and the browser, limited to WebSQL's constraints (like the inability to drop tables or read schemas). Composing SQL queries in the browser for execution on the server is highly discouraged, as this can be the cause of serious security vulnerabilities. The browser builds outside of WebSQL are primarily for learning purposes - for example, you can pop open the console and build queries on this page using the knex object.
The primary target environment for Knex is Node.js, you will need to install the knex library, and then install the appropriate database library: pg for PostgreSQL, CockroachDB and Amazon Redshift, pg-native for PostgreSQL with native C++ libpq bindings (requires PostgresSQL installed to link against), mysql for MySQL or MariaDB, sqlite3 for SQLite3, or tedious for MSSQL.
If you want to use CockroachDB or Redshift instance, you can use the pg driver.
If you want to use a MariaDB instance, you can use the mysql driver.
Knex can be built using a JavaScript build tool such as browserify or webpack. In fact, this documentation uses a webpack build which includes knex. View source on this page to see the browser build in-action (the global knex variable).
The knex module is itself a function which takes a configuration object for Knex, accepting a few parameters. The client parameter is required and determines which client adapter will be used with the library.
The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, a connection string, or a function returning an object:
Knex's PostgreSQL client allows you to set the initial search path for each connection automatically using an additional option "searchPath" as shown below.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。