Terminal
Terminal/Skill
Connects the Kysely query builder to TiDB Cloud, over standard TCP or the serverless HTTP driver for edge runtimes.
By PingCAP (TiDB)
Works with
npx skills add pingcap/agent-rules --skill tidbx-kyselyUse 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.
mysql:// URL in DATABASE_URL).mysql2 pool + Kysely MysqlDialect.@tidbcloud/kysely dialect over HTTP.references/kysely-usage.md for full examples.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 mysql2
pool.
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 }) })
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
references/serverless-kysely-tutorial.md for the full walkthrough.
import { Kysely } from 'kysely'
import { TiDBCloudServerlessDialect } from '@tidbcloud/kysely'
const db = new Kysely({
dialect: new TiDBCloudServerlessDialect({ url: process.env.DATABASE_URL }),
})