@mikro-orm/sql 7.1.0-dev.8 → 7.1.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 +1 -1
- package/AbstractSqlConnection.js +27 -6
- package/AbstractSqlDriver.d.ts +15 -1
- package/AbstractSqlDriver.js +143 -26
- package/AbstractSqlPlatform.d.ts +15 -3
- package/AbstractSqlPlatform.js +25 -7
- package/PivotCollectionPersister.d.ts +2 -2
- package/PivotCollectionPersister.js +6 -1
- package/README.md +2 -1
- package/SqlEntityManager.d.ts +48 -5
- package/SqlEntityManager.js +77 -7
- package/SqlMikroORM.d.ts +23 -0
- package/SqlMikroORM.js +23 -0
- package/dialects/mysql/BaseMySqlPlatform.d.ts +3 -5
- package/dialects/mysql/BaseMySqlPlatform.js +6 -10
- package/dialects/mysql/MySqlSchemaHelper.d.ts +16 -3
- package/dialects/mysql/MySqlSchemaHelper.js +197 -49
- package/dialects/oracledb/OracleDialect.d.ts +1 -1
- package/dialects/oracledb/OracleDialect.js +2 -1
- package/dialects/postgresql/BasePostgreSqlEntityManager.d.ts +19 -0
- package/dialects/postgresql/BasePostgreSqlEntityManager.js +24 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +11 -5
- package/dialects/postgresql/BasePostgreSqlPlatform.js +75 -17
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +31 -1
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +269 -28
- package/dialects/postgresql/index.d.ts +2 -0
- package/dialects/postgresql/index.js +2 -0
- package/dialects/postgresql/typeOverrides.d.ts +14 -0
- package/dialects/postgresql/typeOverrides.js +12 -0
- package/dialects/sqlite/SqlitePlatform.d.ts +2 -1
- package/dialects/sqlite/SqlitePlatform.js +4 -0
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +4 -1
- package/dialects/sqlite/SqliteSchemaHelper.js +49 -19
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +4 -4
- package/plugin/transformer.d.ts +11 -3
- package/plugin/transformer.js +138 -29
- package/query/CriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +2 -2
- package/query/ObjectCriteriaNode.js +1 -1
- package/query/QueryBuilder.d.ts +42 -1
- package/query/QueryBuilder.js +78 -7
- package/schema/DatabaseSchema.d.ts +29 -2
- package/schema/DatabaseSchema.js +131 -4
- package/schema/DatabaseTable.d.ts +14 -1
- package/schema/DatabaseTable.js +165 -32
- package/schema/SchemaComparator.d.ts +18 -0
- package/schema/SchemaComparator.js +196 -1
- package/schema/SchemaHelper.d.ts +67 -1
- package/schema/SchemaHelper.js +255 -25
- package/schema/SqlSchemaGenerator.d.ts +2 -2
- package/schema/SqlSchemaGenerator.js +40 -10
- package/schema/partitioning.d.ts +13 -0
- package/schema/partitioning.js +326 -0
- package/typings.d.ts +59 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Install a driver package for your database:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
|
|
22
23
|
npm install @mikro-orm/mysql # MySQL
|
|
23
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
24
25
|
npm install @mikro-orm/sqlite # SQLite
|
package/SqlEntityManager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EntitySchemaWithMeta, EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type
|
|
1
|
+
import { type AbortQueryOptions, type EntitySchemaWithMeta, EntityManager, type AnyEntity, type ConnectionType, type CountByOptions, type Dictionary, type EntityData, type EntityKey, type EntityName, type EntityRepository, type FilterQuery, type GetRepository, type LoggingOptions, type QueryResult, type RawQueryFragment } from '@mikro-orm/core';
|
|
2
2
|
import type { AbstractSqlDriver } from './AbstractSqlDriver.js';
|
|
3
3
|
import type { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
4
4
|
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
@@ -6,6 +6,13 @@ import type { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
|
6
6
|
import type { Kysely } from 'kysely';
|
|
7
7
|
import type { InferClassEntityDB, InferKyselyDB } from './typings.js';
|
|
8
8
|
import { type MikroKyselyPluginOptions } from './plugin/index.js';
|
|
9
|
+
/** Options for the modern signature of `SqlEntityManager.execute()`. */
|
|
10
|
+
export interface EmExecuteOptions extends AbortQueryOptions {
|
|
11
|
+
/** Result shape — `'all'` for rows, `'get'` for a single row, `'run'` for affected count. Defaults to `'all'`. */
|
|
12
|
+
method?: 'all' | 'get' | 'run';
|
|
13
|
+
/** Logger context payload forwarded to `Logger.logQuery`. */
|
|
14
|
+
loggerContext?: LoggingOptions;
|
|
15
|
+
}
|
|
9
16
|
/** Options for `SqlEntityManager.getKysely()`. */
|
|
10
17
|
export interface GetKyselyOptions extends MikroKyselyPluginOptions {
|
|
11
18
|
/** Connection type to use (`'read'` or `'write'`). */
|
|
@@ -24,14 +31,50 @@ export declare class SqlEntityManager<Driver extends AbstractSqlDriver = Abstrac
|
|
|
24
31
|
*/
|
|
25
32
|
qb<Entity extends object, RootAlias extends string = never>(entityName: EntityName<Entity>, alias?: RootAlias, type?: ConnectionType, loggerContext?: LoggingOptions): QueryBuilder<Entity, RootAlias>;
|
|
26
33
|
/**
|
|
27
|
-
* Returns configured Kysely instance.
|
|
34
|
+
* Returns a configured Kysely instance bound to this EntityManager.
|
|
35
|
+
*
|
|
36
|
+
* When the EntityManager is inside a transaction (e.g. within `em.transactional(...)`, or after
|
|
37
|
+
* `em.begin()`), the returned Kysely instance automatically uses the transaction context, so any
|
|
38
|
+
* queries executed via Kysely's own `.execute()` / `.executeTakeFirst*()` participate in the
|
|
39
|
+
* current transaction.
|
|
40
|
+
*
|
|
41
|
+
* If you need a Kysely instance that is **not** bound to the current transaction (e.g. to perform
|
|
42
|
+
* a side query against the pool while inside a transactional block), fork the EntityManager first:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* await em.transactional(async em => {
|
|
46
|
+
* // bound to the current transaction
|
|
47
|
+
* await em.getKysely().selectFrom('user').selectAll().execute();
|
|
48
|
+
*
|
|
49
|
+
* // bound to the pool, runs outside the transaction
|
|
50
|
+
* await em.fork().getKysely().selectFrom('audit_log').selectAll().execute();
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* The `options.type` (`'read'` / `'write'`) is only honored outside a transaction — inside a
|
|
55
|
+
* transaction the connection is already pinned.
|
|
28
56
|
*/
|
|
29
57
|
getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(options?: TOptions): Kysely<TDB extends undefined ? InferKyselyDB<EntitiesFromManager<this>, TOptions> & InferClassEntityDB<AllEntitiesFromManager<this>, TOptions> : TDB>;
|
|
30
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Executes a raw SQL query, using the current transaction context if available. The fork-level
|
|
60
|
+
* `signal` / `inflightQueryAbortStrategy` (set via `em.fork({ signal })`) is applied automatically.
|
|
61
|
+
* For per-call cancellation use the options-bag overload below.
|
|
62
|
+
*/
|
|
31
63
|
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', loggerContext?: LoggingOptions): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Executes a raw SQL query with an options bag carrying `method`, `loggerContext`, `signal`
|
|
66
|
+
* and `inflightQueryAbortStrategy`. Per-call `signal` / `inflightQueryAbortStrategy` override
|
|
67
|
+
* the fork-level defaults set via `em.fork({ signal })`. The current transaction context is
|
|
68
|
+
* applied automatically.
|
|
69
|
+
*/
|
|
70
|
+
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params: any[], options: EmExecuteOptions): Promise<T>;
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
countBy<Entity extends object>(entityName: EntityName<Entity>, groupBy: EntityKey<Entity> | readonly EntityKey<Entity>[], options?: CountByOptions<Entity>): Promise<Dictionary<number>>;
|
|
32
75
|
getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>;
|
|
33
76
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
34
77
|
}
|
|
35
|
-
type EntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta> : never;
|
|
36
|
-
type AllEntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? NonNullable<TEntityManager['~entities']>[number] : never;
|
|
78
|
+
type EntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends readonly any[] ? Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta> : never;
|
|
79
|
+
type AllEntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends readonly any[] ? NonNullable<TEntityManager['~entities']>[number] : never;
|
|
37
80
|
export {};
|
package/SqlEntityManager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, } from '@mikro-orm/core';
|
|
1
|
+
import { EntityManager, raw, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { MikroKyselyPlugin } from './plugin/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* @inheritDoc
|
|
@@ -9,7 +9,9 @@ export class SqlEntityManager extends EntityManager {
|
|
|
9
9
|
*/
|
|
10
10
|
createQueryBuilder(entityName, alias, type, loggerContext) {
|
|
11
11
|
const context = this.getContext(false);
|
|
12
|
-
|
|
12
|
+
const qb = this.driver.createQueryBuilder(entityName, context.getTransactionContext(), type, true, loggerContext ?? context.loggerContext, alias, this);
|
|
13
|
+
qb.setAbortOptions(context.getAbortOptions());
|
|
14
|
+
return qb;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Shortcut for `createQueryBuilder()`
|
|
@@ -18,10 +20,33 @@ export class SqlEntityManager extends EntityManager {
|
|
|
18
20
|
return this.createQueryBuilder(entityName, alias, type, loggerContext);
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
|
-
* Returns configured Kysely instance.
|
|
23
|
+
* Returns a configured Kysely instance bound to this EntityManager.
|
|
24
|
+
*
|
|
25
|
+
* When the EntityManager is inside a transaction (e.g. within `em.transactional(...)`, or after
|
|
26
|
+
* `em.begin()`), the returned Kysely instance automatically uses the transaction context, so any
|
|
27
|
+
* queries executed via Kysely's own `.execute()` / `.executeTakeFirst*()` participate in the
|
|
28
|
+
* current transaction.
|
|
29
|
+
*
|
|
30
|
+
* If you need a Kysely instance that is **not** bound to the current transaction (e.g. to perform
|
|
31
|
+
* a side query against the pool while inside a transactional block), fork the EntityManager first:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* await em.transactional(async em => {
|
|
35
|
+
* // bound to the current transaction
|
|
36
|
+
* await em.getKysely().selectFrom('user').selectAll().execute();
|
|
37
|
+
*
|
|
38
|
+
* // bound to the pool, runs outside the transaction
|
|
39
|
+
* await em.fork().getKysely().selectFrom('audit_log').selectAll().execute();
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The `options.type` (`'read'` / `'write'`) is only honored outside a transaction — inside a
|
|
44
|
+
* transaction the connection is already pinned.
|
|
22
45
|
*/
|
|
23
46
|
getKysely(options = {}) {
|
|
24
|
-
|
|
47
|
+
const context = this.getContext(false);
|
|
48
|
+
const ctx = context.getTransactionContext();
|
|
49
|
+
let kysely = ctx ?? this.getConnection(options.type).getClient();
|
|
25
50
|
if (options.columnNamingStrategy != null ||
|
|
26
51
|
options.tableNamingStrategy != null ||
|
|
27
52
|
options.processOnCreateHooks != null ||
|
|
@@ -31,9 +56,54 @@ export class SqlEntityManager extends EntityManager {
|
|
|
31
56
|
}
|
|
32
57
|
return kysely;
|
|
33
58
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
async execute(query, params = [], methodOrOptions = 'all', loggerContext) {
|
|
60
|
+
const opts = typeof methodOrOptions === 'string' ? { method: methodOrOptions, loggerContext } : methodOrOptions;
|
|
61
|
+
const context = this.getContext(false);
|
|
62
|
+
// Per-field fallback to fork-level abort, matching `EntityManager.prepareOptions` semantics.
|
|
63
|
+
const fork = context.getAbortOptions();
|
|
64
|
+
const hasAbort = opts.signal != null || opts.inflightQueryAbortStrategy != null || fork != null;
|
|
65
|
+
// Connection layer carries abort piggy-backed on `loggerContext`; merge only when needed.
|
|
66
|
+
const merged = hasAbort || opts.loggerContext ? { ...opts.loggerContext } : undefined;
|
|
67
|
+
if (merged && hasAbort) {
|
|
68
|
+
merged.signal = opts.signal ?? fork?.signal;
|
|
69
|
+
merged.inflightQueryAbortStrategy = opts.inflightQueryAbortStrategy ?? fork?.inflightQueryAbortStrategy;
|
|
70
|
+
}
|
|
71
|
+
return this.getDriver().execute(query, params, opts.method ?? 'all', context.getTransactionContext(), merged);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @inheritDoc
|
|
75
|
+
*/
|
|
76
|
+
async countBy(entityName, groupBy, options = {}) {
|
|
77
|
+
const em = this.getContext(false);
|
|
78
|
+
options = { ...options };
|
|
79
|
+
em.prepareOptions(options);
|
|
80
|
+
const meta = em.getMetadata().find(entityName);
|
|
81
|
+
const fields = Utils.asArray(groupBy);
|
|
82
|
+
const { where: rawWhere, ...countOptions } = options;
|
|
83
|
+
await em.tryFlush(entityName, options);
|
|
84
|
+
const where = await em.processWhere(entityName, rawWhere ?? {}, options, 'read');
|
|
85
|
+
const qb = em.createQueryBuilder(meta.class);
|
|
86
|
+
qb
|
|
87
|
+
.select([...fields, raw('count(*) as cnt')])
|
|
88
|
+
.where(where)
|
|
89
|
+
.groupBy(fields);
|
|
90
|
+
if (countOptions.having) {
|
|
91
|
+
qb.having(countOptions.having);
|
|
92
|
+
}
|
|
93
|
+
if (countOptions.schema) {
|
|
94
|
+
qb.withSchema(countOptions.schema);
|
|
95
|
+
}
|
|
96
|
+
const rows = await qb.execute('all', { mapResults: false });
|
|
97
|
+
const results = {};
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const keyParts = fields.map(f => {
|
|
100
|
+
const col = meta.properties[f]?.fieldNames?.[0] ?? f;
|
|
101
|
+
return String(row[col]);
|
|
102
|
+
});
|
|
103
|
+
const key = keyParts.join(Utils.PK_SEPARATOR);
|
|
104
|
+
results[key] = +row.cnt;
|
|
105
|
+
}
|
|
106
|
+
return results;
|
|
37
107
|
}
|
|
38
108
|
getRepository(entityName) {
|
|
39
109
|
return super.getRepository(entityName);
|
package/SqlMikroORM.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AnyEntity, type EntityClass, type EntityManager, type EntityManagerType, type EntitySchema, type IDatabaseDriver, MikroORM, type Options } from '@mikro-orm/core';
|
|
2
|
+
import type { AbstractSqlDriver } from './AbstractSqlDriver.js';
|
|
3
|
+
import type { SqlEntityManager } from './SqlEntityManager.js';
|
|
4
|
+
/** Configuration options shared by all SQL drivers. */
|
|
5
|
+
export type SqlOptions<D extends AbstractSqlDriver = AbstractSqlDriver, EM extends SqlEntityManager<D> = SqlEntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<D, EM, Entities>>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a type-safe configuration object for any SQL driver. The driver class
|
|
8
|
+
* must be passed via `options.driver` (e.g. `SqliteDriver`, `MySqlDriver`, …).
|
|
9
|
+
*/
|
|
10
|
+
export declare function defineSqlConfig<D extends AbstractSqlDriver = AbstractSqlDriver, EM extends SqlEntityManager<D> = SqlEntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Partial<Options<D, EM, Entities>>;
|
|
11
|
+
/**
|
|
12
|
+
* Generic entry point for SQL drivers. Use this when consuming `@mikro-orm/sql`
|
|
13
|
+
* directly with a Kysely dialect; for the bundled driver packages prefer
|
|
14
|
+
* `@mikro-orm/sqlite`, `@mikro-orm/postgresql`, etc.
|
|
15
|
+
*
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
export declare class SqlMikroORM<D extends AbstractSqlDriver = AbstractSqlDriver, EM extends SqlEntityManager<D> = SqlEntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<D, EM, Entities> {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static init<D extends IDatabaseDriver = AbstractSqlDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
23
|
+
}
|
package/SqlMikroORM.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineConfig, MikroORM, } from '@mikro-orm/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a type-safe configuration object for any SQL driver. The driver class
|
|
4
|
+
* must be passed via `options.driver` (e.g. `SqliteDriver`, `MySqlDriver`, …).
|
|
5
|
+
*/
|
|
6
|
+
export function defineSqlConfig(options) {
|
|
7
|
+
return defineConfig(options);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generic entry point for SQL drivers. Use this when consuming `@mikro-orm/sql`
|
|
11
|
+
* directly with a Kysely dialect; for the bundled driver packages prefer
|
|
12
|
+
* `@mikro-orm/sqlite`, `@mikro-orm/postgresql`, etc.
|
|
13
|
+
*
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
export class SqlMikroORM extends MikroORM {
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static async init(options) {
|
|
21
|
+
return super.init(options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -35,11 +35,9 @@ export declare class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
35
35
|
getDefaultMappedType(type: string): Type<unknown>;
|
|
36
36
|
isNumericColumn(mappedType: Type<unknown>): boolean;
|
|
37
37
|
supportsUnsigned(): boolean;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*/
|
|
42
|
-
getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence'): string;
|
|
38
|
+
/** MySQL/MariaDB identifier limit. */
|
|
39
|
+
getMaxIdentifierLength(): number;
|
|
40
|
+
getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence' | 'check'): string;
|
|
43
41
|
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
44
42
|
supportsCreatingFullTextIndex(): boolean;
|
|
45
43
|
getFullTextWhereClause(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryOrder, DecimalType, DoubleType, } from '@mikro-orm/core';
|
|
2
2
|
import { MySqlSchemaHelper } from './MySqlSchemaHelper.js';
|
|
3
3
|
import { MySqlExceptionConverter } from './MySqlExceptionConverter.js';
|
|
4
4
|
import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
|
|
@@ -86,19 +86,15 @@ export class BaseMySqlPlatform extends AbstractSqlPlatform {
|
|
|
86
86
|
supportsUnsigned() {
|
|
87
87
|
return true;
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
/** MySQL/MariaDB identifier limit. */
|
|
90
|
+
getMaxIdentifierLength() {
|
|
91
|
+
return 64;
|
|
92
|
+
}
|
|
93
93
|
getIndexName(tableName, columns, type) {
|
|
94
94
|
if (type === 'primary') {
|
|
95
95
|
return this.getDefaultPrimaryName(tableName, columns);
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
if (indexName.length > 64) {
|
|
99
|
-
return `${indexName.substring(0, 56 - type.length)}_${Utils.hash(indexName, 5)}_${type}`;
|
|
100
|
-
}
|
|
101
|
-
return indexName;
|
|
97
|
+
return super.getIndexName(tableName, columns, type);
|
|
102
98
|
}
|
|
103
99
|
getDefaultPrimaryName(tableName, columns) {
|
|
104
100
|
return 'PRIMARY'; // https://dev.mysql.com/doc/refman/8.0/en/create-table.html#create-table-indexes-keys
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Dictionary, type Transaction, type Type } from '@mikro-orm/core';
|
|
2
|
-
import type { CheckDef, Column, ForeignKey, IndexDef, Table, TableDifference, SqlTriggerDef } from '../../typings.js';
|
|
2
|
+
import type { CheckDef, Column, ForeignKey, IndexDef, Table, TableDifference, SqlTriggerDef, SqlRoutineDef } from '../../typings.js';
|
|
3
3
|
import type { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
|
|
4
4
|
import { SchemaHelper } from '../../schema/SchemaHelper.js';
|
|
5
5
|
import type { DatabaseSchema } from '../../schema/DatabaseSchema.js';
|
|
@@ -11,7 +11,12 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
11
11
|
'current_timestamp(?)': string[];
|
|
12
12
|
'0': string[];
|
|
13
13
|
};
|
|
14
|
+
private static readonly PARTIAL_INDEX_RE;
|
|
14
15
|
getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
|
|
16
|
+
getSetSchemaSQL(schema: string): string;
|
|
17
|
+
getResetSchemaSQL(defaultSchema: string): string;
|
|
18
|
+
supportsMigrationSchema(): boolean;
|
|
19
|
+
tableExists(connection: AbstractSqlConnection, tableName: string, schemaName: string | undefined, ctx?: Transaction): Promise<boolean>;
|
|
15
20
|
disableForeignKeysSQL(): string;
|
|
16
21
|
enableForeignKeysSQL(): string;
|
|
17
22
|
finalizeTable(table: DatabaseTable, charset: string, collate?: string): string;
|
|
@@ -22,8 +27,10 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
22
27
|
getAllIndexes(connection: AbstractSqlConnection, tables: Table[], ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
|
|
23
28
|
getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
|
|
24
29
|
/**
|
|
25
|
-
* Build the column list for a MySQL index
|
|
26
|
-
*
|
|
30
|
+
* Build the column list for a MySQL index. MySQL requires collation via an expression:
|
|
31
|
+
* `(column COLLATE collation_name)`. Partial indexes (`where`) are emulated via functional
|
|
32
|
+
* indexes — requires MySQL 8.0.13+. MariaDB does not support inline functional indexes
|
|
33
|
+
* and overrides to throw at a higher level.
|
|
27
34
|
*/
|
|
28
35
|
protected getIndexColumns(index: IndexDef): string;
|
|
29
36
|
/**
|
|
@@ -34,6 +41,12 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
34
41
|
getAllChecks(connection: AbstractSqlConnection, tables: Table[], ctx?: Transaction): Promise<Dictionary<CheckDef[]>>;
|
|
35
42
|
/** Generates SQL to create MySQL triggers. MySQL requires one trigger per event. */
|
|
36
43
|
createTrigger(table: DatabaseTable, trigger: SqlTriggerDef): string;
|
|
44
|
+
createRoutine(routine: SqlRoutineDef): string;
|
|
45
|
+
dropRoutine(routine: SqlRoutineDef): string;
|
|
46
|
+
getAllRoutines(connection: AbstractSqlConnection): Promise<SqlRoutineDef[]>;
|
|
47
|
+
private getAllRoutineParams;
|
|
48
|
+
private formatDataAccess;
|
|
49
|
+
private parseDataAccess;
|
|
37
50
|
getAllTriggers(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<SqlTriggerDef[]>>;
|
|
38
51
|
getAllForeignKeys(connection: AbstractSqlConnection, tables: Table[], ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
39
52
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
|