@zuzjs/orm 0.2.2 → 0.2.3
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(
|
|
121
|
+
like(conditions: Partial<Record<keyof T, string | string[]>>): this;
|
|
122
122
|
/**
|
|
123
123
|
* Adds a DISTINCT clause to the query.
|
|
124
124
|
* @returns The current instance of ZormQueryBuilder.
|
|
@@ -251,20 +251,26 @@ class ZormQueryBuilder extends Promise {
|
|
|
251
251
|
* @param value - A string or an array of strings to match.
|
|
252
252
|
* @returns The current instance of ZormQueryBuilder.
|
|
253
253
|
*/
|
|
254
|
-
like(
|
|
255
|
-
if (!
|
|
254
|
+
like(conditions) {
|
|
255
|
+
if (!conditions || Object.keys(conditions).length === 0)
|
|
256
256
|
return this;
|
|
257
257
|
const qb = this.queryBuilder;
|
|
258
|
-
const
|
|
259
|
-
const params = {};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
258
|
+
const orConditions = [];
|
|
259
|
+
const params = {};
|
|
260
|
+
Object.entries(conditions).forEach(([field, value]) => {
|
|
261
|
+
const values = Array.isArray(value) ? value : [value];
|
|
262
|
+
const fieldConditions = [];
|
|
263
|
+
values.forEach((val, index) => {
|
|
264
|
+
const paramKey = `${field}LikeParam${index}_${this.whereCount}`;
|
|
265
|
+
fieldConditions.push(`${this.entityAlias}.${String(field)} LIKE :${paramKey}`);
|
|
266
|
+
params[paramKey] = val; // Directly use the value (supports %xyz% pattern)
|
|
267
|
+
});
|
|
268
|
+
if (fieldConditions.length > 0) {
|
|
269
|
+
orConditions.push(`(${fieldConditions.join(" OR ")})`);
|
|
270
|
+
}
|
|
265
271
|
});
|
|
266
|
-
if (
|
|
267
|
-
qb.andWhere(`(${
|
|
272
|
+
if (orConditions.length > 0) {
|
|
273
|
+
qb.andWhere(`(${orConditions.join(" OR ")})`, params);
|
|
268
274
|
this.whereCount++;
|
|
269
275
|
}
|
|
270
276
|
return this;
|