database-builder
Version:
Library to assist in creating and maintaining SQL commands.
73 lines (72 loc) • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ddl = void 0;
var utils_1 = require("./../core/utils");
var drop_1 = require("./drop/drop");
var create_1 = require("./create/create");
var alter_1 = require("./alter/alter");
var Ddl = /** @class */ (function () {
function Ddl(_a
// private readonly _database: DatabaseBase = void 0,
// private readonly _mappersTable: GetMapper,
// public readonly enableLog: boolean = true
) {
var _b = _a === void 0 ? {} : _a
// private readonly _database: DatabaseBase = void 0,
// private readonly _mappersTable: GetMapper,
// public readonly enableLog: boolean = true
, getMapper = _b.getMapper, _c = _b.database, database = _c === void 0 ? void 0 : _c, _d = _b.enableLog, enableLog = _d === void 0 ? true : _d;
this._getMapper = getMapper;
this._database = database;
this.enableLog = enableLog;
}
Ddl.prototype.create = function (typeT, mapperTable, database) {
if (mapperTable === void 0) { mapperTable = this._getMapper.get(typeT).mapperTable; }
if (database === void 0) { database = this.getDatabase(); }
return new create_1.Create(typeT, mapperTable, database, this.enableLog);
};
Ddl.prototype.alter = function (typeT, mapperTable, database) {
if (mapperTable === void 0) { mapperTable = this._getMapper.get(typeT).mapperTable; }
if (database === void 0) { database = this.getDatabase(); }
return new alter_1.Alter(typeT, mapperTable, database, this.enableLog);
};
Ddl.prototype.drop = function (typeT, mapperTable, database) {
if (mapperTable === void 0) { mapperTable = this._getMapper.get(typeT).mapperTable; }
if (database === void 0) { database = this.getDatabase(); }
return new drop_1.Drop(typeT, mapperTable, database, this.enableLog);
};
/**
* hasTable
*/
Ddl.prototype.hasTable = function (tablename) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._database.executeSql("\n SELECT name\n FROM sqlite_master\n WHERE type = 'table' AND\n name = ?;\n ", [_this._getMapper.get(tablename).tableName])
.then(function (result) {
resolve(result.rows.length > 0);
})
.catch(function (err) { return reject(err); });
});
};
/**
* hasColumn
*/
Ddl.prototype.hasColumn = function (tablename, column) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._database.executeSql("\n SELECT name\n FROM pragma_table_info(?)\n WHERE name = ?;\n ", [_this._getMapper.get(tablename).tableName, utils_1.Utils.getColumn(column)])
.then(function (result) {
resolve(result.rows.length > 0);
})
.catch(function (err) { return reject(err); });
});
};
Ddl.prototype.getDatabase = function () {
// if (!this._database) {
// throw new DatabaseBuilderError("Transaction ou Database not specified in query.");
// }
return this._database;
};
return Ddl;
}());
exports.Ddl = Ddl;