@mikro-orm/sql 7.0.0-rc.1 → 7.0.0-rc.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.
- package/SqlEntityManager.d.ts +3 -2
- package/dialects/sqlite/BaseSqliteConnection.d.ts +4 -1
- package/dialects/sqlite/BaseSqliteConnection.js +4 -0
- package/dialects/sqlite/NodeSqliteDialect.d.ts +21 -0
- package/dialects/sqlite/NodeSqliteDialect.js +41 -0
- package/dialects/sqlite/SqliteDriver.d.ts +12 -0
- package/dialects/sqlite/SqliteDriver.js +14 -0
- package/dialects/sqlite/{BaseSqlitePlatform.d.ts → SqlitePlatform.d.ts} +5 -2
- package/dialects/sqlite/{BaseSqlitePlatform.js → SqlitePlatform.js} +27 -4
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +5 -0
- package/dialects/sqlite/SqliteSchemaHelper.js +20 -1
- package/dialects/sqlite/index.d.ts +3 -1
- package/dialects/sqlite/index.js +3 -1
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +30 -4
- package/schema/SqlSchemaGenerator.d.ts +2 -1
- package/schema/SqlSchemaGenerator.js +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/typings.d.ts +10 -1
package/SqlEntityManager.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
|
4
4
|
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
5
5
|
import type { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
6
6
|
import type { Kysely } from 'kysely';
|
|
7
|
-
import type { InferKyselyDB } from './typings.js';
|
|
7
|
+
import type { InferClassEntityDB, InferKyselyDB } from './typings.js';
|
|
8
8
|
import { type MikroKyselyPluginOptions } from './plugin/index.js';
|
|
9
9
|
export interface GetKyselyOptions extends MikroKyselyPluginOptions {
|
|
10
10
|
type?: ConnectionType;
|
|
@@ -24,10 +24,11 @@ export declare class SqlEntityManager<Driver extends AbstractSqlDriver = Abstrac
|
|
|
24
24
|
/**
|
|
25
25
|
* Returns configured Kysely instance.
|
|
26
26
|
*/
|
|
27
|
-
getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(options?: TOptions): Kysely<TDB extends undefined ? InferKyselyDB<EntitiesFromManager<this>, TOptions> : TDB>;
|
|
27
|
+
getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(options?: TOptions): Kysely<TDB extends undefined ? InferKyselyDB<EntitiesFromManager<this>, TOptions> & InferClassEntityDB<AllEntitiesFromManager<this>, TOptions> : TDB>;
|
|
28
28
|
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', loggerContext?: LoggingOptions): Promise<T>;
|
|
29
29
|
getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>;
|
|
30
30
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
31
31
|
}
|
|
32
32
|
type EntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? (Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta>) : never;
|
|
33
|
+
type AllEntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? NonNullable<TEntityManager['~entities']>[number] : never;
|
|
33
34
|
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { type Dialect } from 'kysely';
|
|
2
|
+
import type { Dictionary } from '@mikro-orm/core';
|
|
1
3
|
import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
|
|
2
|
-
export declare
|
|
4
|
+
export declare class BaseSqliteConnection extends AbstractSqlConnection {
|
|
5
|
+
createKyselyDialect(options: Dictionary): Dialect;
|
|
3
6
|
connect(options?: {
|
|
4
7
|
skipOnConnect?: boolean;
|
|
5
8
|
}): Promise<void>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { CompiledQuery } from 'kysely';
|
|
2
2
|
import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
|
|
3
3
|
export class BaseSqliteConnection extends AbstractSqlConnection {
|
|
4
|
+
createKyselyDialect(options) {
|
|
5
|
+
throw new Error('No SQLite dialect configured. Pass a Kysely dialect via the `driverOptions` config option, '
|
|
6
|
+
+ 'e.g. `new NodeSqliteDialect(...)` for node:sqlite or a custom dialect for other libraries.');
|
|
7
|
+
}
|
|
4
8
|
async connect(options) {
|
|
5
9
|
await super.connect(options);
|
|
6
10
|
await this.getClient().executeQuery(CompiledQuery.raw('pragma foreign_keys = on'));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SqliteDialect } from 'kysely';
|
|
2
|
+
/**
|
|
3
|
+
* Kysely dialect for `node:sqlite` (Node.js 22.5+, Deno 2.2+).
|
|
4
|
+
*
|
|
5
|
+
* Bridges `node:sqlite`'s `DatabaseSync` to the `better-sqlite3` interface
|
|
6
|
+
* that Kysely's `SqliteDialect` expects.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { SqliteDriver, NodeSqliteDialect } from '@mikro-orm/sql';
|
|
11
|
+
*
|
|
12
|
+
* const orm = await MikroORM.init({
|
|
13
|
+
* driver: SqliteDriver,
|
|
14
|
+
* dbName: ':memory:',
|
|
15
|
+
* driverOptions: new NodeSqliteDialect(':memory:'),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class NodeSqliteDialect extends SqliteDialect {
|
|
20
|
+
constructor(dbName: string);
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SqliteDialect } from 'kysely';
|
|
2
|
+
/**
|
|
3
|
+
* Kysely dialect for `node:sqlite` (Node.js 22.5+, Deno 2.2+).
|
|
4
|
+
*
|
|
5
|
+
* Bridges `node:sqlite`'s `DatabaseSync` to the `better-sqlite3` interface
|
|
6
|
+
* that Kysely's `SqliteDialect` expects.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { SqliteDriver, NodeSqliteDialect } from '@mikro-orm/sql';
|
|
11
|
+
*
|
|
12
|
+
* const orm = await MikroORM.init({
|
|
13
|
+
* driver: SqliteDriver,
|
|
14
|
+
* dbName: ':memory:',
|
|
15
|
+
* driverOptions: new NodeSqliteDialect(':memory:'),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class NodeSqliteDialect extends SqliteDialect {
|
|
20
|
+
constructor(dbName) {
|
|
21
|
+
const { DatabaseSync } = globalThis.process.getBuiltinModule('node:sqlite');
|
|
22
|
+
super({
|
|
23
|
+
database: () => {
|
|
24
|
+
const db = new DatabaseSync(dbName);
|
|
25
|
+
return {
|
|
26
|
+
prepare(sql) {
|
|
27
|
+
const stmt = db.prepare(sql);
|
|
28
|
+
return {
|
|
29
|
+
reader: /^\s*(select|pragma|explain|with)/i.test(sql) || /\breturning\b/i.test(sql),
|
|
30
|
+
all: (params) => stmt.all(...params),
|
|
31
|
+
run: (params) => stmt.run(...params),
|
|
32
|
+
/* v8 ignore next */
|
|
33
|
+
get: (params) => stmt.get(...params),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
close() { db.close(); },
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Configuration } from '@mikro-orm/core';
|
|
2
|
+
import { AbstractSqlDriver } from '../../AbstractSqlDriver.js';
|
|
3
|
+
import { BaseSqliteConnection } from './BaseSqliteConnection.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generic SQLite driver that uses `driverOptions` for the Kysely dialect.
|
|
6
|
+
* Use this with any SQLite library by passing a Kysely dialect via `driverOptions`.
|
|
7
|
+
*
|
|
8
|
+
* For the default better-sqlite3 experience, use `@mikro-orm/sqlite` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SqliteDriver extends AbstractSqlDriver<BaseSqliteConnection> {
|
|
11
|
+
constructor(config: Configuration);
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractSqlDriver } from '../../AbstractSqlDriver.js';
|
|
2
|
+
import { BaseSqliteConnection } from './BaseSqliteConnection.js';
|
|
3
|
+
import { SqlitePlatform } from './SqlitePlatform.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generic SQLite driver that uses `driverOptions` for the Kysely dialect.
|
|
6
|
+
* Use this with any SQLite library by passing a Kysely dialect via `driverOptions`.
|
|
7
|
+
*
|
|
8
|
+
* For the default better-sqlite3 experience, use `@mikro-orm/sqlite` instead.
|
|
9
|
+
*/
|
|
10
|
+
export class SqliteDriver extends AbstractSqlDriver {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config, new SqlitePlatform(), BaseSqliteConnection, ['kysely']);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -3,7 +3,7 @@ import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
|
|
|
3
3
|
import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
|
|
4
4
|
import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
|
|
5
5
|
import { SqliteExceptionConverter } from './SqliteExceptionConverter.js';
|
|
6
|
-
export declare
|
|
6
|
+
export declare class SqlitePlatform extends AbstractSqlPlatform {
|
|
7
7
|
protected readonly schemaHelper: SqliteSchemaHelper;
|
|
8
8
|
protected readonly exceptionConverter: SqliteExceptionConverter;
|
|
9
9
|
/** @internal */
|
|
@@ -71,6 +71,9 @@ export declare abstract class BaseSqlitePlatform extends AbstractSqlPlatform {
|
|
|
71
71
|
supportsSchemas(): boolean;
|
|
72
72
|
getDefaultSchemaName(): string | undefined;
|
|
73
73
|
getFullTextWhereClause(): string;
|
|
74
|
-
|
|
74
|
+
escape(value: any): string;
|
|
75
|
+
convertVersionValue(value: Date | number, prop: EntityProperty): number | {
|
|
76
|
+
$in: (string | number)[];
|
|
77
|
+
};
|
|
75
78
|
quoteValue(value: any): string;
|
|
76
79
|
}
|
|
@@ -2,7 +2,7 @@ import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
|
|
|
2
2
|
import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
|
|
3
3
|
import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
|
|
4
4
|
import { SqliteExceptionConverter } from './SqliteExceptionConverter.js';
|
|
5
|
-
export class
|
|
5
|
+
export class SqlitePlatform extends AbstractSqlPlatform {
|
|
6
6
|
schemaHelper = new SqliteSchemaHelper(this);
|
|
7
7
|
exceptionConverter = new SqliteExceptionConverter();
|
|
8
8
|
/** @internal */
|
|
@@ -19,7 +19,7 @@ export class BaseSqlitePlatform extends AbstractSqlPlatform {
|
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
getCurrentTimestampSQL(length) {
|
|
22
|
-
return
|
|
22
|
+
return `(strftime('%s', 'now') * 1000)`;
|
|
23
23
|
}
|
|
24
24
|
getDateTimeTypeDeclarationSQL(column) {
|
|
25
25
|
return 'datetime';
|
|
@@ -101,9 +101,32 @@ export class BaseSqlitePlatform extends AbstractSqlPlatform {
|
|
|
101
101
|
getFullTextWhereClause() {
|
|
102
102
|
return `:column: match :query`;
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
escape(value) {
|
|
105
|
+
if (value == null) {
|
|
106
|
+
return 'null';
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === 'boolean') {
|
|
109
|
+
return value ? 'true' : 'false';
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
112
|
+
return '' + value;
|
|
113
|
+
}
|
|
114
|
+
if (value instanceof Date) {
|
|
115
|
+
return '' + +value;
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
return value.map(v => this.escape(v)).join(', ');
|
|
119
|
+
}
|
|
120
|
+
if (Buffer.isBuffer(value)) {
|
|
121
|
+
return `X'${value.toString('hex')}'`;
|
|
122
|
+
}
|
|
123
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
124
|
+
}
|
|
125
|
+
convertVersionValue(value, prop) {
|
|
105
126
|
if (prop.runtimeType === 'Date') {
|
|
106
|
-
|
|
127
|
+
const ts = +value;
|
|
128
|
+
const str = new Date(ts).toISOString().replace('T', ' ').replace(/\.\d{3}Z$/, '');
|
|
129
|
+
return { $in: [ts, str] };
|
|
107
130
|
}
|
|
108
131
|
return value;
|
|
109
132
|
}
|
|
@@ -39,6 +39,11 @@ export declare class SqliteSchemaHelper extends SchemaHelper {
|
|
|
39
39
|
*/
|
|
40
40
|
private extractViewDefinition;
|
|
41
41
|
private getColumns;
|
|
42
|
+
/**
|
|
43
|
+
* SQLite strips outer parentheses from expression defaults (`DEFAULT (expr)` → `expr` in pragma).
|
|
44
|
+
* We need to add them back so they match what we generate in DDL.
|
|
45
|
+
*/
|
|
46
|
+
private wrapExpressionDefault;
|
|
42
47
|
private getEnumDefinitions;
|
|
43
48
|
getPrimaryKeys(connection: AbstractSqlConnection, indexes: IndexDef[], tableName: string, schemaName?: string): Promise<string[]>;
|
|
44
49
|
private getIndexes;
|
|
@@ -286,7 +286,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
286
286
|
return {
|
|
287
287
|
name: col.name,
|
|
288
288
|
type: col.type,
|
|
289
|
-
default: col.dflt_value,
|
|
289
|
+
default: this.wrapExpressionDefault(col.dflt_value),
|
|
290
290
|
nullable: !col.notnull,
|
|
291
291
|
primary: !!col.pk,
|
|
292
292
|
mappedType,
|
|
@@ -296,6 +296,25 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
296
296
|
};
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* SQLite strips outer parentheses from expression defaults (`DEFAULT (expr)` → `expr` in pragma).
|
|
301
|
+
* We need to add them back so they match what we generate in DDL.
|
|
302
|
+
*/
|
|
303
|
+
wrapExpressionDefault(value) {
|
|
304
|
+
if (value == null) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
// simple values that are returned as-is from pragma (no wrapping needed)
|
|
308
|
+
if (/^-?\d/.test(value) || /^[xX]'/.test(value) || value[0] === "'" || value[0] === '"' || value[0] === '(') {
|
|
309
|
+
return value;
|
|
310
|
+
}
|
|
311
|
+
const lower = value.toLowerCase();
|
|
312
|
+
if (['null', 'true', 'false', 'current_timestamp', 'current_date', 'current_time'].includes(lower)) {
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
// everything else is an expression that had its outer parens stripped
|
|
316
|
+
return `(${value})`;
|
|
317
|
+
}
|
|
299
318
|
async getEnumDefinitions(connection, tableName, schemaName) {
|
|
300
319
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
301
320
|
const sql = `select sql from ${prefix}sqlite_master where type = ? and name = ?`;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './BaseSqliteConnection.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './NodeSqliteDialect.js';
|
|
3
|
+
export * from './SqliteDriver.js';
|
|
4
|
+
export * from './SqlitePlatform.js';
|
|
3
5
|
export * from './SqliteSchemaHelper.js';
|
|
4
6
|
export * from './SqliteNativeQueryBuilder.js';
|
package/dialects/sqlite/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './BaseSqliteConnection.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './NodeSqliteDialect.js';
|
|
3
|
+
export * from './SqliteDriver.js';
|
|
4
|
+
export * from './SqlitePlatform.js';
|
|
3
5
|
export * from './SqliteSchemaHelper.js';
|
|
4
6
|
export * from './SqliteNativeQueryBuilder.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.2",
|
|
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
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"@mikro-orm/core": "^6.6.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.0.0-rc.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-rc.2"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyEntity, type AutoPath, type ConnectionType, type Dictionary, type EntityData, type EntityKey, type EntityManager, type EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterObject, type FilterOptions, type FilterValue, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type PopulatePath, QueryFlag, type QueryOrderKeysFlat, type QueryOrderMap, type QueryResult, RawQueryFragment, type Raw, type RequiredEntityData, type Scalar, type Subquery, type Transaction } from '@mikro-orm/core';
|
|
1
|
+
import { type AnyEntity, type AutoPath, type Collection, type ConnectionType, type Dictionary, type EntityData, type EntityDTOFlat, type EntityDTOProp, type EntityKey, type EntityManager, type EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterObject, type FilterOptions, type FilterValue, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type PrimaryProperty, type ObjectQuery, PopulateHint, type PopulateOptions, type PopulatePath, QueryFlag, type QueryOrderKeysFlat, type QueryOrderMap, type QueryResult, RawQueryFragment, type Raw, type RequiredEntityData, type Scalar, type SerializeDTO, type Subquery, type Transaction } from '@mikro-orm/core';
|
|
2
2
|
import { JoinType, QueryType } from './enums.js';
|
|
3
3
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver.js';
|
|
4
4
|
import { type Alias, type OnConflictClause, QueryBuilderHelper } from './QueryBuilderHelper.js';
|
|
@@ -848,10 +848,36 @@ export interface RunQueryBuilder<Entity extends object, RootAlias extends string
|
|
|
848
848
|
where(cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|
|
849
849
|
execute<Result = QueryResult<Entity>>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
850
850
|
}
|
|
851
|
+
/**
|
|
852
|
+
* @internal Optimized DTO type for execute().
|
|
853
|
+
* Bypasses the double mapped type of EntityDTO<Loaded<T, H, F>> by using DirectDTO
|
|
854
|
+
* which only iterates selected keys instead of all entity keys.
|
|
855
|
+
*
|
|
856
|
+
* - Wildcard, no joins: EntityDTO<T>
|
|
857
|
+
* - Selected fields, no joins: DirectDTO<T, F> (~132x faster than Pick<EntityDTO<T>, F>)
|
|
858
|
+
* - Wildcard + single-level join: Omit<EntityDTO<T>> + override populated relations
|
|
859
|
+
* - Selected fields + single-level join: DirectDTO for root + DirectDTO for joined (~60x faster)
|
|
860
|
+
* - Wildcard + nested joins: uses SerializeDTO<T, H> (~40x faster than EntityDTO<Loaded<T, H>>)
|
|
861
|
+
* - Fields + nested joins: falls back to EntityDTO<Loaded<T, H, F>>
|
|
862
|
+
*/
|
|
863
|
+
type DirectDTO<T, F extends keyof T> = {
|
|
864
|
+
[K in F]: EntityDTOProp<T, NonNullable<T[K]>> | Extract<T[K], null | undefined>;
|
|
865
|
+
};
|
|
866
|
+
type PopulatedDTO<T, K extends keyof T> = NonNullable<T[K]> extends Collection<infer U> ? EntityDTOFlat<U & object>[] : EntityDTOFlat<ExpandProperty<T[K]>>;
|
|
867
|
+
type SubFields<F extends string, Rel extends string> = F extends `${Rel}.${infer Sub}` ? Sub : never;
|
|
868
|
+
type RootFields<F extends string, H extends string> = F extends `${string}.${string}` ? F extends `${H}.${string}` ? never : F : F;
|
|
869
|
+
type JoinDTO<T, K extends keyof T, F extends string> = NonNullable<T[K]> extends Collection<infer U> ? SubFields<F, K & string> extends never ? EntityDTOProp<T, Collection<U>> : DirectDTO<U, (SubFields<F, K & string> | PrimaryProperty<U>) & keyof U>[] : SubFields<F, K & string> extends never ? EntityDTOProp<T, T[K]> : DirectDTO<NonNullable<T[K]>, (SubFields<F, K & string> | PrimaryProperty<NonNullable<T[K]>>) & keyof NonNullable<T[K]>> | Extract<T[K], null | undefined>;
|
|
870
|
+
type ExecuteDTO<T, H extends string, F extends string> = [
|
|
871
|
+
H
|
|
872
|
+
] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
|
|
873
|
+
[K in H & keyof T as K & keyof EntityDTOFlat<T>]: PopulatedDTO<T, K> | Extract<T[K], null | undefined>;
|
|
874
|
+
} : true extends (H extends `${string}.${string}` ? true : false) ? EntityDTOFlat<Loaded<T, H, F>> : DirectDTO<T, (RootFields<F, H> | PrimaryProperty<T>) & keyof T> & {
|
|
875
|
+
[K in H & keyof T]: JoinDTO<T, K, F>;
|
|
876
|
+
};
|
|
851
877
|
export interface SelectQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never, RawAliases extends string = never, Fields extends string = '*'> extends QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields> {
|
|
852
|
-
execute<Result = Entity[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
853
|
-
execute<Result = Entity[]>(method: 'all', mapResults?: boolean): Promise<Result>;
|
|
854
|
-
execute<Result = Entity
|
|
878
|
+
execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
879
|
+
execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method: 'all', mapResults?: boolean): Promise<Result>;
|
|
880
|
+
execute<Result = ExecuteDTO<Entity, Hint, Fields>>(method: 'get', mapResults?: boolean): Promise<Result>;
|
|
855
881
|
execute<Result = QueryResult<Entity>>(method: 'run', mapResults?: boolean): Promise<Result>;
|
|
856
882
|
}
|
|
857
883
|
export interface CountQueryBuilder<Entity extends object> extends QueryBuilder<Entity, any, any> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ClearDatabaseOptions, type CreateSchemaOptions, type Dictionary, type DropSchemaOptions, type EnsureDatabaseOptions, type EntityMetadata, type ISchemaGenerator, type MikroORM, type Transaction, type UpdateSchemaOptions } from '@mikro-orm/core';
|
|
2
|
+
import { AbstractSchemaGenerator } from '@mikro-orm/core/schema';
|
|
2
3
|
import type { SchemaDifference } from '../typings.js';
|
|
3
4
|
import { DatabaseSchema } from './DatabaseSchema.js';
|
|
4
5
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommitOrderCalculator, Utils, } from '@mikro-orm/core';
|
|
2
|
+
import { AbstractSchemaGenerator } from '@mikro-orm/core/schema';
|
|
2
3
|
import { DatabaseSchema } from './DatabaseSchema.js';
|
|
3
4
|
import { SchemaComparator } from './SchemaComparator.js';
|
|
4
5
|
export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|