@zuzjs/orm 0.2.7 → 0.2.9

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[]>>): this;
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
- params[paramKey] = val; // Directly use the value (supports %xyz% pattern)
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 ")})`);
@@ -402,7 +417,7 @@ class ZormQueryBuilder extends Promise {
402
417
  hasRows: _select.length > 0,
403
418
  count: _select.length,
404
419
  row: _select.length > 0 ? _select[0] : null,
405
- rows: _select.length > 1 ? _select : [],
420
+ rows: _select.length == 1 ? [_select[0]] : _select,
406
421
  };
407
422
  if (this.isActiveRecord) {
408
423
  _result.save = () => this._saveActiveRecord(_select[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",