Community MySQL state adapter for Chat SDK, built with mysql2. Currently at version 0.1.0. Provides state persistence for Chat SDK bots using MySQL as the primary datastore, supporting subscriptions, distributed locking, key-value caching with TTL, and automatic table creation. Supports MySQL 5.7+. Compared to the built-in Redis adapter, this is a lighter alternative when you already have MySQL and want to avoid a separate Redis instance, though it has higher latency and lacks automatic expired row cleanup. The adapter automatically detects MYSQL_URL or DATABASE_URL environment variables, or accepts an explicit URL or an existing mysql2 pool instance. It is fully typed (TypeScript) and published on npm.
npm install chat-state-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a MySQL state adapter and use it with the Chat SDK bot instance.
Run periodic cleanup SQL queries (as described in the README) or schedule a cron job to delete expired rows.
Use the Redis state adapter for high-contention distributed locking, or keep contention low.
Pass the url or client option, or set MYSQL_URL or DATABASE_URL.
Grant CREATE TABLE privileges or create the tables manually in advance.
Set MYSQL_URL environment variable or pass url/client option to createMySqlState.
Grant necessary privileges to the user: GRANT ALL PRIVILEGES ON chat.* TO 'user'@'host';
Ensure mysql2 is installed: npm install mysql2. If using an existing client, verify the import path.