@jovijovi/pedrojs-mysql
Version:
MySQL package for pedro.js
35 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mysql = void 0;
const sequelize_1 = require("sequelize");
const pedrojs_log_1 = require("@jovijovi/pedrojs-log");
var Mysql;
(function (Mysql) {
// Connect mysql database
function Connect(cfg, logging = false) {
if (cfg.uri) {
return new sequelize_1.Sequelize(cfg.uri, {
logging: logging,
});
}
return new sequelize_1.Sequelize(cfg.db, cfg.user, cfg.secret, {
host: cfg.ip,
port: cfg.port,
dialect: 'mysql',
logging: logging,
});
}
Mysql.Connect = Connect;
async function Ping(engine) {
try {
await engine.authenticate();
pedrojs_log_1.log.RequestId().info('Connect the mysql successfully.');
}
catch (error) {
pedrojs_log_1.log.RequestId().fatal('Connect the mysql failed, error=%o', error);
throw new Error('Connect the mysql failed');
}
}
Mysql.Ping = Ping;
})(Mysql = exports.Mysql || (exports.Mysql = {}));
//# sourceMappingURL=conn.js.map