网页
综合
更新时间 2026-06-26 14:59:48
Interfaces | Knex.js
自动蜘蛛
knexjs.org
正文约 2763 字
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.js provides several options to deal with query output. The following methods are present on the query builder, schema builder, and the raw builder:
Promises are the preferred way of dealing with queries in knex, as they allow you to return values from a fulfillment handler, which in turn become the value of the promise. The main benefit of promises are the ability to catch thrown errors without crashing the node app, making your code behave like a .try / .catch / .finally in synchronous code.
.then(onFulfilled, [onRejected])
Coerces the current query builder chain into a promise state, accepting the resolve and reject handlers as specified by the Promises/A+ spec. As stated in the spec, more than one call to the then method for the current query chain will resolve with the same value, in the order they were called; the query will not be executed multiple times.
Coerces the current query builder into a promise state, catching any error thrown by the query, the same as calling .then(null, onRejected).
.asCallback(callback)
If you'd prefer a callback interface over promises, the asCallback function accepts a standard node style callback for executing the query chain. Note that as with the then method, subsequent calls to the same query chain will return the same result.
Streams are a powerful way of piping data through as it comes in, rather than all at once. You can read more about streams here at substack's stream handbook. See the following for example uses of stream & pipe. If you wish to use streams with PostgreSQL, you must also install the pg-query-stream module. If you wish to use streams with the pgnative dialect, please be aware that the results will not be streamed as they are received, but rather streamed after the entire result set has returned. On an HTTP server, make sure to manually close your streams if a request is aborted.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。