A lightweight MySQL wrapper for serverless environments (AWS Lambda, Cloud Functions) that automatically detects read vs. write queries and routes them to appropriate read replicas or the primary database. Version 1.0.12 is the latest stable release, updated sporadically. Key differentiators: zero-config read/write splitting using SQL parsing, connection pooling optimized for serverless cold starts, and promise-based API. Simpler than typeorm or knex for basic MySQL access, with built-in replica routing.
npm install serverless-mysql-rwNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates setup with read/write hosts, automatic query routing, and usage in a serverless handler.
Use explicit `db.read()` or `db.write()` methods for ambiguous queries.
Replace `import mysql from 'serverless-mysql-rw'` with `import mysql from 'serverless-mysql-rw'` (factory) or `import { ServerlessMySQL } from 'serverless-mysql-rw'`.Call `db.end()` at the end of your handler or use `await db.end()` in a finally block.
Rename `replica` to `read` in the config object.
Use `import mysql from 'serverless-mysql-rw'` (factory) or `import { ServerlessMySQL } from 'serverless-mysql-rw'`.Run `npm install mysql2`.
Ensure `read` object has all required fields (host, user, password, database).
Set `"type": "module"` in package.json or use .mjs extension.