database-builder
Version:
Library to assist in creating and maintaining SQL commands.
59 lines (58 loc) • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryReadableBuilderBase = void 0;
var row_result_1 = require("../../core/row-result");
var QueryReadableBuilderBase = /** @class */ (function () {
function QueryReadableBuilderBase(enableLog) {
if (enableLog === void 0) { enableLog = true; }
this.enableLog = enableLog;
}
QueryReadableBuilderBase.prototype.toCast = function (cursor) {
var items = [];
this.forCursor(cursor, function (item) {
items.push(item);
});
return items;
};
QueryReadableBuilderBase.prototype.map = function (cursor, mapper) {
var items = [];
this.forCursor(cursor, function (item) {
items.push(mapper(item));
});
return items;
};
QueryReadableBuilderBase.prototype.mapper = function (cursor, mapperTable, mapper, getMapper, query, newable) {
var items = [];
this.forCursor(cursor, function (item) {
items.push(mapper(new row_result_1.RowResult(item, newable, mapperTable, getMapper, query)));
});
return items;
};
QueryReadableBuilderBase.prototype.read = function (cursor, newable, mapperTable) {
return this.readCursor(cursor, newable, mapperTable);
};
QueryReadableBuilderBase.prototype.readCursor = function (cursor, newable, mapperTable) {
var items = [];
this.forCursor(cursor, function (row) {
var item = new row_result_1.RowResult(row, newable, mapperTable).read(newable);
items.push(item);
});
return items;
};
QueryReadableBuilderBase.prototype.forCursor = function (cursor, forRow) {
// verificar se consulta retornou dados
if (cursor && cursor.rows && cursor.rows.length) {
for (var index = 0; index < cursor.rows.length; index++) {
forRow(cursor.rows.item(index));
}
}
};
QueryReadableBuilderBase.prototype.log = function (log) {
if (this.enableLog) {
// tslint:disable-next-line
console.log(log);
}
};
return QueryReadableBuilderBase;
}());
exports.QueryReadableBuilderBase = QueryReadableBuilderBase;