UNPKG

@riao/dbal

Version:
229 lines 7.33 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataDefinitionRepository = void 0; const ddl_1 = require("../ddl"); const repository_1 = require("../repository"); /** * Use the DDL Repository to create & modify your database schema */ class DataDefinitionRepository extends repository_1.Repository { constructor(options) { var _a; super(options); this.ddlBuilderType = ddl_1.DataDefinitionBuilder; this.ddlBuilderType = (_a = options.ddlBuilderType) !== null && _a !== void 0 ? _a : this.ddlBuilderType; } init(options) { super.init(options); this.isReady = true; } getDDLBuilder() { return new this.ddlBuilderType(); } /** * Temporarily disable foreign key checks on the session. * Some databases may require escalated priveleges */ disableForeignKeyChecks() { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().disableForeignKeyChecks()); }); } /** * Re-enable foreign key checks on the session. * Some databases may require escalated priveleges */ enableForeignKeyChecks() { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().enableForeignKeyChecks()); }); } /** * Create a new database * * @param options Database options */ createDatabase(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().createDatabase(options)); }); } /** * Create a new table * * @param options Table options */ createTable(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().createTable(options)); }); } /** * Create an index on a table * * @param options Index options */ createIndex(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().createIndex(options)); }); } /** * Create a new user * * @param options Table options */ createUser(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().createUser(options)); }); } /** * IMPORTANT: UNSTABLE. Grant is currently only compatible with * mysql and mssql and may cause unintended side-effects and/or * privilege escalation. * This should not be used in most circumstances! * Use a dedicated database connection for this method, as it may change * the database connection's default database. * This method and it's arguments are likely to change in future versions * * @param options Grant options * @returns */ grant(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().grant(options)); }); } /** * Add columns to a table * * @param options Add column options */ addColumns(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().addColumns(options)); }); } /** * Add a foreign key to a table * * @param options Foreign key options */ addForeignKey(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().addForeignKey(options)); }); } /** * Change a column * * @param options Column options */ changeColumn(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().changeColumn(options)); }); } /** * Drop a column * * @param options Drop options */ dropColumn(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropColumn(options)); }); } /** * Drop a foreign key constraint * * @param options Drop options */ dropForeignKey(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropForeignKey(options)); }); } /** * Rename a table * * @param options Rename options */ renameTable(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().renameTable(options)); }); } /** * Drop a database * * @param options Options */ dropDatabase(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropDatabase(options)); }); } /** * Drop an existing table * * @param options Options */ dropTable(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropTable(options)); }); } /** * Drop user(s) * * @param options Options */ dropUser(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropUser(options)); }); } /** * Truncate an existing table * * @param options Options */ truncate(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().truncate(options)); }); } /** * Create a new trigger * * @param options Trigger options */ createTrigger(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().createTrigger(options)); }); } /** * Drop an existing trigger * * @param options Trigger options */ dropTrigger(options) { return __awaiter(this, void 0, void 0, function* () { yield this.query(this.getDDLBuilder().dropTrigger(options)); }); } } exports.DataDefinitionRepository = DataDefinitionRepository; //# sourceMappingURL=ddl-repository.js.map