UNPKG

552 BJavaScriptView Raw
1'use strict';
2
3const KeyvSql = require('@keyv/sql');
4const mysql = require('mysql2/promise');
5
6class KeyvMysql extends KeyvSql {
7 constructor(options) {
8 if (typeof options === 'string') {
9 options = { uri: options };
10 }
11
12 options = Object.assign({
13 dialect: 'mysql',
14 uri: 'mysql://localhost',
15 }, options);
16
17 options.connect = () => Promise.resolve()
18 .then(() => mysql.createConnection(options.uri))
19 .then(connection => sql => connection.execute(sql)
20 .then(data => data[0]));
21
22 super(options);
23 }
24}
25
26module.exports = KeyvMysql;