@simplysm/sd-orm-common
Advanced tools
Comparing version 3.5.57 to 3.5.58
@@ -272,40 +272,20 @@ "use strict"; | ||
.where(function (item) { | ||
var orArr = []; | ||
var fieldOrArr = []; | ||
var fields = fwd(item); | ||
for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) { | ||
var field = fields_1[_i]; | ||
var splitSearchTextWhereArr = []; | ||
for (var _a = 0, splitSearchText_1 = splitSearchText; _a < splitSearchText_1.length; _a++) { | ||
var text = splitSearchText_1[_a]; | ||
orArr.push(_this.db.qh.includes(field, text)); | ||
if (text.includes("*")) { | ||
splitSearchTextWhereArr.push(_this.db.qh.like(field, text.replace(/\*/g, "%"))); | ||
} | ||
else { | ||
splitSearchTextWhereArr.push(_this.db.qh.includes(field, text)); | ||
} | ||
} | ||
fieldOrArr.push(_this.db.qh.and(splitSearchTextWhereArr)); | ||
} | ||
return [_this.db.qh.or(orArr)]; | ||
return [_this.db.qh.or(fieldOrArr)]; | ||
}); | ||
result = result.select(function (item) { | ||
var fields = fwd(item); | ||
var countQuery = []; | ||
for (var _i = 0, fields_2 = fields; _i < fields_2.length; _i++) { | ||
var field = fields_2[_i]; | ||
countQuery.push.apply(countQuery, [_this.db.qh.case(_this.db.qh.includes(field, searchText), 10000).else(0), "+"]); | ||
} | ||
for (var _a = 0, fields_3 = fields; _a < fields_3.length; _a++) { | ||
var field = fields_3[_a]; | ||
var andArr = []; | ||
for (var _b = 0, splitSearchText_2 = splitSearchText; _b < splitSearchText_2.length; _b++) { | ||
var text = splitSearchText_2[_b]; | ||
andArr.push(_this.db.qh.includes(field, text)); | ||
} | ||
countQuery.push.apply(countQuery, [_this.db.qh.case(_this.db.qh.and(andArr), 100).else(0), "+"]); | ||
} | ||
for (var _c = 0, fields_4 = fields; _c < fields_4.length; _c++) { | ||
var field = fields_4[_c]; | ||
for (var _d = 0, splitSearchText_3 = splitSearchText; _d < splitSearchText_3.length; _d++) { | ||
var text = splitSearchText_3[_d]; | ||
countQuery.push.apply(countQuery, [_this.db.qh.case(_this.db.qh.includes(field, text), 1).else(0), "+"]); | ||
} | ||
} | ||
countQuery = countQuery.slice(0, -1); | ||
return tslib_1.__assign(tslib_1.__assign({}, item), { __searchOrder: new QueryUnit_1.QueryUnit(Number, countQuery) }); | ||
}); | ||
result = result.orderBy(function (item) { return item["__searchOrder"]; }, true); | ||
return result; | ||
@@ -690,3 +670,2 @@ }; | ||
delete queryable._def.orderBy; | ||
delete queryable._entity["__searchOrder"]; | ||
return [4, queryable.singleAsync()]; | ||
@@ -693,0 +672,0 @@ case 1: |
@@ -84,2 +84,5 @@ "use strict"; | ||
}; | ||
QueryHelper.prototype.like = function (source, target) { | ||
return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target)]; | ||
}; | ||
QueryHelper.prototype.startsWith = function (source, target) { | ||
@@ -86,0 +89,0 @@ return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target), " + ", "'%'"]; |
@@ -258,33 +258,18 @@ "use strict"; | ||
.where(item => { | ||
const orArr = []; | ||
const fieldOrArr = []; | ||
const fields = fwd(item); | ||
for (const field of fields) { | ||
const splitSearchTextWhereArr = []; | ||
for (const text of splitSearchText) { | ||
orArr.push(this.db.qh.includes(field, text)); | ||
if (text.includes("*")) { | ||
splitSearchTextWhereArr.push(this.db.qh.like(field, text.replace(/\*/g, "%"))); | ||
} | ||
else { | ||
splitSearchTextWhereArr.push(this.db.qh.includes(field, text)); | ||
} | ||
} | ||
fieldOrArr.push(this.db.qh.and(splitSearchTextWhereArr)); | ||
} | ||
return [this.db.qh.or(orArr)]; | ||
return [this.db.qh.or(fieldOrArr)]; | ||
}); | ||
result = result.select(item => { | ||
const fields = fwd(item); | ||
let countQuery = []; | ||
for (const field of fields) { | ||
countQuery.push(...[this.db.qh.case(this.db.qh.includes(field, searchText), 10000).else(0), "+"]); | ||
} | ||
for (const field of fields) { | ||
const andArr = []; | ||
for (const text of splitSearchText) { | ||
andArr.push(this.db.qh.includes(field, text)); | ||
} | ||
countQuery.push(...[this.db.qh.case(this.db.qh.and(andArr), 100).else(0), "+"]); | ||
} | ||
for (const field of fields) { | ||
for (const text of splitSearchText) { | ||
countQuery.push(...[this.db.qh.case(this.db.qh.includes(field, text), 1).else(0), "+"]); | ||
} | ||
} | ||
countQuery = countQuery.slice(0, -1); | ||
return Object.assign(Object.assign({}, item), { __searchOrder: new QueryUnit_1.QueryUnit(Number, countQuery) }); | ||
}); | ||
result = result.orderBy(item => item["__searchOrder"], true); | ||
return result; | ||
@@ -626,3 +611,2 @@ } | ||
delete queryable._def.orderBy; | ||
delete queryable._entity["__searchOrder"]; | ||
const item = await queryable.singleAsync(); | ||
@@ -629,0 +613,0 @@ return ((_a = item === null || item === void 0 ? void 0 : item.cnt) !== null && _a !== void 0 ? _a : 0); |
@@ -20,2 +20,3 @@ import { ISelectQueryDef, TDbDateSeparator, TEntityValue, TEntityValueOrQueryableOrArray, TQueryBuilderValue, TQueryValue } from "./commons"; | ||
includes(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[]; | ||
like(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[]; | ||
startsWith(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[]; | ||
@@ -22,0 +23,0 @@ endsWith(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[]; |
@@ -82,2 +82,5 @@ "use strict"; | ||
} | ||
like(source, target) { | ||
return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target)]; | ||
} | ||
startsWith(source, target) { | ||
@@ -84,0 +87,0 @@ return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target), " + ", "'%'"]; |
{ | ||
"name": "@simplysm/sd-orm-common", | ||
"version": "3.5.57", | ||
"version": "3.5.58", | ||
"description": "심플리즘 패키지 - ORM 모듈 (browser/node)", | ||
@@ -13,4 +13,4 @@ "author": "김석래", | ||
"dependencies": { | ||
"@simplysm/sd-core-common": "3.5.57" | ||
"@simplysm/sd-core-common": "3.5.58" | ||
} | ||
} |
@@ -396,2 +396,34 @@ import { DbContext } from "./DbContext"; | ||
.where(item => { | ||
const fieldOrArr = []; | ||
const fields = fwd(item); | ||
for (const field of fields) { | ||
const splitSearchTextWhereArr = []; | ||
for (const text of splitSearchText) { | ||
if (text.includes("*")) { | ||
splitSearchTextWhereArr.push(this.db.qh.like(field as any, text.replace(/\*/g, "%"))); | ||
} | ||
else { | ||
splitSearchTextWhereArr.push(this.db.qh.includes(field as any, text)); | ||
} | ||
} | ||
fieldOrArr.push(this.db.qh.and(splitSearchTextWhereArr)); | ||
} | ||
return [this.db.qh.or(fieldOrArr)]; | ||
}); | ||
return result; | ||
} | ||
/*public search(fwd: (entity: TEntity<T>) => TEntityValue<String | string | undefined>[], searchText: string): Queryable<D, T> { | ||
let result: Queryable<D, T> = new Queryable(this.db, this); | ||
const splitSearchText = searchText.trim().split(" ") | ||
.map(item => item.trim()) | ||
.filter(item => Boolean(item)); | ||
// WHERE | ||
result = result | ||
.where(item => { | ||
const orArr = []; | ||
@@ -446,3 +478,3 @@ | ||
return result; | ||
} | ||
}*/ | ||
@@ -863,3 +895,3 @@ public wrap(): Queryable<D, T>; | ||
delete queryable._def.orderBy; | ||
delete queryable._entity["__searchOrder"]; | ||
// delete queryable._entity["__searchOrder"]; | ||
const item = await queryable.singleAsync(); | ||
@@ -866,0 +898,0 @@ |
@@ -104,2 +104,6 @@ import { | ||
public like(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[] { | ||
return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target)]; | ||
} | ||
public startsWith(source: TEntityValue<string | undefined>, target: TEntityValue<string | undefined>): TQueryBuilderValue[] { | ||
@@ -106,0 +110,0 @@ return [this.getQueryValue(source), " LIKE ", this.getQueryValue(target), " + ", "'%'"]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
656980
9836
+ Added@simplysm/sd-core-common@3.5.58(transitive)
- Removed@simplysm/sd-core-common@3.5.57(transitive)