k8w-promise-mysql
Version:
Simple native Promise wrapper for mysqljs/mysql
34 lines (33 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const mysql = require("mysql");
const PromiseMySQLPool_1 = require("./src/PromiseMySQLPool");
const PromiseMyCluster_1 = require("./src/PromiseMyCluster");
class PromiseMySQL {
static createPool(config) {
return new PromiseMySQLPool_1.default(mysql.createPool(config));
}
static createCluster(config) {
let poolCluster = mysql.createPoolCluster(config.options);
let i;
for (i = 0; i < config.master.length; i++) {
if (i == 0) {
poolCluster.add('MASTER', config.master[i]);
}
else {
poolCluster.add(`MASTER${i}`, config.master[i]);
}
}
if (config.slave) {
for (i = 0; i < config.slave.length; i++) {
poolCluster.add(`SLAVE${i + 1}`, config.slave[i]);
}
}
return new PromiseMyCluster_1.default(poolCluster);
}
}
PromiseMySQL.escape = mysql.escape;
PromiseMySQL.escapeId = mysql.escapeId;
PromiseMySQL.format = mysql.format;
PromiseMySQL.raw = mysql.raw;
exports.default = PromiseMySQL;