@mikro-orm/knex 6.0.0-dev.293 → 6.0.0-dev.295

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.
@@ -11,7 +11,6 @@ export declare abstract class AbstractSqlPlatform extends Platform {
11
11
  lookupExtensions(orm: MikroORM): void;
12
12
  getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): SqlSchemaGenerator;
13
13
  quoteValue(value: any): string;
14
- formatQuery(sql: string, params: readonly any[]): string;
15
14
  getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string;
16
15
  getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string;
17
16
  getJsonIndexDefinition(index: IndexDef): string[];
@@ -41,45 +41,6 @@ class AbstractSqlPlatform extends core_1.Platform {
41
41
  // @ts-ignore
42
42
  return (0, sqlstring_1.escape)(value, true, this.timezone);
43
43
  }
44
- formatQuery(sql, params) {
45
- if (params.length === 0) {
46
- return sql;
47
- }
48
- // fast string replace without regexps
49
- let j = 0;
50
- let pos = 0;
51
- let ret = '';
52
- if (sql[0] === '?') {
53
- if (sql[1] === '?') {
54
- ret += this.quoteIdentifier(params[j++]);
55
- pos = 2;
56
- }
57
- else {
58
- ret += this.quoteValue(params[j++]);
59
- pos = 1;
60
- }
61
- }
62
- while (pos < sql.length) {
63
- const idx = sql.indexOf('?', pos + 1);
64
- if (idx === -1) {
65
- ret += sql.substring(pos, sql.length);
66
- break;
67
- }
68
- if (sql.substring(idx - 1, idx + 1) === '\\?') {
69
- ret += sql.substring(pos, idx - 1) + '?';
70
- pos = idx + 1;
71
- }
72
- else if (sql.substring(idx, idx + 2) === '??') {
73
- ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]);
74
- pos = idx + 2;
75
- }
76
- else {
77
- ret += sql.substring(pos, idx) + this.quoteValue(params[j++]);
78
- pos = idx + 1;
79
- }
80
- }
81
- return ret;
82
- }
83
44
  getSearchJsonPropertySQL(path, type, aliased) {
84
45
  return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
85
46
  }
package/index.mjs CHANGED
@@ -33,6 +33,7 @@ export const Check = mod.Check;
33
33
  export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
34
34
  export const Collection = mod.Collection;
35
35
  export const CommitOrderCalculator = mod.CommitOrderCalculator;
36
+ export const Config = mod.Config;
36
37
  export const Configuration = mod.Configuration;
37
38
  export const ConfigurationLoader = mod.ConfigurationLoader;
38
39
  export const Connection = mod.Connection;
@@ -194,6 +195,7 @@ export const compareArrays = mod.compareArrays;
194
195
  export const compareBooleans = mod.compareBooleans;
195
196
  export const compareBuffers = mod.compareBuffers;
196
197
  export const compareObjects = mod.compareObjects;
198
+ export const createSqlFunction = mod.createSqlFunction;
197
199
  export const defineConfig = mod.defineConfig;
198
200
  export const equals = mod.equals;
199
201
  export const getOnConflictFields = mod.getOnConflictFields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.0-dev.293",
3
+ "version": "6.0.0-dev.295",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^5.0.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.293"
69
+ "@mikro-orm/core": "6.0.0-dev.295"
70
70
  }
71
71
  }
@@ -202,11 +202,11 @@ class QueryBuilderHelper {
202
202
  const alias = join.inverseAlias ?? join.alias;
203
203
  join.cond[`${alias}.${typeProperty}`] = join.prop.targetMeta.discriminatorValue;
204
204
  }
205
- Object.keys(join.cond).forEach(key => {
206
- const needsPrefix = key.includes('.') || core_1.Utils.isOperator(key) || core_1.RawQueryFragment.isKnownFragment(key);
207
- const newKey = needsPrefix ? key : `${join.alias}.${key}`;
208
- conditions.push(this.processJoinClause(newKey, join.cond[key], params));
209
- });
205
+ for (const key of Object.keys(join.cond)) {
206
+ const hasPrefix = key.includes('.') || core_1.Utils.isOperator(key) || core_1.RawQueryFragment.isKnownFragment(key);
207
+ const newKey = hasPrefix ? key : `${join.alias}.${key}`;
208
+ conditions.push(this.processJoinClause(newKey, join.cond[key], join.alias, params));
209
+ }
210
210
  let sql = method + ' ';
211
211
  if (join.subquery) {
212
212
  sql += `(${join.subquery})`;
@@ -221,10 +221,10 @@ class QueryBuilderHelper {
221
221
  return qb.joinRaw(sql, params);
222
222
  });
223
223
  }
224
- processJoinClause(key, value, params, operator = '$eq') {
224
+ processJoinClause(key, value, alias, params, operator = '$eq') {
225
225
  if (core_1.Utils.isGroupOperator(key) && Array.isArray(value)) {
226
226
  const parts = value.map(sub => {
227
- return this.wrapQueryGroup(Object.keys(sub).map(k => this.processJoinClause(k, sub[k], params)));
227
+ return this.wrapQueryGroup(Object.keys(sub).map(k => this.processJoinClause(k, sub[k], alias, params)));
228
228
  });
229
229
  return this.wrapQueryGroup(parts, key);
230
230
  }
@@ -236,11 +236,11 @@ class QueryBuilderHelper {
236
236
  value = this.platform.getRegExpValue(value);
237
237
  }
238
238
  if (core_1.Utils.isOperator(key, false) && core_1.Utils.isPlainObject(value)) {
239
- const parts = Object.keys(value).map(k => this.processJoinClause(k, value[k], params, key));
239
+ const parts = Object.keys(value).map(k => this.processJoinClause(k, value[k], alias, params, key));
240
240
  return key === '$not' ? `not ${this.wrapQueryGroup(parts)}` : this.wrapQueryGroup(parts);
241
241
  }
242
242
  if (core_1.Utils.isPlainObject(value) && Object.keys(value).every(k => core_1.Utils.isOperator(k, false))) {
243
- const parts = Object.keys(value).map(op => this.processJoinClause(key, value[op], params, op));
243
+ const parts = Object.keys(value).map(op => this.processJoinClause(key, value[op], alias, params, op));
244
244
  return this.wrapQueryGroup(parts);
245
245
  }
246
246
  operator = operator === '$not' ? '$eq' : operator;
@@ -267,7 +267,7 @@ class QueryBuilderHelper {
267
267
  }
268
268
  const rawField = core_1.RawQueryFragment.getKnownFragment(key);
269
269
  if (rawField) {
270
- let sql = rawField.sql;
270
+ let sql = rawField.sql.replaceAll(core_1.ALIAS_REPLACEMENT, alias);
271
271
  params.push(...rawField.params);
272
272
  params.push(...core_1.Utils.asArray(value));
273
273
  if (core_1.Utils.asArray(value).length > 0) {
@@ -201,6 +201,10 @@ class SchemaHelper {
201
201
  if (defaultValue == null) {
202
202
  return defaultValue;
203
203
  }
204
+ const raw = core_1.RawQueryFragment.getKnownFragment(defaultValue);
205
+ if (raw) {
206
+ return this.platform.formatQuery(raw.sql, raw.params);
207
+ }
204
208
  const genericValue = defaultValue.replace(/\(\d+\)/, '(?)').toLowerCase();
205
209
  const norm = defaultValues[genericValue];
206
210
  if (!norm) {