@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(field: keyof T, value: string | string[]): this;
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(field, value) {
255
- if (!value || (Array.isArray(value) && value.length === 0))
254
+ like(conditions) {
255
+ if (!conditions || Object.keys(conditions).length === 0)
256
256
  return this;
257
257
  const qb = this.queryBuilder;
258
- const conditions = [];
259
- const params = {}; // Ensure this is always an object
260
- const values = Array.isArray(value) ? value : [value];
261
- values.forEach((val, index) => {
262
- const paramKey = `${String(field)}LikeParam${index}_${this.whereCount}`;
263
- conditions.push(`${this.entityAlias}.${String(field)} LIKE :${paramKey}`);
264
- params[paramKey] = val; // Directly use the value, allowing custom `%xyz%` patterns
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 (conditions.length > 0) {
267
- qb.andWhere(`(${conditions.join(" OR ")})`, params);
272
+ if (orConditions.length > 0) {
273
+ qb.andWhere(`(${orConditions.join(" OR ")})`, params);
268
274
  this.whereCount++;
269
275
  }
270
276
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",