@devbro/sql-generator
Version:
generic sql generator
62 lines • 2.3 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Schema_exports = {};
__export(Schema_exports, {
Schema: () => Schema
});
module.exports = __toCommonJS(Schema_exports);
var import_Blueprint = require("./Blueprint");
var import_SchemaGrammar = require("./SchemaGrammar");
class Schema {
constructor(connection, grammar) {
this.connection = connection;
this.grammar = grammar;
}
async createTable(tableName, structMethod) {
const blueprint = new import_Blueprint.Blueprint();
blueprint.setTableName(tableName, false);
structMethod(blueprint);
const grammar = new import_SchemaGrammar.SchemaGrammar();
const sql = grammar.toSql(blueprint);
await this.connection?.runQuery({ sql, bindings: [] });
}
async dropTable(tableName) {
const grammar = new import_SchemaGrammar.SchemaGrammar();
await this.connection?.runQuery(grammar.compileDropTable(tableName));
}
async tables() {
const grammar = new import_SchemaGrammar.SchemaGrammar();
return await this.connection?.runQuery(grammar.compileTables());
}
async tableExists(table_name) {
const grammar = new import_SchemaGrammar.SchemaGrammar();
return (await this.connection?.runQuery(grammar.compileTableExists(table_name)))[0]["exists"];
}
async dropTableIfExists(tableName) {
if (await this.tableExists(tableName)) {
await this.dropTable(tableName);
}
return;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Schema
});
//# sourceMappingURL=Schema.js.map