@zuzjs/orm 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -118,7 +118,7 @@ declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends
|
|
|
118
118
|
* @param value - A string or an array of strings to match.
|
|
119
119
|
* @returns The current instance of ZormQueryBuilder.
|
|
120
120
|
*/
|
|
121
|
-
like(conditions: Partial<Record<keyof T, string | string[]
|
|
121
|
+
like(conditions: Partial<Record<keyof T, string | string[]>>, mode: "contains" | "startsWith" | "endsWith" | "exact"): this;
|
|
122
122
|
/**
|
|
123
123
|
* Adds a DISTINCT clause to the query.
|
|
124
124
|
* @returns The current instance of ZormQueryBuilder.
|
|
@@ -286,7 +286,7 @@ class ZormQueryBuilder extends Promise {
|
|
|
286
286
|
* @param value - A string or an array of strings to match.
|
|
287
287
|
* @returns The current instance of ZormQueryBuilder.
|
|
288
288
|
*/
|
|
289
|
-
like(conditions) {
|
|
289
|
+
like(conditions, mode) {
|
|
290
290
|
if (!conditions || Object.keys(conditions).length === 0)
|
|
291
291
|
return this;
|
|
292
292
|
const qb = this.queryBuilder;
|
|
@@ -298,7 +298,22 @@ class ZormQueryBuilder extends Promise {
|
|
|
298
298
|
values.forEach((val, index) => {
|
|
299
299
|
const paramKey = `${field}LikeParam${index}_${this.whereCount}`;
|
|
300
300
|
fieldConditions.push(`${this.entityAlias}.${String(field)} LIKE :${paramKey}`);
|
|
301
|
-
|
|
301
|
+
let formattedVal = val;
|
|
302
|
+
switch (mode || "contains") {
|
|
303
|
+
case "startsWith":
|
|
304
|
+
formattedVal = `${val}%`;
|
|
305
|
+
break;
|
|
306
|
+
case "endsWith":
|
|
307
|
+
formattedVal = `%${val}`;
|
|
308
|
+
break;
|
|
309
|
+
case "exact":
|
|
310
|
+
formattedVal = `${val}`;
|
|
311
|
+
break;
|
|
312
|
+
case "contains":
|
|
313
|
+
default:
|
|
314
|
+
formattedVal = `%${val}%`;
|
|
315
|
+
}
|
|
316
|
+
params[paramKey] = formattedVal; // Directly use the value (supports %xyz% pattern)
|
|
302
317
|
});
|
|
303
318
|
if (fieldConditions.length > 0) {
|
|
304
319
|
orConditions.push(`(${fieldConditions.join(" OR ")})`);
|