sipp
Version:
An Opinionated, High-Productivity MVC Web Framework in TypeScript
27 lines • 950 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Connection = void 0;
const Model_1 = require("./Model");
const knex_1 = __importDefault(require("knex"));
const path_1 = require("path");
class Connection {
constructor(mode, knexFilePath) {
const knexConfigPath = knexFilePath || path_1.join(process.cwd(), 'knexfile');
const config = require(knexConfigPath);
if (!config || !config[mode]) {
throw new Error(`knexfile does not export a config for application mode ${mode}`);
}
this.knex = knex_1.default(config[mode]);
}
connect() {
Model_1.Model.knex(this.knex);
}
disconnect() {
return this.knex.destroy();
}
}
exports.Connection = Connection;
//# sourceMappingURL=Connection.js.map