Knex.js dialect adapter for serverless-mysql, enabling persistent database connections across AWS Lambda execution contexts. Version 1.1.0 is the latest stable release, with no frequent updates since 2021. It works as a custom Knex client dialect, wrapping the serverless-mysql connection pool, which maintains MySQL connections across cold starts. Unlike native Knex MySQL drivers, this reduces database load in serverless environments by reusing connections. Minimal overhead, but requires manual setup of the serverless-mysql instance and injection as the dialect along with the mysql option.
npm install knex-serverless-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes Knex with the serverless-mysql custom dialect and runs a simple query.
Ensure you pass the serverless-mysql object as the 'mysql' property; standard mysql2 won't work
Add a declaration file or use `@ts-ignore` when importing the dialect
Consider migrating to mysql2 with a connection pool manager like `lambda-mysql-connector`
Use `knex.destroy()` in a handler callback or after the Lambda has warmed up, not per invocation
Use standard Knex with mysql2 for migrations, and only use this dialect for runtime queries
Use `client: knexServerlessMysql` instead of `client: 'serverless-mysql'`
Include `mysql: yourServerlessMysqlInstance` in the Knex configuration object
Use `const knexServerlessMysql = require('knex-serverless-mysql').default` or import the default exportCheck environment variables, VPC configuration, and ensure DB allows Lambda IP ranges