ts-db-helper
Version:
Simple ORM based on TypeScript
54 lines • 1.8 kB
JavaScript
/**
* @public
* @class QueryCreate
*
* @description
* this class is designed to be used behind {@link Create} function
* this class is an helper to easily create a table from the data model generated with the annotations
*
* @example
* ```typescript
* Create(TodoDataModel).exec().subscribe((QueryResult<any>) = {
* // todo something on create succeed
* }, (err) => {
* // do something with the error
* });
* ```
*
* @author Olivier Margarit
* @since 0.1
*/
var QueryCreate = /** @class */ (function () {
/**
* @public
* @constructor should not be called directly for API design purpose
*
* @param {DbTable} table object with a single model infomations
* generated with table and column annotations
*/
function QueryCreate(table) {
this.table = table;
}
/**
* @public
* @method build should be removed to be a part of the private API
*
* @return {DbQuery} of the query with the string part and
* clauses params.
*/
QueryCreate.prototype.build = function () {
var columns = [];
for (var _i = 0, _a = this.table.columnList; _i < _a.length; _i++) {
var column = _a[_i];
var value = '`' + column.name + '` ' + (column.autoIncrement ? 'INTEGER' : column.type);
value += (column.primaryKey ? ' PRIMARY KEY' : '');
value += (column.autoIncrement ? ' AUTOINCREMENT' : '');
columns.push(value);
}
var query = 'CREATE TABLE IF NOT EXISTS ' + this.table.name + ' (' + columns.join(',') + ')';
return query;
};
return QueryCreate;
}());
export { QueryCreate };
//# sourceMappingURL=query-create.model.js.map