@zuzjs/orm 0.1.4 → 0.1.5

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.
@@ -1,4 +1,4 @@
1
- import { Repository, ObjectLiteral, FindOptionsWhere } from "typeorm";
1
+ import { Repository, ObjectLiteral } from "typeorm";
2
2
  import { QueryAction } from "../types";
3
3
  import { QueryResult } from "mysql2";
4
4
  import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
@@ -40,7 +40,7 @@ declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends
40
40
  * @param condition - The condition to be added.
41
41
  * @returns The current instance of ZormQueryBuilder.
42
42
  */
43
- or(condition: FindOptionsWhere<T>): this;
43
+ or(condition: Partial<Record<keyof T, any>>): this;
44
44
  /**
45
45
  * Adds an ORDER BY clause to the query.
46
46
  * @param field - The field to order by.
@@ -88,20 +88,21 @@ class ZormQueryBuilder extends Promise {
88
88
  return this;
89
89
  }
90
90
  applyCondition(qb, condition, type) {
91
- Object.entries(condition).forEach(([key, value]) => {
91
+ Object.entries(condition).forEach(([key, value], index) => {
92
+ const paramKey = `${key}Param${index}_${this.whereCount}`; // Unique parameter name
92
93
  if (typeof value === "string") {
93
94
  const match = value.match(/^(!=|>=|<=|>|<|=)\s*(.+)$/); // Improved regex
94
95
  if (match) {
95
96
  const [, operator, rawValue] = match;
96
97
  const sqlOperator = operator; // Directly use the matched operator
97
- const paramKey = `${key}Param`; // Unique parameter name
98
98
  const parsedValue = !isNaN(Number(rawValue)) ? Number(rawValue) : rawValue.trim(); // Convert to number if possible
99
99
  qb[type](`${qb.alias}.${key} ${sqlOperator} :${paramKey}`, { [paramKey]: parsedValue });
100
100
  return;
101
101
  }
102
102
  }
103
103
  // Default case (normal equality condition)
104
- qb[type](`${this.entityAlias}.${key} = :${key}`, { [key]: value });
104
+ qb[type](`${this.entityAlias}.${key} = :${paramKey}`, { [paramKey]: value });
105
+ this.whereCount++;
105
106
  });
106
107
  }
107
108
  /**
@@ -112,7 +113,6 @@ class ZormQueryBuilder extends Promise {
112
113
  where(condition) {
113
114
  const qb = this.queryBuilder;
114
115
  this.applyCondition(qb, condition, `andWhere`);
115
- this.whereCount++;
116
116
  return this;
117
117
  }
118
118
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",