@mikro-orm/sql 7.0.0-rc.2 → 7.0.0
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.d.ts +5 -4
- package/AbstractSqlConnection.js +20 -6
- package/AbstractSqlDriver.d.ts +19 -13
- package/AbstractSqlDriver.js +225 -47
- package/AbstractSqlPlatform.d.ts +35 -0
- package/AbstractSqlPlatform.js +51 -5
- package/PivotCollectionPersister.d.ts +2 -11
- package/PivotCollectionPersister.js +59 -59
- package/README.md +5 -4
- package/SqlEntityManager.d.ts +2 -2
- package/SqlEntityManager.js +5 -5
- package/dialects/index.d.ts +1 -0
- package/dialects/index.js +1 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +2 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +8 -4
- package/dialects/mysql/BaseMySqlPlatform.d.ts +6 -0
- package/dialects/mysql/BaseMySqlPlatform.js +18 -2
- package/dialects/mysql/MySqlSchemaHelper.d.ts +1 -1
- package/dialects/mysql/MySqlSchemaHelper.js +25 -14
- package/dialects/oracledb/OracleDialect.d.ts +78 -0
- package/dialects/oracledb/OracleDialect.js +166 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +19 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.js +249 -0
- package/dialects/oracledb/index.d.ts +2 -0
- package/dialects/oracledb/index.js +2 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +6 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.js +49 -37
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +75 -59
- package/dialects/sqlite/BaseSqliteConnection.js +2 -2
- package/dialects/sqlite/NodeSqliteDialect.js +3 -1
- package/dialects/sqlite/SqlitePlatform.d.ts +1 -0
- package/dialects/sqlite/SqlitePlatform.js +7 -1
- package/dialects/sqlite/SqliteSchemaHelper.js +23 -17
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/package.json +30 -30
- package/plugin/index.d.ts +1 -14
- package/plugin/index.js +13 -13
- package/plugin/transformer.d.ts +6 -22
- package/plugin/transformer.js +91 -82
- package/query/ArrayCriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +28 -10
- package/query/CriteriaNodeFactory.js +20 -4
- package/query/NativeQueryBuilder.d.ts +28 -3
- package/query/NativeQueryBuilder.js +65 -3
- package/query/ObjectCriteriaNode.js +75 -31
- package/query/QueryBuilder.d.ts +199 -100
- package/query/QueryBuilder.js +544 -358
- package/query/QueryBuilderHelper.d.ts +18 -14
- package/query/QueryBuilderHelper.js +364 -147
- package/query/ScalarCriteriaNode.js +17 -8
- package/query/enums.d.ts +2 -0
- package/query/enums.js +2 -0
- package/query/raw.js +1 -1
- package/schema/DatabaseSchema.d.ts +7 -5
- package/schema/DatabaseSchema.js +68 -45
- package/schema/DatabaseTable.d.ts +8 -6
- package/schema/DatabaseTable.js +191 -107
- package/schema/SchemaComparator.d.ts +1 -3
- package/schema/SchemaComparator.js +76 -50
- package/schema/SchemaHelper.d.ts +2 -13
- package/schema/SchemaHelper.js +30 -9
- package/schema/SqlSchemaGenerator.d.ts +4 -14
- package/schema/SqlSchemaGenerator.js +26 -12
- package/typings.d.ts +10 -5
- package/tsconfig.build.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
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
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
"./package.json": "./package.json",
|
|
8
|
-
".": "./index.js"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
13
|
-
},
|
|
14
5
|
"keywords": [
|
|
15
|
-
"
|
|
6
|
+
"data-mapper",
|
|
7
|
+
"ddd",
|
|
8
|
+
"entity",
|
|
9
|
+
"identity-map",
|
|
10
|
+
"javascript",
|
|
11
|
+
"js",
|
|
12
|
+
"mariadb",
|
|
13
|
+
"mikro-orm",
|
|
16
14
|
"mongo",
|
|
17
15
|
"mongodb",
|
|
18
16
|
"mysql",
|
|
19
|
-
"
|
|
17
|
+
"orm",
|
|
20
18
|
"postgresql",
|
|
21
19
|
"sqlite",
|
|
22
20
|
"sqlite3",
|
|
23
21
|
"ts",
|
|
24
22
|
"typescript",
|
|
25
|
-
"
|
|
26
|
-
"javascript",
|
|
27
|
-
"entity",
|
|
28
|
-
"ddd",
|
|
29
|
-
"mikro-orm",
|
|
30
|
-
"unit-of-work",
|
|
31
|
-
"data-mapper",
|
|
32
|
-
"identity-map"
|
|
23
|
+
"unit-of-work"
|
|
33
24
|
],
|
|
34
|
-
"
|
|
35
|
-
"license": "MIT",
|
|
25
|
+
"homepage": "https://mikro-orm.io",
|
|
36
26
|
"bugs": {
|
|
37
27
|
"url": "https://github.com/mikro-orm/mikro-orm/issues"
|
|
38
28
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Martin Adámek",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": "./index.js"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "yarn compile && yarn copy",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
|
-
"publishConfig": {
|
|
50
|
-
"access": "public"
|
|
51
|
-
},
|
|
52
49
|
"dependencies": {
|
|
53
50
|
"kysely": "0.28.11"
|
|
54
51
|
},
|
|
55
52
|
"devDependencies": {
|
|
56
|
-
"@mikro-orm/core": "^
|
|
53
|
+
"@mikro-orm/core": "^7.0.0"
|
|
57
54
|
},
|
|
58
55
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "
|
|
56
|
+
"@mikro-orm/core": "^6.0.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">= 22.17.0"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/plugin/index.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { type KyselyPlugin, type PluginTransformQueryArgs, type PluginTransformResultArgs, type QueryResult, type RootOperationNode, type UnknownRow } from 'kysely';
|
|
2
|
-
import { MikroTransformer } from './transformer.js';
|
|
3
2
|
import type { SqlEntityManager } from '../SqlEntityManager.js';
|
|
4
|
-
import type { EntityMetadata } from '@mikro-orm/core';
|
|
5
|
-
/**
|
|
6
|
-
* Cache for query transformation data
|
|
7
|
-
* Stores the query node and metadata about tables/aliases
|
|
8
|
-
*/
|
|
9
|
-
interface QueryTransformCache {
|
|
10
|
-
entityMap: Map<string, EntityMetadata>;
|
|
11
|
-
}
|
|
12
3
|
export interface MikroKyselyPluginOptions {
|
|
13
4
|
/**
|
|
14
5
|
* Use database table names ('table') or entity names ('entity') in queries.
|
|
@@ -42,12 +33,8 @@ export interface MikroKyselyPluginOptions {
|
|
|
42
33
|
convertValues?: boolean;
|
|
43
34
|
}
|
|
44
35
|
export declare class MikroKyselyPlugin implements KyselyPlugin {
|
|
45
|
-
|
|
46
|
-
protected readonly options: MikroKyselyPluginOptions;
|
|
47
|
-
protected static queryNodeCache: WeakMap<any, QueryTransformCache>;
|
|
48
|
-
protected readonly transformer: MikroTransformer;
|
|
36
|
+
#private;
|
|
49
37
|
constructor(em: SqlEntityManager, options?: MikroKyselyPluginOptions);
|
|
50
38
|
transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
|
|
51
39
|
transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
|
|
52
40
|
}
|
|
53
|
-
export {};
|
package/plugin/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { SelectQueryNode as SelectQueryNodeClass, InsertQueryNode as InsertQueryNodeClass, UpdateQueryNode as UpdateQueryNodeClass, DeleteQueryNode as DeleteQueryNodeClass, } from 'kysely';
|
|
2
2
|
import { MikroTransformer } from './transformer.js';
|
|
3
3
|
export class MikroKyselyPlugin {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
transformer;
|
|
4
|
+
static #queryNodeCache = new WeakMap();
|
|
5
|
+
#transformer;
|
|
6
|
+
#options;
|
|
8
7
|
constructor(em, options = {}) {
|
|
9
|
-
this
|
|
10
|
-
this
|
|
11
|
-
this.transformer = new MikroTransformer(em, options);
|
|
8
|
+
this.#options = options;
|
|
9
|
+
this.#transformer = new MikroTransformer(em, options);
|
|
12
10
|
}
|
|
13
11
|
transformQuery(args) {
|
|
14
|
-
this
|
|
15
|
-
const result = this
|
|
12
|
+
this.#transformer.reset();
|
|
13
|
+
const result = this.#transformer.transformNode(args.node, args.queryId);
|
|
16
14
|
// Cache the entity map if it is one we can process (for use in transformResult)
|
|
17
15
|
if (SelectQueryNodeClass.is(args.node) ||
|
|
18
16
|
InsertQueryNodeClass.is(args.node) ||
|
|
19
17
|
UpdateQueryNodeClass.is(args.node) ||
|
|
20
18
|
DeleteQueryNodeClass.is(args.node)) {
|
|
21
|
-
|
|
19
|
+
// clone the entityMap because the transformer's internal map will be cleared and reused by the next query
|
|
20
|
+
const entityMap = new Map(this.#transformer.getOutputEntityMap());
|
|
21
|
+
MikroKyselyPlugin.#queryNodeCache.set(args.queryId, { entityMap });
|
|
22
22
|
}
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
async transformResult(args) {
|
|
26
26
|
// Only transform results if columnNamingStrategy is 'property' or convertValues is true
|
|
27
|
-
if (this
|
|
27
|
+
if (this.#options.columnNamingStrategy !== 'property' && !this.#options.convertValues) {
|
|
28
28
|
return args.result;
|
|
29
29
|
}
|
|
30
30
|
// Retrieve the cached query node and metadata
|
|
31
|
-
const cache = MikroKyselyPlugin
|
|
31
|
+
const cache = MikroKyselyPlugin.#queryNodeCache.get(args.queryId);
|
|
32
32
|
if (!cache) {
|
|
33
33
|
return args.result;
|
|
34
34
|
}
|
|
35
35
|
// Transform the result rows using the transformer
|
|
36
|
-
const transformedRows = this
|
|
36
|
+
const transformedRows = this.#transformer.transformResult(args.result.rows ?? [], cache.entityMap);
|
|
37
37
|
return {
|
|
38
38
|
...args.result,
|
|
39
39
|
rows: transformedRows ?? [],
|
package/plugin/transformer.d.ts
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
import { type EntityMetadata, type EntityProperty
|
|
1
|
+
import { type EntityMetadata, type EntityProperty } from '@mikro-orm/core';
|
|
2
2
|
import { type CommonTableExpressionNameNode, type DeleteQueryNode, type IdentifierNode, type InsertQueryNode, type JoinNode, type MergeQueryNode, type QueryId, type SelectQueryNode, type UpdateQueryNode, type WithNode, ColumnNode, OperationNodeTransformer, TableNode } from 'kysely';
|
|
3
3
|
import type { MikroKyselyPluginOptions } from './index.js';
|
|
4
4
|
import type { SqlEntityManager } from '../SqlEntityManager.js';
|
|
5
|
-
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
|
|
6
5
|
export declare class MikroTransformer extends OperationNodeTransformer {
|
|
7
|
-
|
|
8
|
-
protected readonly options: MikroKyselyPluginOptions;
|
|
9
|
-
/**
|
|
10
|
-
* Context stack to support nested queries (subqueries, CTEs)
|
|
11
|
-
* Each level of query scope has its own Map of table aliases/names to EntityMetadata
|
|
12
|
-
* Top of stack (highest index) is the current scope
|
|
13
|
-
*/
|
|
14
|
-
protected readonly contextStack: Map<string, EntityMetadata | undefined>[];
|
|
15
|
-
/**
|
|
16
|
-
* Subquery alias map: maps subquery/CTE alias to its source table metadata
|
|
17
|
-
* Used to resolve columns from subqueries/CTEs to their original table definitions
|
|
18
|
-
*/
|
|
19
|
-
protected readonly subqueryAliasMap: Map<string, EntityMetadata | undefined>;
|
|
20
|
-
protected readonly metadata: MetadataStorage;
|
|
21
|
-
protected readonly platform: AbstractSqlPlatform;
|
|
22
|
-
/**
|
|
23
|
-
* Global map of all entities involved in the query.
|
|
24
|
-
* Populated during AST transformation and used for result transformation.
|
|
25
|
-
*/
|
|
26
|
-
protected readonly entityMap: Map<string, EntityMetadata<any, import("@mikro-orm/core").EntityCtor<any>>>;
|
|
6
|
+
#private;
|
|
27
7
|
constructor(em: SqlEntityManager, options?: MikroKyselyPluginOptions);
|
|
28
8
|
reset(): void;
|
|
29
9
|
getOutputEntityMap(): Map<string, EntityMetadata>;
|
|
10
|
+
/** @internal */
|
|
11
|
+
getContextStack(): Map<string, EntityMetadata | undefined>[];
|
|
12
|
+
/** @internal */
|
|
13
|
+
getSubqueryAliasMap(): Map<string, EntityMetadata | undefined>;
|
|
30
14
|
transformSelectQuery(node: SelectQueryNode, queryId: QueryId): SelectQueryNode;
|
|
31
15
|
transformInsertQuery(node: InsertQueryNode, queryId?: QueryId): InsertQueryNode;
|
|
32
16
|
transformUpdateQuery(node: UpdateQueryNode, queryId?: QueryId): UpdateQueryNode;
|