@mikro-orm/knex 7.0.0-dev.1 → 7.0.0-dev.11

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.
Files changed (79) hide show
  1. package/AbstractSqlConnection.d.ts +2 -2
  2. package/AbstractSqlConnection.js +33 -31
  3. package/AbstractSqlDriver.d.ts +14 -12
  4. package/AbstractSqlDriver.js +198 -186
  5. package/AbstractSqlPlatform.d.ts +4 -4
  6. package/AbstractSqlPlatform.js +17 -21
  7. package/PivotCollectionPersister.d.ts +1 -1
  8. package/PivotCollectionPersister.js +5 -8
  9. package/SqlEntityManager.d.ts +4 -3
  10. package/SqlEntityManager.js +2 -6
  11. package/SqlEntityRepository.d.ts +2 -2
  12. package/SqlEntityRepository.js +2 -6
  13. package/dialects/index.d.ts +4 -4
  14. package/dialects/index.js +4 -20
  15. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +1 -1
  16. package/dialects/mssql/MsSqlNativeQueryBuilder.js +29 -29
  17. package/dialects/mssql/index.d.ts +1 -1
  18. package/dialects/mssql/index.js +1 -17
  19. package/dialects/mysql/MySqlExceptionConverter.js +16 -19
  20. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +1 -1
  21. package/dialects/mysql/MySqlNativeQueryBuilder.js +13 -17
  22. package/dialects/mysql/MySqlPlatform.d.ts +5 -5
  23. package/dialects/mysql/MySqlPlatform.js +16 -20
  24. package/dialects/mysql/MySqlSchemaHelper.d.ts +5 -5
  25. package/dialects/mysql/MySqlSchemaHelper.js +8 -12
  26. package/dialects/mysql/index.d.ts +4 -4
  27. package/dialects/mysql/index.js +4 -20
  28. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
  29. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +2 -6
  30. package/dialects/postgresql/index.d.ts +1 -1
  31. package/dialects/postgresql/index.js +1 -17
  32. package/dialects/sqlite/BaseSqliteConnection.d.ts +2 -2
  33. package/dialects/sqlite/BaseSqliteConnection.js +14 -12
  34. package/dialects/sqlite/BaseSqlitePlatform.d.ts +4 -5
  35. package/dialects/sqlite/BaseSqlitePlatform.js +11 -19
  36. package/dialects/sqlite/SqliteExceptionConverter.js +16 -19
  37. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +1 -1
  38. package/dialects/sqlite/SqliteNativeQueryBuilder.js +2 -6
  39. package/dialects/sqlite/SqliteSchemaHelper.d.ts +5 -5
  40. package/dialects/sqlite/SqliteSchemaHelper.js +22 -26
  41. package/dialects/sqlite/index.d.ts +5 -5
  42. package/dialects/sqlite/index.js +5 -21
  43. package/index.d.ts +11 -11
  44. package/index.js +13 -34
  45. package/package.json +7 -16
  46. package/query/ArrayCriteriaNode.d.ts +2 -2
  47. package/query/ArrayCriteriaNode.js +2 -6
  48. package/query/CriteriaNode.d.ts +1 -1
  49. package/query/CriteriaNode.js +25 -33
  50. package/query/CriteriaNodeFactory.d.ts +1 -1
  51. package/query/CriteriaNodeFactory.js +17 -21
  52. package/query/NativeQueryBuilder.d.ts +2 -2
  53. package/query/NativeQueryBuilder.js +33 -37
  54. package/query/ObjectCriteriaNode.d.ts +2 -2
  55. package/query/ObjectCriteriaNode.js +43 -43
  56. package/query/QueryBuilder.d.ts +17 -15
  57. package/query/QueryBuilder.js +204 -193
  58. package/query/QueryBuilderHelper.d.ts +4 -4
  59. package/query/QueryBuilderHelper.js +86 -96
  60. package/query/ScalarCriteriaNode.d.ts +2 -2
  61. package/query/ScalarCriteriaNode.js +12 -16
  62. package/query/enums.js +4 -7
  63. package/query/index.d.ts +9 -9
  64. package/query/index.js +9 -25
  65. package/schema/DatabaseSchema.d.ts +3 -3
  66. package/schema/DatabaseSchema.js +7 -11
  67. package/schema/DatabaseTable.d.ts +3 -3
  68. package/schema/DatabaseTable.js +44 -33
  69. package/schema/SchemaComparator.d.ts +4 -4
  70. package/schema/SchemaComparator.js +15 -19
  71. package/schema/SchemaHelper.d.ts +5 -5
  72. package/schema/SchemaHelper.js +22 -26
  73. package/schema/SqlSchemaGenerator.d.ts +4 -4
  74. package/schema/SqlSchemaGenerator.js +23 -36
  75. package/schema/index.d.ts +5 -5
  76. package/schema/index.js +5 -21
  77. package/typings.d.ts +7 -4
  78. package/typings.js +1 -2
  79. package/index.mjs +0 -232
package/index.d.ts CHANGED
@@ -2,17 +2,17 @@
2
2
  * @packageDocumentation
3
3
  * @module knex
4
4
  */
5
- export * from './AbstractSqlConnection';
6
- export * from './AbstractSqlDriver';
7
- export * from './AbstractSqlPlatform';
8
- export * from './SqlEntityManager';
9
- export * from './SqlEntityRepository';
10
- export * from './query';
11
- export * from './schema';
12
- export * from './dialects';
13
- export * from './typings';
14
- export { SqlEntityManager as EntityManager } from './SqlEntityManager';
15
- export { SqlEntityRepository as EntityRepository } from './SqlEntityRepository';
16
5
  /** @ignore */
17
6
  export { Kysely } from 'kysely';
18
7
  export * from '@mikro-orm/core';
8
+ export * from './AbstractSqlConnection.js';
9
+ export * from './AbstractSqlDriver.js';
10
+ export * from './AbstractSqlPlatform.js';
11
+ export * from './SqlEntityManager.js';
12
+ export * from './SqlEntityRepository.js';
13
+ export * from './query/index.js';
14
+ export * from './schema/index.js';
15
+ export * from './dialects/index.js';
16
+ export * from './typings.js';
17
+ export { SqlEntityManager as EntityManager } from './SqlEntityManager.js';
18
+ export { SqlEntityRepository as EntityRepository } from './SqlEntityRepository.js';
package/index.js CHANGED
@@ -1,39 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Kysely = exports.EntityRepository = exports.EntityManager = void 0;
18
1
  /**
19
2
  * @packageDocumentation
20
3
  * @module knex
21
4
  */
22
- /* istanbul ignore file */
23
- __exportStar(require("./AbstractSqlConnection"), exports);
24
- __exportStar(require("./AbstractSqlDriver"), exports);
25
- __exportStar(require("./AbstractSqlPlatform"), exports);
26
- __exportStar(require("./SqlEntityManager"), exports);
27
- __exportStar(require("./SqlEntityRepository"), exports);
28
- __exportStar(require("./query"), exports);
29
- __exportStar(require("./schema"), exports);
30
- __exportStar(require("./dialects"), exports);
31
- __exportStar(require("./typings"), exports);
32
- var SqlEntityManager_1 = require("./SqlEntityManager");
33
- Object.defineProperty(exports, "EntityManager", { enumerable: true, get: function () { return SqlEntityManager_1.SqlEntityManager; } });
34
- var SqlEntityRepository_1 = require("./SqlEntityRepository");
35
- Object.defineProperty(exports, "EntityRepository", { enumerable: true, get: function () { return SqlEntityRepository_1.SqlEntityRepository; } });
36
5
  /** @ignore */
37
- var kysely_1 = require("kysely");
38
- Object.defineProperty(exports, "Kysely", { enumerable: true, get: function () { return kysely_1.Kysely; } });
39
- __exportStar(require("@mikro-orm/core"), exports);
6
+ export { Kysely } from 'kysely';
7
+ export * from '@mikro-orm/core';
8
+ export * from './AbstractSqlConnection.js';
9
+ export * from './AbstractSqlDriver.js';
10
+ export * from './AbstractSqlPlatform.js';
11
+ export * from './SqlEntityManager.js';
12
+ export * from './SqlEntityRepository.js';
13
+ export * from './query/index.js';
14
+ export * from './schema/index.js';
15
+ export * from './dialects/index.js';
16
+ export * from './typings.js';
17
+ export { SqlEntityManager as EntityManager } from './SqlEntityManager.js';
18
+ export { SqlEntityRepository as EntityRepository } from './SqlEntityRepository.js';
package/package.json CHANGED
@@ -1,19 +1,11 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "7.0.0-dev.1",
3
+ "version": "7.0.0-dev.11",
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
- "main": "index.js",
6
- "module": "index.mjs",
7
- "typings": "index.d.ts",
5
+ "type": "module",
8
6
  "exports": {
9
7
  "./package.json": "./package.json",
10
- ".": {
11
- "import": {
12
- "types": "./index.d.ts",
13
- "default": "./index.mjs"
14
- },
15
- "require": "./index.js"
16
- }
8
+ ".": "./index.js"
17
9
  },
18
10
  "repository": {
19
11
  "type": "git",
@@ -49,7 +41,7 @@
49
41
  "node": ">= 22.11.0"
50
42
  },
51
43
  "scripts": {
52
- "build": "yarn clean && yarn compile && yarn copy && yarn run -T gen-esm-wrapper index.js index.mjs",
44
+ "build": "yarn clean && yarn compile && yarn copy",
53
45
  "clean": "yarn run -T rimraf ./dist",
54
46
  "compile": "yarn run -T tsc -p tsconfig.build.json",
55
47
  "copy": "node ../../scripts/copy.mjs"
@@ -58,14 +50,13 @@
58
50
  "access": "public"
59
51
  },
60
52
  "dependencies": {
61
- "fs-extra": "11.3.0",
62
- "kysely": "https://pkg.pr.new/kysely-org/kysely/kysely@2b7007e",
53
+ "kysely": "0.28.0",
63
54
  "sqlstring": "2.3.3"
64
55
  },
65
56
  "devDependencies": {
66
- "@mikro-orm/core": "^6.4.5"
57
+ "@mikro-orm/core": "^6.4.13"
67
58
  },
68
59
  "peerDependencies": {
69
- "@mikro-orm/core": "7.0.0-dev.1"
60
+ "@mikro-orm/core": "7.0.0-dev.11"
70
61
  }
71
62
  }
@@ -1,5 +1,5 @@
1
- import { CriteriaNode } from './CriteriaNode';
2
- import type { IQueryBuilder, ICriteriaNodeProcessOptions } from '../typings';
1
+ import { CriteriaNode } from './CriteriaNode.js';
2
+ import type { IQueryBuilder, ICriteriaNodeProcessOptions } from '../typings.js';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayCriteriaNode = void 0;
4
- const CriteriaNode_1 = require("./CriteriaNode");
1
+ import { CriteriaNode } from './CriteriaNode.js';
5
2
  /**
6
3
  * @internal
7
4
  */
8
- class ArrayCriteriaNode extends CriteriaNode_1.CriteriaNode {
5
+ export class ArrayCriteriaNode extends CriteriaNode {
9
6
  process(qb, options) {
10
7
  return this.payload.map((node) => {
11
8
  return node.process(qb, options);
@@ -22,4 +19,3 @@ class ArrayCriteriaNode extends CriteriaNode_1.CriteriaNode {
22
19
  });
23
20
  }
24
21
  }
25
- exports.ArrayCriteriaNode = ArrayCriteriaNode;
@@ -1,6 +1,6 @@
1
1
  import { inspect } from 'node:util';
2
2
  import { type EntityKey, type EntityProperty, type MetadataStorage } from '@mikro-orm/core';
3
- import type { ICriteriaNode, ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings';
3
+ import type { ICriteriaNode, ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings.js';
4
4
  /**
5
5
  * Helper for working with deeply nested where/orderBy/having criteria. Uses composite pattern to build tree from the payload.
6
6
  * Auto-joins relations and converts payload from { books: { publisher: { name: '...' } } } to { 'publisher_alias.name': '...' }
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CriteriaNode = void 0;
4
- const node_util_1 = require("node:util");
5
- const core_1 = require("@mikro-orm/core");
1
+ import { inspect } from 'node:util';
2
+ import { RawQueryFragment, ReferenceKind, Utils, } from '@mikro-orm/core';
6
3
  /**
7
4
  * Helper for working with deeply nested where/orderBy/having criteria. Uses composite pattern to build tree from the payload.
8
5
  * Auto-joins relations and converts payload from { books: { publisher: { name: '...' } } } to { 'publisher_alias.name': '...' }
9
6
  * @internal
10
7
  */
11
- class CriteriaNode {
8
+ export class CriteriaNode {
12
9
  metadata;
13
10
  entityName;
14
11
  parent;
@@ -23,7 +20,7 @@ class CriteriaNode {
23
20
  this.key = key;
24
21
  const meta = parent && metadata.find(parent.entityName);
25
22
  if (meta && key) {
26
- const pks = core_1.Utils.splitPrimaryKeys(key);
23
+ const pks = Utils.splitPrimaryKeys(key);
27
24
  if (pks.length > 1) {
28
25
  return;
29
26
  }
@@ -31,7 +28,7 @@ class CriteriaNode {
31
28
  this.prop = meta.props.find(prop => prop.name === k || (prop.fieldNames?.length === 1 && prop.fieldNames[0] === k && prop.persist !== false));
32
29
  const isProp = this.prop || meta.props.find(prop => (prop.fieldNames || []).includes(k));
33
30
  // do not validate if the key is prefixed or type casted (e.g. `k::text`)
34
- if (validate && !isProp && !k.includes('.') && !k.includes('::') && !core_1.Utils.isOperator(k) && !core_1.RawQueryFragment.isKnownFragment(k)) {
31
+ if (validate && !isProp && !k.includes('.') && !k.includes('::') && !Utils.isOperator(k) && !RawQueryFragment.isKnownFragment(k)) {
35
32
  throw new Error(`Trying to query by not existing property ${entityName}.${k}`);
36
33
  }
37
34
  }
@@ -52,41 +49,37 @@ class CriteriaNode {
52
49
  shouldRename(payload) {
53
50
  const type = this.prop ? this.prop.kind : null;
54
51
  const composite = this.prop?.joinColumns ? this.prop.joinColumns.length > 1 : false;
55
- const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
56
- const scalar = payload === null || core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
57
- const plainObject = core_1.Utils.isPlainObject(payload);
52
+ const customExpression = RawQueryFragment.isKnownFragment(this.key);
53
+ const scalar = payload === null || Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
54
+ const plainObject = Utils.isPlainObject(payload);
58
55
  const keys = plainObject ? Object.keys(payload) : [];
59
- const operator = plainObject && keys.every(k => core_1.Utils.isOperator(k, false));
56
+ const operator = plainObject && keys.every(k => Utils.isOperator(k, false));
60
57
  if (composite) {
61
58
  return true;
62
59
  }
63
60
  switch (type) {
64
- case core_1.ReferenceKind.MANY_TO_ONE: return false;
65
- case core_1.ReferenceKind.ONE_TO_ONE: return !this.prop.owner;
66
- case core_1.ReferenceKind.ONE_TO_MANY: return scalar || operator;
67
- case core_1.ReferenceKind.MANY_TO_MANY: return scalar || operator;
61
+ case ReferenceKind.MANY_TO_ONE: return false;
62
+ case ReferenceKind.ONE_TO_ONE: return !this.prop.owner;
63
+ case ReferenceKind.ONE_TO_MANY: return scalar || operator;
64
+ case ReferenceKind.MANY_TO_MANY: return scalar || operator;
68
65
  default: return false;
69
66
  }
70
67
  }
71
68
  renameFieldToPK(qb) {
72
69
  let joinAlias = qb.getAliasForJoinPath(this.getPath());
73
- if (!joinAlias && this.parent && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(this.prop.kind) && this.prop.owner) {
70
+ if (!joinAlias && this.parent && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind) && this.prop.owner) {
74
71
  joinAlias = qb.getAliasForJoinPath(this.parent.getPath());
75
- return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${joinAlias ?? qb.alias}.${col}`));
72
+ return Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${joinAlias ?? qb.alias}.${col}`));
76
73
  }
77
74
  const alias = joinAlias ?? qb.alias;
78
- if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY) {
79
- return core_1.Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
75
+ if (this.prop.kind === ReferenceKind.MANY_TO_MANY) {
76
+ return Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
80
77
  }
81
- // if we found a matching join, we need to use the target table column names, as we use that alias instead of the root
82
- if (!joinAlias && this.prop.owner && this.prop.joinColumns.length > 1) {
83
- return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${alias}.${col}`));
84
- }
85
- return core_1.Utils.getPrimaryKeyHash(this.prop.referencedColumnNames.map(col => `${alias}.${col}`));
78
+ return Utils.getPrimaryKeyHash(this.prop.referencedColumnNames.map(col => `${alias}.${col}`));
86
79
  }
87
80
  getPath(addIndex = false) {
88
81
  // use index on parent only if we are processing to-many relation
89
- const addParentIndex = this.prop && [core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(this.prop.kind);
82
+ const addParentIndex = this.prop && [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(this.prop.kind);
90
83
  const parentPath = this.parent?.getPath(addParentIndex) ?? this.entityName;
91
84
  const index = addIndex && this.index != null ? `[${this.index}]` : '';
92
85
  // ignore group operators to allow easier mapping (e.g. for orderBy)
@@ -102,10 +95,10 @@ class CriteriaNode {
102
95
  if (!this.key || !this.prop) {
103
96
  return false;
104
97
  }
105
- const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
106
- const scalar = this.payload === null || core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
107
- const operator = core_1.Utils.isObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
108
- return this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY && (scalar || operator);
98
+ const customExpression = RawQueryFragment.isKnownFragment(this.key);
99
+ const scalar = this.payload === null || Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
100
+ const operator = Utils.isObject(this.payload) && Object.keys(this.payload).every(k => Utils.isOperator(k, false));
101
+ return this.prop.kind === ReferenceKind.MANY_TO_MANY && (scalar || operator);
109
102
  }
110
103
  getPivotPath(path) {
111
104
  return `${path}[pivot]`;
@@ -114,12 +107,11 @@ class CriteriaNode {
114
107
  return alias ? `${alias}.${field}` : field;
115
108
  }
116
109
  /** @ignore */
117
- [node_util_1.inspect.custom]() {
110
+ [inspect.custom]() {
118
111
  const o = {};
119
112
  ['entityName', 'key', 'index', 'payload']
120
113
  .filter(k => this[k] !== undefined)
121
114
  .forEach(k => o[k] = this[k]);
122
- return `${this.constructor.name} ${(0, node_util_1.inspect)(o)}`;
115
+ return `${this.constructor.name} ${inspect(o)}`;
123
116
  }
124
117
  }
125
- exports.CriteriaNode = CriteriaNode;
@@ -1,5 +1,5 @@
1
1
  import { type Dictionary, type EntityKey, type EntityMetadata, type MetadataStorage } from '@mikro-orm/core';
2
- import type { ICriteriaNode } from '../typings';
2
+ import type { ICriteriaNode } from '../typings.js';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -1,32 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CriteriaNodeFactory = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const ObjectCriteriaNode_1 = require("./ObjectCriteriaNode");
6
- const ArrayCriteriaNode_1 = require("./ArrayCriteriaNode");
7
- const ScalarCriteriaNode_1 = require("./ScalarCriteriaNode");
1
+ import { isRaw, JsonType, RawQueryFragment, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core';
2
+ import { ObjectCriteriaNode } from './ObjectCriteriaNode.js';
3
+ import { ArrayCriteriaNode } from './ArrayCriteriaNode.js';
4
+ import { ScalarCriteriaNode } from './ScalarCriteriaNode.js';
8
5
  /**
9
6
  * @internal
10
7
  */
11
- class CriteriaNodeFactory {
8
+ export class CriteriaNodeFactory {
12
9
  static createNode(metadata, entityName, payload, parent, key) {
13
- const customExpression = core_1.RawQueryFragment.isKnownFragment(key || '');
14
- const scalar = core_1.Utils.isPrimaryKey(payload) || (0, core_1.isRaw)(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
10
+ const customExpression = RawQueryFragment.isKnownFragment(key || '');
11
+ const scalar = Utils.isPrimaryKey(payload) || isRaw(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
15
12
  if (Array.isArray(payload) && !scalar) {
16
13
  return this.createArrayNode(metadata, entityName, payload, parent, key);
17
14
  }
18
- if (core_1.Utils.isPlainObject(payload) && !scalar) {
15
+ if (Utils.isPlainObject(payload) && !scalar) {
19
16
  return this.createObjectNode(metadata, entityName, payload, parent, key);
20
17
  }
21
18
  return this.createScalarNode(metadata, entityName, payload, parent, key);
22
19
  }
23
20
  static createScalarNode(metadata, entityName, payload, parent, key) {
24
- const node = new ScalarCriteriaNode_1.ScalarCriteriaNode(metadata, entityName, parent, key);
21
+ const node = new ScalarCriteriaNode(metadata, entityName, parent, key);
25
22
  node.payload = payload;
26
23
  return node;
27
24
  }
28
25
  static createArrayNode(metadata, entityName, payload, parent, key) {
29
- const node = new ArrayCriteriaNode_1.ArrayCriteriaNode(metadata, entityName, parent, key);
26
+ const node = new ArrayCriteriaNode(metadata, entityName, parent, key);
30
27
  node.payload = payload.map((item, index) => {
31
28
  const n = this.createNode(metadata, entityName, item, node);
32
29
  // we care about branching only for $and
@@ -39,7 +36,7 @@ class CriteriaNodeFactory {
39
36
  }
40
37
  static createObjectNode(metadata, entityName, payload, parent, key) {
41
38
  const meta = metadata.find(entityName);
42
- const node = new ObjectCriteriaNode_1.ObjectCriteriaNode(metadata, entityName, parent, key);
39
+ const node = new ObjectCriteriaNode(metadata, entityName, parent, key);
43
40
  node.payload = {};
44
41
  for (const key of Object.keys(payload)) {
45
42
  node.payload[key] = this.createObjectItemNode(metadata, entityName, node, payload, key, meta);
@@ -48,11 +45,11 @@ class CriteriaNodeFactory {
48
45
  }
49
46
  static createObjectItemNode(metadata, entityName, node, payload, key, meta) {
50
47
  const prop = meta?.properties[key];
51
- const childEntity = prop && prop.kind !== core_1.ReferenceKind.SCALAR ? prop.type : entityName;
52
- if (prop?.customType instanceof core_1.JsonType) {
48
+ const childEntity = prop && prop.kind !== ReferenceKind.SCALAR ? prop.type : entityName;
49
+ if (prop?.customType instanceof JsonType) {
53
50
  return this.createScalarNode(metadata, childEntity, payload[key], node, key);
54
51
  }
55
- if (prop?.kind !== core_1.ReferenceKind.EMBEDDED) {
52
+ if (prop?.kind !== ReferenceKind.EMBEDDED) {
56
53
  return this.createNode(metadata, childEntity, payload[key], node, key);
57
54
  }
58
55
  if (payload[key] == null) {
@@ -64,13 +61,13 @@ class CriteriaNodeFactory {
64
61
  }
65
62
  // array operators can be used on embedded properties
66
63
  const allowedOperators = ['$contains', '$contained', '$overlap'];
67
- const operator = Object.keys(payload[key]).some(f => core_1.Utils.isOperator(f) && !allowedOperators.includes(f));
64
+ const operator = Object.keys(payload[key]).some(f => Utils.isOperator(f) && !allowedOperators.includes(f));
68
65
  if (operator) {
69
- throw core_1.ValidationError.cannotUseOperatorsInsideEmbeddables(entityName, prop.name, payload);
66
+ throw ValidationError.cannotUseOperatorsInsideEmbeddables(entityName, prop.name, payload);
70
67
  }
71
68
  const map = Object.keys(payload[key]).reduce((oo, k) => {
72
69
  if (!prop.embeddedProps[k] && !allowedOperators.includes(k)) {
73
- throw core_1.ValidationError.invalidEmbeddableQuery(entityName, k, prop.type);
70
+ throw ValidationError.invalidEmbeddableQuery(entityName, k, prop.type);
74
71
  }
75
72
  if (prop.embeddedProps[k]) {
76
73
  oo[prop.embeddedProps[k].name] = payload[key][k];
@@ -86,4 +83,3 @@ class CriteriaNodeFactory {
86
83
  return this.createNode(metadata, entityName, map, node, key);
87
84
  }
88
85
  }
89
- exports.CriteriaNodeFactory = CriteriaNodeFactory;
@@ -1,6 +1,6 @@
1
1
  import { type Dictionary, LockMode, type QueryFlag, RawQueryFragment } from '@mikro-orm/core';
2
- import { QueryType } from './enums';
3
- import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
2
+ import { QueryType } from './enums.js';
3
+ import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
4
4
  interface Options {
5
5
  tableName?: string | RawQueryFragment;
6
6
  indexHint?: string;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NativeQueryBuilder = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const enums_1 = require("./enums");
1
+ import { LockMode, raw, RawQueryFragment, Utils } from '@mikro-orm/core';
2
+ import { QueryType } from './enums.js';
6
3
  /** @internal */
7
- class NativeQueryBuilder {
4
+ export class NativeQueryBuilder {
8
5
  platform;
9
6
  type;
10
7
  parts = [];
@@ -14,14 +11,14 @@ class NativeQueryBuilder {
14
11
  this.platform = platform;
15
12
  }
16
13
  select(fields) {
17
- this.type = enums_1.QueryType.SELECT;
14
+ this.type = QueryType.SELECT;
18
15
  this.options.select ??= [];
19
- this.options.select.push(...core_1.Utils.asArray(fields));
16
+ this.options.select.push(...Utils.asArray(fields));
20
17
  return this;
21
18
  }
22
19
  count(fields = '*', distinct) {
23
- this.type = enums_1.QueryType.COUNT;
24
- this.options.select = core_1.Utils.asArray(fields);
20
+ this.type = QueryType.COUNT;
21
+ this.options.select = Utils.asArray(fields);
25
22
  this.options.distinct = distinct;
26
23
  return this;
27
24
  }
@@ -31,7 +28,7 @@ class NativeQueryBuilder {
31
28
  from(tableName, options) {
32
29
  if (tableName instanceof NativeQueryBuilder) {
33
30
  const { sql, params } = tableName.compile();
34
- tableName = (0, core_1.raw)(sql, params);
31
+ tableName = raw(sql, params);
35
32
  }
36
33
  if (typeof tableName === 'string') {
37
34
  const alias = options?.alias ? ` as ${this.platform.quoteIdentifier(options.alias)}` : '';
@@ -77,20 +74,20 @@ class NativeQueryBuilder {
77
74
  this.parts.push(...this.options.comment.map(comment => `/* ${comment} */`));
78
75
  }
79
76
  switch (this.type) {
80
- case enums_1.QueryType.SELECT:
81
- case enums_1.QueryType.COUNT:
77
+ case QueryType.SELECT:
78
+ case QueryType.COUNT:
82
79
  this.compileSelect();
83
80
  break;
84
- case enums_1.QueryType.INSERT:
81
+ case QueryType.INSERT:
85
82
  this.compileInsert();
86
83
  break;
87
- case enums_1.QueryType.UPDATE:
84
+ case QueryType.UPDATE:
88
85
  this.compileUpdate();
89
86
  break;
90
- case enums_1.QueryType.DELETE:
87
+ case QueryType.DELETE:
91
88
  this.compileDelete();
92
89
  break;
93
- case enums_1.QueryType.TRUNCATE:
90
+ case QueryType.TRUNCATE:
94
91
  this.compileTruncate();
95
92
  break;
96
93
  }
@@ -106,20 +103,20 @@ class NativeQueryBuilder {
106
103
  if (!this.options.lockMode) {
107
104
  return;
108
105
  }
109
- if ([core_1.LockMode.PESSIMISTIC_READ, core_1.LockMode.PESSIMISTIC_PARTIAL_READ, core_1.LockMode.PESSIMISTIC_READ_OR_FAIL].includes(this.options.lockMode)) {
106
+ if ([LockMode.PESSIMISTIC_READ, LockMode.PESSIMISTIC_PARTIAL_READ, LockMode.PESSIMISTIC_READ_OR_FAIL].includes(this.options.lockMode)) {
110
107
  this.parts.push('for share');
111
108
  }
112
- if ([core_1.LockMode.PESSIMISTIC_WRITE, core_1.LockMode.PESSIMISTIC_PARTIAL_WRITE, core_1.LockMode.PESSIMISTIC_WRITE_OR_FAIL].includes(this.options.lockMode)) {
109
+ if ([LockMode.PESSIMISTIC_WRITE, LockMode.PESSIMISTIC_PARTIAL_WRITE, LockMode.PESSIMISTIC_WRITE_OR_FAIL].includes(this.options.lockMode)) {
113
110
  this.parts.push('for update');
114
111
  }
115
112
  if (this.options.lockTables?.length) {
116
113
  const fields = this.options.lockTables.map(field => this.quote(field));
117
114
  this.parts.push(`of ${fields.join(', ')}`);
118
115
  }
119
- if ([core_1.LockMode.PESSIMISTIC_PARTIAL_READ, core_1.LockMode.PESSIMISTIC_PARTIAL_WRITE].includes(this.options.lockMode)) {
116
+ if ([LockMode.PESSIMISTIC_PARTIAL_READ, LockMode.PESSIMISTIC_PARTIAL_WRITE].includes(this.options.lockMode)) {
120
117
  this.parts.push('skip locked');
121
118
  }
122
- if ([core_1.LockMode.PESSIMISTIC_READ_OR_FAIL, core_1.LockMode.PESSIMISTIC_WRITE_OR_FAIL].includes(this.options.lockMode)) {
119
+ if ([LockMode.PESSIMISTIC_READ_OR_FAIL, LockMode.PESSIMISTIC_WRITE_OR_FAIL].includes(this.options.lockMode)) {
123
120
  this.parts.push('nowait');
124
121
  }
125
122
  }
@@ -129,7 +126,7 @@ class NativeQueryBuilder {
129
126
  return;
130
127
  }
131
128
  this.parts.push('on conflict');
132
- if (clause.fields instanceof core_1.RawQueryFragment) {
129
+ if (clause.fields instanceof RawQueryFragment) {
133
130
  this.parts.push(clause.fields.sql);
134
131
  this.params.push(...clause.fields.params);
135
132
  }
@@ -140,7 +137,7 @@ class NativeQueryBuilder {
140
137
  if (clause.ignore) {
141
138
  this.parts.push('do nothing');
142
139
  }
143
- if (core_1.Utils.isObject(clause.merge)) {
140
+ if (Utils.isObject(clause.merge)) {
144
141
  this.parts.push('do update set');
145
142
  const fields = Object.keys(clause.merge).map(field => {
146
143
  this.params.push(clause.merge[field]);
@@ -155,7 +152,7 @@ class NativeQueryBuilder {
155
152
  this.parts.push(fields.join(', '));
156
153
  }
157
154
  else {
158
- const dataAsArray = core_1.Utils.asArray(this.options.data);
155
+ const dataAsArray = Utils.asArray(this.options.data);
159
156
  const keys = Object.keys(dataAsArray[0]);
160
157
  const fields = keys.map(field => `${this.quote(field)} = excluded.${this.quote(field)}`);
161
158
  this.parts.push(fields.join(', '));
@@ -183,22 +180,22 @@ class NativeQueryBuilder {
183
180
  return this;
184
181
  }
185
182
  insert(data) {
186
- this.type = enums_1.QueryType.INSERT;
183
+ this.type = QueryType.INSERT;
187
184
  this.options.data = data;
188
185
  return this;
189
186
  }
190
187
  update(data) {
191
- this.type = enums_1.QueryType.UPDATE;
188
+ this.type = QueryType.UPDATE;
192
189
  this.options.data ??= {};
193
190
  Object.assign(this.options.data, data);
194
191
  return this;
195
192
  }
196
193
  delete() {
197
- this.type = enums_1.QueryType.DELETE;
194
+ this.type = QueryType.DELETE;
198
195
  return this;
199
196
  }
200
197
  truncate() {
201
- this.type = enums_1.QueryType.TRUNCATE;
198
+ this.type = QueryType.TRUNCATE;
202
199
  return this;
203
200
  }
204
201
  distinct() {
@@ -224,12 +221,12 @@ class NativeQueryBuilder {
224
221
  }
225
222
  comment(comment) {
226
223
  this.options.comment ??= [];
227
- this.options.comment.push(...core_1.Utils.asArray(comment));
224
+ this.options.comment.push(...Utils.asArray(comment));
228
225
  return this;
229
226
  }
230
227
  hintComment(comment) {
231
228
  this.options.hintComment ??= [];
232
- this.options.hintComment.push(...core_1.Utils.asArray(comment));
229
+ this.options.hintComment.push(...Utils.asArray(comment));
233
230
  return this;
234
231
  }
235
232
  setFlags(flags) {
@@ -250,7 +247,7 @@ class NativeQueryBuilder {
250
247
  }
251
248
  toRaw() {
252
249
  const { sql, params } = this.compile();
253
- return (0, core_1.raw)(sql, params);
250
+ return raw(sql, params);
254
251
  }
255
252
  compileSelect() {
256
253
  this.parts.push('select');
@@ -297,7 +294,7 @@ class NativeQueryBuilder {
297
294
  else if (this.options.distinctOn) {
298
295
  fields = `distinct on (${this.options.distinctOn.map(field => this.quote(field)).join(', ')}) ${fields}`;
299
296
  }
300
- if (this.type === enums_1.QueryType.COUNT) {
297
+ if (this.type === QueryType.COUNT) {
301
298
  fields = `count(${fields}) as ${this.quote('count')}`;
302
299
  }
303
300
  return fields;
@@ -324,7 +321,7 @@ class NativeQueryBuilder {
324
321
  }
325
322
  }
326
323
  processInsertData() {
327
- const dataAsArray = core_1.Utils.asArray(this.options.data);
324
+ const dataAsArray = Utils.asArray(this.options.data);
328
325
  const keys = Object.keys(dataAsArray[0]);
329
326
  const values = keys.map(() => '?');
330
327
  const parts = [];
@@ -334,7 +331,7 @@ class NativeQueryBuilder {
334
331
  for (const data of dataAsArray) {
335
332
  for (const key of keys) {
336
333
  if (typeof data[key] === 'undefined') {
337
- this.params.push(this.platform.usesDefaultKeyword() ? (0, core_1.raw)('default') : null);
334
+ this.params.push(this.platform.usesDefaultKeyword() ? raw('default') : null);
338
335
  }
339
336
  else {
340
337
  this.params.push(data[key]);
@@ -396,14 +393,14 @@ class NativeQueryBuilder {
396
393
  throw new Error('No table name provided');
397
394
  }
398
395
  const indexHint = this.options.indexHint ? ' ' + this.options.indexHint : '';
399
- if (this.options.tableName instanceof core_1.RawQueryFragment) {
396
+ if (this.options.tableName instanceof RawQueryFragment) {
400
397
  this.params.push(...this.options.tableName.params);
401
398
  return this.options.tableName.sql + indexHint;
402
399
  }
403
400
  return this.options.tableName + indexHint;
404
401
  }
405
402
  quote(id) {
406
- if (id instanceof core_1.RawQueryFragment) {
403
+ if (id instanceof RawQueryFragment) {
407
404
  return this.platform.formatQuery(id.sql, id.params);
408
405
  }
409
406
  if (id instanceof NativeQueryBuilder) {
@@ -426,4 +423,3 @@ class NativeQueryBuilder {
426
423
  return this.platform.quoteIdentifier(id);
427
424
  }
428
425
  }
429
- exports.NativeQueryBuilder = NativeQueryBuilder;
@@ -1,5 +1,5 @@
1
- import { CriteriaNode } from './CriteriaNode';
2
- import type { ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings';
1
+ import { CriteriaNode } from './CriteriaNode.js';
2
+ import type { ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings.js';
3
3
  /**
4
4
  * @internal
5
5
  */