@keyv/mysql
TypeScript icon, indicating that this package has built-in type declarations

1.7.5 • Public • Published

@keyv/mysql keyv

MySQL/MariaDB storage adapter for Keyv

build codecov npm npm

MySQL/MariaDB storage adapter for Keyv.

Install

npm install --save keyv @keyv/mysql

Usage

const Keyv = require('keyv');

const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname');
keyv.on('error', handleConnectionError);

You can specify a custom table with the table option and the primary key size with keySize.

e.g:

const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname', {
  table: 'cache',
  keySize: 255
});

SSL

const fs = require('fs');
const path = require('path');
const KeyvMysql = require('@keyv/mysql');

const options = {
	ssl: {
		rejectUnauthorized: false,
		ca: fs.readFileSync(path.join(__dirname, '/certs/ca.pem')).toString(),
		key: fs.readFileSync(path.join(__dirname, '/certs/client-key.pem')).toString(),
		cert: fs.readFileSync(path.join(__dirname, '/certs/client-cert.pem')).toString(),
	},
};

const keyv = new KeyvMysql({uri, ...options});

Note: Some MySQL/MariaDB installations won't allow a key size longer than 767 bytes. If you get an error on table creation try reducing keySize to 191 or lower. #5

License

MIT © Jared Wray

Package Sidebar

Install

npm i @keyv/mysql

Weekly Downloads

286

Version

1.7.5

License

MIT

Unpacked Size

24.4 kB

Total Files

13

Last publish

Collaborators

  • jaredwray
  • lukechilds