@mikro-orm/knex 6.0.0-dev.98 → 6.0.0-dev.99
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.
- package/AbstractSqlConnection.js +2 -1
- package/AbstractSqlDriver.js +4 -1
- package/AbstractSqlPlatform.js +1 -0
- package/SqlEntityRepository.js +1 -0
- package/package.json +2 -2
- package/query/CriteriaNode.js +7 -0
- package/query/QueryBuilder.d.ts +2 -1
- package/query/QueryBuilder.js +46 -18
- package/query/QueryBuilderHelper.js +10 -1
- package/schema/DatabaseSchema.js +5 -3
- package/schema/DatabaseTable.js +9 -5
- package/schema/SchemaComparator.js +3 -0
- package/schema/SchemaHelper.js +1 -0
- package/schema/SqlSchemaGenerator.js +3 -5
package/AbstractSqlConnection.js
CHANGED
|
@@ -10,7 +10,8 @@ function isRootTransaction(trx) {
|
|
|
10
10
|
return !Object.getOwnPropertySymbols(trx).includes(parentTransactionSymbol);
|
|
11
11
|
}
|
|
12
12
|
class AbstractSqlConnection extends core_1.Connection {
|
|
13
|
-
static
|
|
13
|
+
static __patched = false;
|
|
14
|
+
client;
|
|
14
15
|
constructor(config, options, type) {
|
|
15
16
|
super(config, options, type);
|
|
16
17
|
this.patchKnexClient();
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -5,9 +5,12 @@ const core_1 = require("@mikro-orm/core");
|
|
|
5
5
|
const query_1 = require("./query");
|
|
6
6
|
const SqlEntityManager_1 = require("./SqlEntityManager");
|
|
7
7
|
class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
8
|
+
[core_1.EntityManagerType];
|
|
9
|
+
connection;
|
|
10
|
+
replicas = [];
|
|
11
|
+
platform;
|
|
8
12
|
constructor(config, platform, connection, connector) {
|
|
9
13
|
super(config, connector);
|
|
10
|
-
this.replicas = [];
|
|
11
14
|
this.connection = new connection(this.config);
|
|
12
15
|
this.replicas = this.createReplicas(conf => new connection(this.config, conf, 'read'));
|
|
13
16
|
this.platform = platform;
|
package/AbstractSqlPlatform.js
CHANGED
package/SqlEntityRepository.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SqlEntityRepository = void 0;
|
|
4
4
|
const core_1 = require("@mikro-orm/core");
|
|
5
5
|
class SqlEntityRepository extends core_1.EntityRepository {
|
|
6
|
+
em;
|
|
6
7
|
constructor(em, entityName) {
|
|
7
8
|
super(em, entityName);
|
|
8
9
|
this.em = em;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.99",
|
|
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.8.1"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "~6.0.0-dev.99"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/query/CriteriaNode.js
CHANGED
|
@@ -9,6 +9,13 @@ const core_1 = require("@mikro-orm/core");
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
class CriteriaNode {
|
|
12
|
+
metadata;
|
|
13
|
+
entityName;
|
|
14
|
+
parent;
|
|
15
|
+
key;
|
|
16
|
+
payload;
|
|
17
|
+
prop;
|
|
18
|
+
index;
|
|
12
19
|
constructor(metadata, entityName, parent, key, validate = true) {
|
|
13
20
|
this.metadata = metadata;
|
|
14
21
|
this.entityName = entityName;
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { AbstractSqlDriver } from '../AbstractSqlDriver';
|
|
|
7
7
|
import { QueryBuilderHelper, type Alias } from './QueryBuilderHelper';
|
|
8
8
|
import type { SqlEntityManager } from '../SqlEntityManager';
|
|
9
9
|
import type { Field } from '../typings';
|
|
10
|
+
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
10
11
|
/**
|
|
11
12
|
* SQL query builder with fluent interface.
|
|
12
13
|
*
|
|
@@ -80,7 +81,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
80
81
|
/**
|
|
81
82
|
* @internal
|
|
82
83
|
*/
|
|
83
|
-
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection,
|
|
84
|
+
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, AbstractSqlPlatform>> | undefined, logging?: LoggingOptions | undefined);
|
|
84
85
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
85
86
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
86
87
|
distinct(): SelectQueryBuilder<T>;
|
package/query/QueryBuilder.js
CHANGED
|
@@ -26,6 +26,12 @@ const CriteriaNodeFactory_1 = require("./CriteriaNodeFactory");
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
class QueryBuilder {
|
|
29
|
+
metadata;
|
|
30
|
+
driver;
|
|
31
|
+
context;
|
|
32
|
+
connectionType;
|
|
33
|
+
em;
|
|
34
|
+
logging;
|
|
29
35
|
get mainAlias() {
|
|
30
36
|
this.ensureFromClause();
|
|
31
37
|
return this._mainAlias;
|
|
@@ -37,6 +43,46 @@ class QueryBuilder {
|
|
|
37
43
|
this.ensureFromClause();
|
|
38
44
|
return this._helper;
|
|
39
45
|
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
type;
|
|
48
|
+
/** @internal */
|
|
49
|
+
_fields;
|
|
50
|
+
/** @internal */
|
|
51
|
+
_populate = [];
|
|
52
|
+
/** @internal */
|
|
53
|
+
_populateWhere;
|
|
54
|
+
/** @internal */
|
|
55
|
+
_populateMap = {};
|
|
56
|
+
aliasCounter = 0;
|
|
57
|
+
flags = new Set([core_1.QueryFlag.CONVERT_CUSTOM_TYPES]);
|
|
58
|
+
finalized = false;
|
|
59
|
+
_joins = {};
|
|
60
|
+
_explicitAlias = false;
|
|
61
|
+
_schema;
|
|
62
|
+
_cond = {};
|
|
63
|
+
_data;
|
|
64
|
+
_orderBy = [];
|
|
65
|
+
_groupBy = [];
|
|
66
|
+
_having = {};
|
|
67
|
+
_returning;
|
|
68
|
+
_onConflict;
|
|
69
|
+
_limit;
|
|
70
|
+
_offset;
|
|
71
|
+
_distinctOn;
|
|
72
|
+
_joinedProps = new Map();
|
|
73
|
+
_cache;
|
|
74
|
+
_indexHint;
|
|
75
|
+
_comments = [];
|
|
76
|
+
_hintComments = [];
|
|
77
|
+
flushMode;
|
|
78
|
+
lockMode;
|
|
79
|
+
lockTables;
|
|
80
|
+
subQueries = {};
|
|
81
|
+
_mainAlias;
|
|
82
|
+
_aliases = {};
|
|
83
|
+
_helper;
|
|
84
|
+
platform;
|
|
85
|
+
knex;
|
|
40
86
|
/**
|
|
41
87
|
* @internal
|
|
42
88
|
*/
|
|
@@ -47,24 +93,6 @@ class QueryBuilder {
|
|
|
47
93
|
this.connectionType = connectionType;
|
|
48
94
|
this.em = em;
|
|
49
95
|
this.logging = logging;
|
|
50
|
-
/** @internal */
|
|
51
|
-
this._populate = [];
|
|
52
|
-
/** @internal */
|
|
53
|
-
this._populateMap = {};
|
|
54
|
-
this.aliasCounter = 0;
|
|
55
|
-
this.flags = new Set([core_1.QueryFlag.CONVERT_CUSTOM_TYPES]);
|
|
56
|
-
this.finalized = false;
|
|
57
|
-
this._joins = {};
|
|
58
|
-
this._explicitAlias = false;
|
|
59
|
-
this._cond = {};
|
|
60
|
-
this._orderBy = [];
|
|
61
|
-
this._groupBy = [];
|
|
62
|
-
this._having = {};
|
|
63
|
-
this._joinedProps = new Map();
|
|
64
|
-
this._comments = [];
|
|
65
|
-
this._hintComments = [];
|
|
66
|
-
this.subQueries = {};
|
|
67
|
-
this._aliases = {};
|
|
68
96
|
this.platform = this.driver.getPlatform();
|
|
69
97
|
this.knex = this.driver.getConnection(this.connectionType).getKnex();
|
|
70
98
|
if (alias) {
|
|
@@ -8,6 +8,14 @@ const enums_1 = require("./enums");
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
class QueryBuilderHelper {
|
|
11
|
+
entityName;
|
|
12
|
+
alias;
|
|
13
|
+
aliasMap;
|
|
14
|
+
subQueries;
|
|
15
|
+
knex;
|
|
16
|
+
driver;
|
|
17
|
+
platform;
|
|
18
|
+
metadata;
|
|
11
19
|
constructor(entityName, alias, aliasMap, subQueries, knex, driver) {
|
|
12
20
|
this.entityName = entityName;
|
|
13
21
|
this.alias = alias;
|
|
@@ -374,7 +382,8 @@ class QueryBuilderHelper {
|
|
|
374
382
|
const replacement = this.getOperatorReplacement(op, value);
|
|
375
383
|
const fields = core_1.Utils.splitPrimaryKeys(key);
|
|
376
384
|
if (fields.length > 1 && Array.isArray(value[op]) && !value[op].every((v) => Array.isArray(v))) {
|
|
377
|
-
value[op]
|
|
385
|
+
const tmp = value[op].length === 1 && core_1.Utils.isPlainObject(value[op][0]) ? fields.map(f => value[op][0][f]) : value[op];
|
|
386
|
+
value[op] = this.knex.raw(`(${fields.map(() => '?').join(', ')})`, tmp);
|
|
378
387
|
}
|
|
379
388
|
if (this.subQueries[key]) {
|
|
380
389
|
return void qb[m](this.knex.raw(`(${this.subQueries[key]})`), replacement, value[op]);
|
package/schema/DatabaseSchema.js
CHANGED
|
@@ -7,12 +7,14 @@ const DatabaseTable_1 = require("./DatabaseTable");
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
class DatabaseSchema {
|
|
10
|
+
platform;
|
|
11
|
+
name;
|
|
12
|
+
tables = [];
|
|
13
|
+
namespaces = new Set();
|
|
14
|
+
nativeEnums = {}; // for postgres
|
|
10
15
|
constructor(platform, name) {
|
|
11
16
|
this.platform = platform;
|
|
12
17
|
this.name = name;
|
|
13
|
-
this.tables = [];
|
|
14
|
-
this.namespaces = new Set();
|
|
15
|
-
this.nativeEnums = {}; // for postgres
|
|
16
18
|
}
|
|
17
19
|
addTable(name, schema, comment) {
|
|
18
20
|
const namespaceName = schema ?? this.name;
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -6,15 +6,19 @@ const core_1 = require("@mikro-orm/core");
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
class DatabaseTable {
|
|
9
|
+
platform;
|
|
10
|
+
name;
|
|
11
|
+
schema;
|
|
12
|
+
columns = {};
|
|
13
|
+
indexes = [];
|
|
14
|
+
checks = [];
|
|
15
|
+
foreignKeys = {};
|
|
16
|
+
nativeEnums = {}; // for postgres
|
|
17
|
+
comment;
|
|
9
18
|
constructor(platform, name, schema) {
|
|
10
19
|
this.platform = platform;
|
|
11
20
|
this.name = name;
|
|
12
21
|
this.schema = schema;
|
|
13
|
-
this.columns = {};
|
|
14
|
-
this.indexes = [];
|
|
15
|
-
this.checks = [];
|
|
16
|
-
this.foreignKeys = {};
|
|
17
|
-
this.nativeEnums = {}; // for postgres
|
|
18
22
|
Object.defineProperties(this, {
|
|
19
23
|
platform: { enumerable: false, writable: true },
|
|
20
24
|
});
|
|
@@ -7,6 +7,9 @@ const core_1 = require("@mikro-orm/core");
|
|
|
7
7
|
* Compares two Schemas and return an instance of SchemaDifference.
|
|
8
8
|
*/
|
|
9
9
|
class SchemaComparator {
|
|
10
|
+
platform;
|
|
11
|
+
helper;
|
|
12
|
+
logger;
|
|
10
13
|
constructor(platform) {
|
|
11
14
|
this.platform = platform;
|
|
12
15
|
this.helper = this.platform.getSchemaHelper();
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -5,11 +5,9 @@ const core_1 = require("@mikro-orm/core");
|
|
|
5
5
|
const DatabaseSchema_1 = require("./DatabaseSchema");
|
|
6
6
|
const SchemaComparator_1 = require("./SchemaComparator");
|
|
7
7
|
class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.options = this.config.get('schemaGenerator');
|
|
12
|
-
}
|
|
8
|
+
helper = this.platform.getSchemaHelper();
|
|
9
|
+
options = this.config.get('schemaGenerator');
|
|
10
|
+
lastEnsuredDatabase;
|
|
13
11
|
static register(orm) {
|
|
14
12
|
orm.config.registerExtension('@mikro-orm/schema-generator', () => new SqlSchemaGenerator(orm.em));
|
|
15
13
|
}
|