@db2lake/driver-mysql
v0.2.0
Published
MySQL source driver for db2lake
Maintainers
Readme
@db2lake/driver-mysql
MySQL source driver for the @db2lake pipeline. Streams rows using cursor-based pagination and the mysql2/promise client.
Features
- Cursor-based pagination (generator/streaming)
- Parameterized queries
- TypeScript types and minimal surface area for integration with
@db2lakepipelines
Installation
Install the package:
npm install @db2lake/driver-mysqlProject structure
├── src/
│ └── index.ts # MySQLSourceDriver implementation
│ └── type.ts # MySQL configuration types
└── package.json # Package metadataQuick usage
import { MySQLSourceDriver, MySQLConfig } from '@db2lake/driver-mysql';
const config: MySQLConfig = {
query: 'SELECT * FROM users WHERE id > ? LIMIT 100',
params: [0],
cursorField: 'id',
cursorParamsIndex: 0,
connectionOptions: { host: 'localhost', user: 'root', database: 'test' }
};
const driver = new MySQLSourceDriver(config);
for await (const batch of driver.fetch()) {
// process batch
}
await driver.close();Using a connection URI
import { MySQLSourceDriver, MySQLConfig } from '@db2lake/driver-mysql';
const config: MySQLConfig = {
query: 'SELECT * FROM orders WHERE order_id > ? LIMIT 50',
params: [0],
cursorField: 'order_id',
cursorParamsIndex: 0,
connectionUri: 'mysql://user:password@localhost:3306/shopdb'
};
const driver = new MySQLSourceDriver(config);
for await (const batch of driver.fetch()) {
// process orders
}
await driver.close();Configuration Options
query(string): SQL with placeholdersparams(any[]): parameters for the querycursorField(string | optional): field used to advance the cursorcursorParamsIndex(number | optional): index inparamswhere cursor value is placedconnectionOptions(ConnectionOptions | optional): passed tomysql2/promise.createConnectionconnectionUri(string | optional): connection URI to use instead of options
Notes:
- The driver will call
connect()automatically on firstfetch()if not connected. - Always call
close()to release the connection and resources.
API
new MySQLSourceDriver(config: MySQLConfig)fetch(): AsyncGenerator<any[], void, unknown>- yields batches of rowsconnect(): Promise<void>- establishes connection (optional)close(): Promise<void>- closes connection and cleans up
License
MIT
