@zuzjs/orm 0.2.1 → 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.
@@ -134,6 +134,7 @@ class MySqlDriver {
134
134
  async generate() {
135
135
  const self = this;
136
136
  self.createPool();
137
+ const numberTypes = [`int`, `bigint`, `tinyint`, `decimal`];
137
138
  //Extract Tables
138
139
  console.log(picocolors_1.default.cyan("○ Extract Tables..."));
139
140
  const [tables] = await self.pool.execute("SHOW TABLES");
@@ -186,7 +187,7 @@ class MySqlDriver {
186
187
  if (Comment && Comment.length > 0) {
187
188
  entityCode.push(`\t/** @comment ${Comment} */`);
188
189
  }
189
- entityCode.push(`\t${Field}!: ${Key == `PRI` && [`int`, `bigint`].includes(Type) ? `number` : [`int`, `bigint`].includes(Type) ? `number` : tsType};\n`);
190
+ entityCode.push(`\t${Field}!: ${Key == `PRI` && numberTypes.includes(Type) ? `number` : numberTypes.includes(Type) ? `number` : tsType};\n`);
190
191
  }
191
192
  // Add foreign key relationships
192
193
  if (foreignKeys[tableName]) {
@@ -111,6 +111,14 @@ declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends
111
111
  * @returns The current instance of ZormQueryBuilder.
112
112
  */
113
113
  in(field: keyof T, values: any[]): this;
114
+ /**
115
+ * Adds a LIKE condition to the query, supporting both single and multiple values.
116
+ * If an array is provided, it uses OR conditions between them.
117
+ * @param field - The field to apply the LIKE condition on.
118
+ * @param value - A string or an array of strings to match.
119
+ * @returns The current instance of ZormQueryBuilder.
120
+ */
121
+ like(conditions: Partial<Record<keyof T, string | string[]>>): this;
114
122
  /**
115
123
  * Adds a DISTINCT clause to the query.
116
124
  * @returns The current instance of ZormQueryBuilder.
@@ -244,6 +244,37 @@ class ZormQueryBuilder extends Promise {
244
244
  this.whereCount++;
245
245
  return this;
246
246
  }
247
+ /**
248
+ * Adds a LIKE condition to the query, supporting both single and multiple values.
249
+ * If an array is provided, it uses OR conditions between them.
250
+ * @param field - The field to apply the LIKE condition on.
251
+ * @param value - A string or an array of strings to match.
252
+ * @returns The current instance of ZormQueryBuilder.
253
+ */
254
+ like(conditions) {
255
+ if (!conditions || Object.keys(conditions).length === 0)
256
+ return this;
257
+ const qb = this.queryBuilder;
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
+ }
271
+ });
272
+ if (orConditions.length > 0) {
273
+ qb.andWhere(`(${orConditions.join(" OR ")})`, params);
274
+ this.whereCount++;
275
+ }
276
+ return this;
277
+ }
247
278
  /**
248
279
  * Adds a DISTINCT clause to the query.
249
280
  * @returns The current instance of ZormQueryBuilder.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",