tidbx-kysely
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTiDB Cloud + Kysely
TiDB Cloud + Kysely
Use this skill when a user wants to connect Kysely to TiDB Cloud (TiDB X). Default to
standard TCP (Node server/runtime). Only use the TiDB Cloud serverless driver over
HTTP for serverless or edge runtimes.
当用户需要将Kysely连接到TiDB Cloud(TiDB X)时使用本技能。默认采用标准TCP连接(适用于Node服务器/运行时)。仅在无服务器或边缘运行时场景下,使用基于HTTP的TiDB Cloud无服务器驱动。
Workflow
工作流程
- Confirm runtime and deployment target (Node server vs serverless/edge).
- Confirm cluster type. The serverless HTTP driver applies to Starter/Essential clusters.
- Collect connection info (prefer a URL in
mysql://).DATABASE_URL - Choose the path:
- Normal usage (default): TCP + pool + Kysely
mysql2.MysqlDialect - Serverless/edge: dialect over HTTP.
@tidbcloud/kysely
- Normal usage (default): TCP +
- Show only the matching snippet first. Include the other path only if the user asks.
Use for full examples.
references/kysely-usage.md
- 确认运行时和部署目标(Node服务器 vs 无服务器/边缘环境)。
- 确认集群类型。无服务器HTTP驱动仅适用于Starter/Essential集群。
- 收集连接信息(优先使用中的
DATABASE_URL格式URL)。mysql:// - 选择对应方案:
- 常规使用(默认):TCP + 连接池 + Kysely
mysql2。MysqlDialect - 无服务器/边缘环境:通过HTTP使用方言。
@tidbcloud/kysely
- 常规使用(默认):TCP +
- 首先仅展示匹配场景的代码片段。仅当用户要求时,再提供另一种方案的内容。完整示例请参考。
references/kysely-usage.md
Normal usage (default)
常规使用(默认)
Use this for Node servers, long-lived runtimes, or when TCP is available. This is the
primary path unless the user explicitly needs serverless/edge. Uses TCP with a
pool.
mysql2ts
import { Kysely, MysqlDialect } from 'kysely'
import { createPool } from 'mysql2'
const pool = createPool({ uri: process.env.DATABASE_URL })
const db = new Kysely({ dialect: new MysqlDialect({ pool }) })适用于Node服务器、长生命周期运行时或TCP连接可用的场景。除非用户明确需要无服务器/边缘环境方案,否则这是首选方案。使用TCP和连接池。
mysql2ts
import { Kysely, MysqlDialect } from 'kysely'
import { createPool } from 'mysql2'
const pool = createPool({ uri: process.env.DATABASE_URL })
const db = new Kysely({ dialect: new MysqlDialect({ pool }) })Serverless/edge usage (HTTP)
无服务器/边缘环境使用(HTTP)
Use this only when the runtime cannot keep TCP connections (serverless/edge). Requires
the TiDB Cloud serverless driver and Starter/Essential clusters. Use from backend
services only (browser origins may be blocked by CORS). See
for the full walkthrough.
references/serverless-kysely-tutorial.mdts
import { Kysely } from 'kysely'
import { TiDBCloudServerlessDialect } from '@tidbcloud/kysely'
const db = new Kysely({
dialect: new TiDBCloudServerlessDialect({ url: process.env.DATABASE_URL }),
})仅当运行时无法保持TCP连接时(无服务器/边缘环境)使用本方案。需要TiDB Cloud无服务器驱动,且仅适用于Starter/Essential集群。仅可从后端服务使用(浏览器端可能会被CORS策略阻止)。完整教程请参考。
references/serverless-kysely-tutorial.mdts
import { Kysely } from 'kysely'
import { TiDBCloudServerlessDialect } from '@tidbcloud/kysely'
const db = new Kysely({
dialect: new TiDBCloudServerlessDialect({ url: process.env.DATABASE_URL }),
})Notes
注意事项
- Many users say "instance" to mean "cluster"; treat them as the same.
- Keep instructions concise; move any long docs into references.
- 很多用户会用“实例”指代“集群”,二者视为同一概念。
- 保持说明简洁;冗长文档请移至参考资料中。