MySQL/MariaDB storage adapter for Keyv
npm install @keyv/mysql> MySQL/MariaDB storage adapter for Keyv




MySQL/MariaDB storage adapter for Keyv.
``shell`
npm install --save keyv @keyv/mysql
`js
import Keyv from 'keyv';
import KeyvMysql from '@keyv/mysql';
const keyv = new Keyv(new KeyvMysql('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.intervalExpiration
If you want to use native MySQL scheduler to delete expired keys, you can specify in seconds.
e.g:
`js
import Keyv from 'keyv';
import KeyvMysql from '@keyv/mysql';
const keyv = new Keyv(new KeyvMysql({
uri: 'mysql://user:pass@localhost:3306/dbname',
table: 'cache',
keySize: 255,
intervalExpiration: 60
}));
`
`js
import Keyv from 'keyv';
import KeyvMysql from '@keyv/mysql';
import fs from 'fs';
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 keyvMysql = new KeyvMysql('mysql://user:pass@localhost:3306/dbname', options);
const keyv = new Keyv({ store: keyvMysql });
``