Connect to TiDB Cloud Lake Using Node.js
The official Node.js driver provides TypeScript support and Promise-based API for modern JavaScript applications.
Installation
npm install tidbcloudlake-driver
Connection String: See driver overview for DSN format and examples.
Key Features
- ✅ TypeScript Support: Full TypeScript definitions included
- ✅ Promise-based API: Modern async/await support
- ✅ Streaming Results: Efficient handling of large result sets
- ✅ Connection Pooling: Built-in connection management
Data Type Mappings
Basic Usage
const { Client } = require('tidbcloudlake-driver');
// Connect to TiDB Cloud Lake
const client = new Client('<your-dsn>');
const conn = await client.getConn();
// DDL: Create table
await conn.exec(`CREATE TABLE users (
id INT,
name STRING,
email STRING
)`);
// Write: Insert data
await conn.exec("INSERT INTO users VALUES (?, ?, ?)", [1, "Alice", "alice@example.com"]);
// Query: Select data
const rows = await conn.queryIter("SELECT id, name, email FROM users WHERE id = ?", [1]);
for await (const row of rows) {
console.log(row.values());
}
conn.close();
Resources
- NPM Package: tidbcloudlake-driver
- GitHub Repository: tidbcloudlake-driver
- TypeScript Definitions: Included in package