@zuzjs/orm 0.2.6 → 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.
@@ -5,3 +5,4 @@ export declare const checkDirectory: (path: string, create: boolean) => {
5
5
  message?: string;
6
6
  };
7
7
  export declare const stackTrace: (_error: string, ...more: string[]) => Error;
8
+ export declare const isNumber: (val: any) => boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.stackTrace = exports.checkDirectory = exports.mapSqlTypeToTypescript = exports.toPascalCase = void 0;
6
+ exports.isNumber = exports.stackTrace = exports.checkDirectory = exports.mapSqlTypeToTypescript = exports.toPascalCase = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const toPascalCase = (str) => {
9
9
  return str.replace(/(^\w|_\w)/g, (match) => match.replace("_", "").toUpperCase());
@@ -68,3 +68,5 @@ const stackTrace = (_error, ...more) => {
68
68
  return Error(lines.join(`\n`));
69
69
  };
70
70
  exports.stackTrace = stackTrace;
71
+ const isNumber = (val) => /^[+-]?\d+(\.\d+)?$/.test(val);
72
+ exports.isNumber = isNumber;
@@ -172,8 +172,9 @@ class MySqlDriver {
172
172
  let enumName = null;
173
173
  if (columnType === "enum" && enumValues) {
174
174
  enumName = (0, index_js_1.toPascalCase)(Field);
175
- enums.push(`export enum ${enumName} { ${enumValues.map(v => `${(0, index_js_1.toPascalCase)(v)} = "${v}"`).join(", ")} }`);
176
- // entityCode.push(`\t@Column({ type: "enum", enum: ${enumName} })\n`);
175
+ enums.push(`export enum ${enumName} { ${enumValues.map(v => {
176
+ return `${(0, index_js_1.isNumber)(v) ? `val${v}` : (0, index_js_1.toPascalCase)(v)} = "${v}"`;
177
+ }).join(", ")} }`);
177
178
  }
178
179
  // Handle primary key
179
180
  if (Key === "PRI") {
@@ -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.
@@ -20,6 +20,22 @@ class ZormQueryBuilder extends Promise {
20
20
  this.action = _action;
21
21
  this.usePromise = _usePromise || false;
22
22
  this.activeRecord = null;
23
+ // switch (_action) {
24
+ // case "create":
25
+ // case "upsert":
26
+ // this.queryBuilder = repository.createQueryBuilder(this.entityAlias) as InsertQueryBuilder<ObjectLiteral>;
27
+ // break;
28
+ // case "update":
29
+ // this.queryBuilder = repository.createQueryBuilder(this.entityAlias).update() as UpdateQueryBuilder<T>;
30
+ // break;
31
+ // case "delete":
32
+ // this.queryBuilder = repository.createQueryBuilder(this.entityAlias).delete() as DeleteQueryBuilder<T>;
33
+ // break;
34
+ // case "select":
35
+ // default:
36
+ // this.queryBuilder = repository.createQueryBuilder(this.entityAlias) as SelectQueryBuilder<T>;
37
+ // break;
38
+ // }
23
39
  }
24
40
  _create() {
25
41
  if (this.queryValues) {
@@ -270,7 +286,7 @@ class ZormQueryBuilder extends Promise {
270
286
  * @param value - A string or an array of strings to match.
271
287
  * @returns The current instance of ZormQueryBuilder.
272
288
  */
273
- like(conditions) {
289
+ like(conditions, mode) {
274
290
  if (!conditions || Object.keys(conditions).length === 0)
275
291
  return this;
276
292
  const qb = this.queryBuilder;
@@ -282,7 +298,22 @@ class ZormQueryBuilder extends Promise {
282
298
  values.forEach((val, index) => {
283
299
  const paramKey = `${field}LikeParam${index}_${this.whereCount}`;
284
300
  fieldConditions.push(`${this.entityAlias}.${String(field)} LIKE :${paramKey}`);
285
- 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)
286
317
  });
287
318
  if (fieldConditions.length > 0) {
288
319
  orConditions.push(`(${fieldConditions.join(" OR ")})`);
@@ -365,6 +396,7 @@ class ZormQueryBuilder extends Promise {
365
396
  const _get = this.repository
366
397
  .createQueryBuilder(this.entityAlias)
367
398
  .where(whereQuery, _updateQuery.getParameters()); // Use the same parameters
399
+ // console.log(_updateQuery.getQueryAndParameters())
368
400
  const _updated = await _get.getMany();
369
401
  return {
370
402
  updated: _update.affected ? _update.affected > 0 : false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",