@zuzjs/orm 0.2.0 → 0.2.2
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` &&
|
|
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(field: keyof T, value: 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,31 @@ 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(field, value) {
|
|
255
|
+
if (!value || (Array.isArray(value) && value.length === 0))
|
|
256
|
+
return this;
|
|
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
|
|
265
|
+
});
|
|
266
|
+
if (conditions.length > 0) {
|
|
267
|
+
qb.andWhere(`(${conditions.join(" OR ")})`, params);
|
|
268
|
+
this.whereCount++;
|
|
269
|
+
}
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
247
272
|
/**
|
|
248
273
|
* Adds a DISTINCT clause to the query.
|
|
249
274
|
* @returns The current instance of ZormQueryBuilder.
|