Wener Site

knex

约 2 分钟阅读
  • knexGitHubknex/knexcomposite - 解耦构建最终 query 的过程 · 对于基础的访问模式提供跨库支持 · knex-types 基于 db schema 生成 ts · 参考 · kysely · Knex QueryLab · Knex to SQL笔记:knex
    • composite - 解耦构建最终 query 的过程
    • 对于基础的访问模式提供跨库支持
  • knex-types 基于 db schema 生成 ts
  • 参考
    • kysely笔记Kyselyknex 会尝试适配不同 dialect, 提供相同的语义 · e.g. MSSQL 可以使用 limit · 因此 knex 相对更复杂 · kysely 要求用户自己熟悉各种 SQL 语法 · e.g. MSSQL 使用 top, 虽然有 limit 接口,但是生成的语法是错误的打开:/notes/web/framework/kysely
    • Knex QueryLabLinkmichaelavila.com/knex-querylabcomposite - 解耦构建最终 query 的过程 · 对于基础的访问模式提供跨库支持 · knex-types 基于 db schema 生成 ts · 参考 · kysely · Knex QueryLab · Knex to SQL笔记:knex
      • Knex to SQL
  • pool
JavaScript
const pool = new Pool({
  // 最小 2 - 推荐 0
  min: 2,

  // 最大 - 根据场景性能要求调整
  max: 10,

  // acquire promises are rejected after this many milliseconds
  // if a resource cannot be acquired
  acquireTimeoutMillis: 30000,

  // create operations are cancelled after this many milliseconds
  // if a resource cannot be acquired
  createTimeoutMillis: 30000,

  // destroy operations are awaited for at most this many milliseconds
  // new resources will be created after this timeout
  destroyTimeoutMillis: 5000,

  // Free resources are destroyed after this many milliseconds.
  // Note that if min > 0, some resources may be kept alive for longer.
  // To reliably destroy all idle resources, set min to 0.
  idleTimeoutMillis: 30000,

  // how often to check for idle resources to destroy
  reapIntervalMillis: 1000,

  // how long to idle after failed create before trying again
  createRetryIntervalMillis: 200,

  // If true, when a create fails, the first pending acquire is
  // rejected with the error. If this is false (the default) then
  // create is retried until acquireTimeoutMillis milliseconds has
  // passed.
  propagateCreateError: false,
});
TypeScript
const db = knex({
  client: 'better-sqlite3',
  connection: {
    filename: 'test.sqlite3',
  },
  useNullAsDefault: true,
});
db.raw('PRAGMA journal_mode = WAL');

FAQ

raw in

Reference Snippets

knex/knex#3186GitHub Issueknex/knex#3186

Crossdb support for INSERT ... ON CONFLICT / MERGE upsert

Medium Response

  • knex 的核心理念是 composite - 解耦构建最终 query 的过程
  • 对于基础的访问模式提供跨库支持
  • knex-types 基于 db schema 生成 ts

关联信息

反向链接和本文引用的外部资料。

反向链接

  • Kysely
    笔记 · Knex.js

    knex 会尝试适配不同 dialect, 提供相同的语义 · e.g. MSSQL 可以使用 limit · 因此 knex 相对更复杂 · kysely 要求用户自己熟悉各种 SQL 语法 · e.g. MSSQL 使用 top, 虽然有 limit 接口,但是生成的语法是错误的

References

GitHub

5 条

其他外链

2 条
最近更新commit 906e816Edit

On this page