@devbro/sql-generator
Version:
generic sql generator
38 lines • 1.18 kB
JavaScript
import { Blueprint } from "./Blueprint";
import { SchemaGrammar } from "./SchemaGrammar";
class Schema {
constructor(connection, grammar) {
this.connection = connection;
this.grammar = grammar;
}
async createTable(tableName, structMethod) {
const blueprint = new Blueprint();
blueprint.setTableName(tableName, false);
structMethod(blueprint);
const grammar = new SchemaGrammar();
const sql = grammar.toSql(blueprint);
await this.connection?.runQuery({ sql, bindings: [] });
}
async dropTable(tableName) {
const grammar = new SchemaGrammar();
await this.connection?.runQuery(grammar.compileDropTable(tableName));
}
async tables() {
const grammar = new SchemaGrammar();
return await this.connection?.runQuery(grammar.compileTables());
}
async tableExists(table_name) {
const grammar = new 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;
}
}
export {
Schema
};
//# sourceMappingURL=Schema.mjs.map