tspace-sql
Advanced tools
Comparing version 1.2.7 to 1.2.8
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Model = function (model, npm) { | ||
return "import { Model } from '" + npm + "'\nclass " + model + " extends Model {\n constructor(){\n super()\n this.useTimestamp()\n }\n}\nexport default " + model + "\n"; | ||
return "import { Model } from '" + npm + "'\nclass " + model + " extends Model {\n constructor(){\n super()\n this.useTimestamp()\n }\n}\nexport { " + model + " }\nexport default " + model + "\n"; | ||
}; | ||
exports.default = Model; |
@@ -8,2 +8,3 @@ declare abstract class Abstract { | ||
protected SELECT: string; | ||
protected EXCEPT: Array<string>; | ||
protected COUNT: string; | ||
@@ -44,2 +45,3 @@ protected FROM: string; | ||
abstract whereSubQuery(column: string, subQuery: string): void; | ||
abstract whereNotInSubQuery(column: string, subQuery: string): void; | ||
abstract orWhereSubQuery(column: string, subQuery: string): void; | ||
@@ -46,0 +48,0 @@ abstract whereBetween(column: string, arrayValue: Array<any>): void; |
@@ -18,2 +18,3 @@ "use strict"; | ||
this.SELECT = ''; | ||
this.EXCEPT = []; | ||
this.COUNT = ''; | ||
@@ -20,0 +21,0 @@ this.FROM = ''; |
@@ -26,2 +26,3 @@ import Base from './Base'; | ||
abstract restore(): void; | ||
abstract except(...params: string[]): void; | ||
abstract with(...nameRelations: string[]): void; | ||
@@ -28,0 +29,0 @@ abstract withHas(...nameSubRelations: string[]): void; |
@@ -21,2 +21,3 @@ import Abstract from './AbstractBase'; | ||
whereSubQuery(column: string, subQuery: string): this; | ||
whereNotInSubQuery(column: string, subQuery: string): this; | ||
orWhereSubQuery(column: string, subQuery: string): this; | ||
@@ -23,0 +24,0 @@ whereBetween(column: string, arrayValue: Array<any>): this; |
@@ -15,2 +15,3 @@ import AbstractModel from './AbstractModel'; | ||
useTable: (table: string) => this; | ||
except(...params: Array<string>): this; | ||
with(...nameRelations: Array<any>): this; | ||
@@ -88,2 +89,3 @@ withHas(...nameSubRelations: Array<string>): this; | ||
private _getSQLModel; | ||
private _exceptColumns; | ||
private _exec; | ||
@@ -90,0 +92,0 @@ private _execGroup; |
@@ -175,2 +175,19 @@ "use strict"; | ||
}; | ||
_this._exceptColumns = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var sql, rawColumns, columns, removeExcept; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
sql = this.CONSTANT.SHOW + " " + this.CONSTANT.COLUMNS + " " + this.CONSTANT.FROM + " " + this.TABLE_NAME; | ||
return [4 /*yield*/, this.queryStatement(sql)]; | ||
case 1: | ||
rawColumns = _a.sent(); | ||
columns = rawColumns.map(function (column) { return column.Field; }); | ||
removeExcept = columns.filter(function (column) { return !_this.EXCEPT.includes(column); }); | ||
this.select(removeExcept.join(',')); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); }; | ||
_this._exec = function (sql, type) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -646,3 +663,2 @@ var mains, emptyData, relations, _i, relations_1, relation, subs, childSubs, resultData, err_1; | ||
_this._returnResult = function (type, data) { | ||
var result = null; | ||
switch (type) { | ||
@@ -655,7 +671,5 @@ case 'FIRST': { | ||
throw new Error("can't find property '" + _this.PLUCK + "' of result"); | ||
result = newData[_this.PLUCK]; | ||
break; | ||
return newData[_this.PLUCK]; | ||
} | ||
result = data.shift(); | ||
break; | ||
return data.shift(); | ||
} | ||
@@ -667,11 +681,8 @@ case 'GET': { | ||
throw new Error("can't find property '" + _this.PLUCK + "' of result"); | ||
result = newData; | ||
break; | ||
return newData; | ||
} | ||
result = data; | ||
break; | ||
return data; | ||
} | ||
case 'PAGINATION': { | ||
result = _this._pagination(data); | ||
break; | ||
return _this._pagination(data); | ||
} | ||
@@ -682,3 +693,2 @@ default: { | ||
} | ||
return result; | ||
}; | ||
@@ -731,2 +741,10 @@ _this._hiddenColumnModel = function (object) { | ||
}; | ||
Model.prototype.except = function () { | ||
var params = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
params[_i] = arguments[_i]; | ||
} | ||
this.EXCEPT = params.length ? params : ['id']; | ||
return this; | ||
}; | ||
Model.prototype.with = function () { | ||
@@ -1026,2 +1044,8 @@ var _this = this; | ||
case 0: | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1035,3 +1059,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this._exec(sql, 'FIRST')]; | ||
case 1: return [2 /*return*/, _d.sent()]; | ||
case 3: return [2 /*return*/, _d.sent()]; | ||
} | ||
@@ -1048,2 +1072,8 @@ }); | ||
case 0: | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1057,3 +1087,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this._exec(sql, 'FIRST')]; | ||
case 1: return [2 /*return*/, _d.sent()]; | ||
case 3: return [2 /*return*/, _d.sent()]; | ||
} | ||
@@ -1075,2 +1105,8 @@ }); | ||
case 0: | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1080,3 +1116,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this._exec(sql, 'GET')]; | ||
case 1: return [2 /*return*/, _d.sent()]; | ||
case 3: return [2 /*return*/, _d.sent()]; | ||
} | ||
@@ -1093,2 +1129,8 @@ }); | ||
case 0: | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1098,3 +1140,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this._exec(sql, 'GET')]; | ||
case 1: return [2 /*return*/, _d.sent()]; | ||
case 3: return [2 /*return*/, _d.sent()]; | ||
} | ||
@@ -1116,2 +1158,8 @@ }); | ||
case 0: | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_f.sent(); | ||
_f.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1129,3 +1177,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this._exec(sql, 'PAGINATION')]; | ||
case 1: return [2 /*return*/, _f.sent()]; | ||
case 3: return [2 /*return*/, _f.sent()]; | ||
} | ||
@@ -1147,3 +1195,9 @@ }); | ||
case 0: | ||
_d.trys.push([0, 4, , 5]); | ||
_d.trys.push([0, 6, , 7]); | ||
if (!this.EXCEPT.length) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this._exceptColumns()]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
if (!this.DEBUG) | ||
@@ -1155,3 +1209,3 @@ this.DEBUG = debug; | ||
return [4 /*yield*/, this.queryStatement(sql)]; | ||
case 1: | ||
case 3: | ||
results = _d.sent(); | ||
@@ -1161,6 +1215,6 @@ data = results.map(function (data) { return data.data; }); | ||
return [4 /*yield*/, this.queryStatement(sqlChild)]; | ||
case 2: | ||
case 4: | ||
childData = _d.sent(); | ||
return [4 /*yield*/, this._execGroup(childData)]; | ||
case 3: | ||
case 5: | ||
child_1 = _d.sent(); | ||
@@ -1177,6 +1231,6 @@ resultData = results.map(function (result) { | ||
return [2 /*return*/, resultData]; | ||
case 4: | ||
case 6: | ||
err_10 = _d.sent(); | ||
throw new Error(err_10.message); | ||
case 5: return [2 /*return*/]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
@@ -1183,0 +1237,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constant = { | ||
SHOW: 'SHOW', | ||
COLUMNS: 'COLUMNS', | ||
MYSQL: 'mysql', | ||
@@ -5,0 +7,0 @@ POSTGRESQL: 'pg', |
{ | ||
"name": "tspace-sql", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"description": "mysql & postgresql query builder object relational mapping", | ||
@@ -5,0 +5,0 @@ "main": "./dist/lib/index.js", |
@@ -32,8 +32,7 @@ # tspace-sql | ||
await new DB().raw('SELECT * FROM users') | ||
await new DB().table('users').all() | ||
await new DB().table('users').where('active',true).get() | ||
await new DB().table('users').whereIn('id',[1,2,3]).where('active','!=',true).first() | ||
await new DB().table('users').where('active',true).get() | ||
await new DB().table('users').where('active',true).findMany() | ||
await new DB().table('users').whereIn('id',[1,2,3]).where('active','!=',true).findOne() | ||
await new DB().table('users').where('active',true).findMany() | ||
// Case sensitive where statement | ||
await new DB().table('users').where(DB.sensitive('username'),'Simple').get() | ||
await new DB().table('users').whereSensitive('username','Simple').findMany() | ||
@@ -100,3 +99,3 @@ await new DB() | ||
(async () => { | ||
await new User().with('car','phones').withHas('phones.brand').get() | ||
await new User().with('car','phones').withChild('phones.brand').findMany() | ||
})() | ||
@@ -114,2 +113,3 @@ ``` | ||
where(column , operator , value) | ||
whereSensitive(column , operator , value) | ||
whereId(id) | ||
@@ -125,3 +125,5 @@ whereUser(userId) | ||
whereSubQuery(colmn , rawSQL) | ||
select(column1 ,column2 ,...N) | ||
except(column1 ,column2 ,...N) | ||
join (primary key , table.foreign key) | ||
@@ -136,3 +138,3 @@ rightJoin (primary key , table.foreign key) | ||
groupBy (column) | ||
hidden (...columns) | ||
hidden (column1 ,column2 ,...N) | ||
insert(objects) | ||
@@ -152,3 +154,3 @@ create(objects) | ||
with(name1 , name2,...nameN) | ||
withHas(nameParent.nameChild1 , nameParent.nameChild2, ...n) | ||
withChild(nameParent.nameChild1 , nameParent.nameChild2, ...n) | ||
@@ -160,5 +162,4 @@ /** | ||
*/ | ||
all() | ||
get() | ||
first() | ||
findMany() | ||
findOne() | ||
find(id) | ||
@@ -168,2 +169,3 @@ exists () | ||
toJSON() | ||
toString() | ||
toArray(column) | ||
@@ -220,4 +222,4 @@ count(column) | ||
this.useDebug() default false *debug raw sql | ||
this.useTimestamp default false * target to created_at & updated_at [patern camelCase -> createdAt etc] when insert or update | ||
this.useSoftDelete() default false * target to where deleted_at is null | ||
this.useTimestamp() default false * case created_at & updated_at [patern camelCase -> createdAt etc] when insert or update | ||
this.useSoftDelete() default false * case where deleted_at is null | ||
this.useTable('Users') default users | ||
@@ -224,0 +226,0 @@ this.usePattern('camelCase') default snake_case |
Sorry, the diff of this file is too big to display
203860
4225
264