@mikro-orm/mysql 7.0.3-dev.9 → 7.0.3

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.
@@ -3,7 +3,7 @@ import { type PoolOptions } from 'mysql2';
3
3
  import { AbstractSqlConnection, type TransactionEventBroadcaster } from '@mikro-orm/sql';
4
4
  /** MySQL database connection using the `mysql2` driver. */
5
5
  export declare class MySqlConnection extends AbstractSqlConnection {
6
- createKyselyDialect(overrides: PoolOptions): MysqlDialect;
7
- mapOptions(overrides: PoolOptions): PoolOptions;
8
- commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
6
+ createKyselyDialect(overrides: PoolOptions): MysqlDialect;
7
+ mapOptions(overrides: PoolOptions): PoolOptions;
8
+ commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
9
9
  }
@@ -3,55 +3,55 @@ import { createPool } from 'mysql2';
3
3
  import { Utils, AbstractSqlConnection } from '@mikro-orm/sql';
4
4
  /** MySQL database connection using the `mysql2` driver. */
5
5
  export class MySqlConnection extends AbstractSqlConnection {
6
- createKyselyDialect(overrides) {
7
- const options = this.mapOptions(overrides);
8
- const password = options.password;
9
- if (typeof password === 'function') {
10
- return new MysqlDialect({
11
- pool: async () => createPool({
12
- ...options,
13
- password: await password(),
14
- }),
15
- onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
16
- });
17
- }
18
- return new MysqlDialect({
19
- pool: createPool(options),
20
- onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
21
- });
6
+ createKyselyDialect(overrides) {
7
+ const options = this.mapOptions(overrides);
8
+ const password = options.password;
9
+ if (typeof password === 'function') {
10
+ return new MysqlDialect({
11
+ pool: async () =>
12
+ createPool({
13
+ ...options,
14
+ password: await password(),
15
+ }),
16
+ onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
17
+ });
22
18
  }
23
- mapOptions(overrides) {
24
- const ret = { ...this.getConnectionOptions() };
25
- const pool = this.config.get('pool');
26
- ret.connectionLimit = pool?.max;
27
- ret.idleTimeout = pool?.idleTimeoutMillis;
28
- if (this.config.get('multipleStatements')) {
29
- ret.multipleStatements = this.config.get('multipleStatements');
30
- }
31
- if (this.config.get('forceUtcTimezone')) {
32
- ret.timezone = 'Z';
33
- }
34
- if (this.config.get('timezone')) {
35
- ret.timezone = this.config.get('timezone');
36
- }
37
- ret.supportBigNumbers = true;
38
- ret.dateStrings = true;
39
- return Utils.mergeConfig(ret, overrides);
19
+ return new MysqlDialect({
20
+ pool: createPool(options),
21
+ onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
22
+ });
23
+ }
24
+ mapOptions(overrides) {
25
+ const ret = { ...this.getConnectionOptions() };
26
+ const pool = this.config.get('pool');
27
+ ret.connectionLimit = pool?.max;
28
+ ret.idleTimeout = pool?.idleTimeoutMillis;
29
+ if (this.config.get('multipleStatements')) {
30
+ ret.multipleStatements = this.config.get('multipleStatements');
31
+ }
32
+ if (this.config.get('forceUtcTimezone')) {
33
+ ret.timezone = 'Z';
34
+ }
35
+ if (this.config.get('timezone')) {
36
+ ret.timezone = this.config.get('timezone');
40
37
  }
41
- async commit(ctx, eventBroadcaster) {
42
- if (!ctx.isRolledBack && 'savepointName' in ctx) {
43
- try {
44
- await ctx.releaseSavepoint(ctx.savepointName).execute();
45
- }
46
- catch (e) {
47
- /* v8 ignore next */
48
- // https://github.com/knex/knex/issues/805
49
- if (e.errno !== 1305) {
50
- throw e;
51
- }
52
- }
53
- return this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
38
+ ret.supportBigNumbers = true;
39
+ ret.dateStrings = true;
40
+ return Utils.mergeConfig(ret, overrides);
41
+ }
42
+ async commit(ctx, eventBroadcaster) {
43
+ if (!ctx.isRolledBack && 'savepointName' in ctx) {
44
+ try {
45
+ await ctx.releaseSavepoint(ctx.savepointName).execute();
46
+ } catch (e) {
47
+ /* v8 ignore next */
48
+ // https://github.com/knex/knex/issues/805
49
+ if (e.errno !== 1305) {
50
+ throw e;
54
51
  }
55
- await super.commit(ctx, eventBroadcaster);
52
+ }
53
+ return this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName));
56
54
  }
55
+ await super.commit(ctx, eventBroadcaster);
56
+ }
57
57
  }
package/MySqlDriver.d.ts CHANGED
@@ -1,15 +1,33 @@
1
- import type { Configuration, Constructor, EntityDictionary, EntityName, FilterQuery, NativeInsertUpdateManyOptions, QueryResult, UpsertManyOptions } from '@mikro-orm/core';
1
+ import type {
2
+ Configuration,
3
+ Constructor,
4
+ EntityDictionary,
5
+ EntityName,
6
+ FilterQuery,
7
+ NativeInsertUpdateManyOptions,
8
+ QueryResult,
9
+ UpsertManyOptions,
10
+ } from '@mikro-orm/core';
2
11
  import { AbstractSqlDriver } from '@mikro-orm/sql';
3
12
  import { MySqlConnection } from './MySqlConnection.js';
4
13
  import { MySqlMikroORM } from './MySqlMikroORM.js';
5
14
  import { MySqlPlatform } from './MySqlPlatform.js';
6
15
  /** Database driver for MySQL. */
7
16
  export declare class MySqlDriver extends AbstractSqlDriver<MySqlConnection, MySqlPlatform> {
8
- private autoIncrementIncrement?;
9
- constructor(config: Configuration);
10
- private getAutoIncrementIncrement;
11
- nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
12
- nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
13
- /** @inheritDoc */
14
- getORMClass(): Constructor<MySqlMikroORM>;
17
+ private autoIncrementIncrement?;
18
+ constructor(config: Configuration);
19
+ private getAutoIncrementIncrement;
20
+ nativeInsertMany<T extends object>(
21
+ entityName: EntityName<T>,
22
+ data: EntityDictionary<T>[],
23
+ options?: NativeInsertUpdateManyOptions<T>,
24
+ ): Promise<QueryResult<T>>;
25
+ nativeUpdateMany<T extends object>(
26
+ entityName: EntityName<T>,
27
+ where: FilterQuery<T>[],
28
+ data: EntityDictionary<T>[],
29
+ options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>,
30
+ ): Promise<QueryResult<T>>;
31
+ /** @inheritDoc */
32
+ getORMClass(): Constructor<MySqlMikroORM>;
15
33
  }
package/MySqlDriver.js CHANGED
@@ -4,54 +4,58 @@ import { MySqlMikroORM } from './MySqlMikroORM.js';
4
4
  import { MySqlPlatform } from './MySqlPlatform.js';
5
5
  /** Database driver for MySQL. */
6
6
  export class MySqlDriver extends AbstractSqlDriver {
7
- autoIncrementIncrement;
8
- constructor(config) {
9
- super(config, new MySqlPlatform(), MySqlConnection, ['kysely', 'mysql2']);
7
+ autoIncrementIncrement;
8
+ constructor(config) {
9
+ super(config, new MySqlPlatform(), MySqlConnection, ['kysely', 'mysql2']);
10
+ }
11
+ async getAutoIncrementIncrement(ctx) {
12
+ if (this.autoIncrementIncrement == null) {
13
+ // the increment step may differ when running a cluster, see https://github.com/mikro-orm/mikro-orm/issues/3828
14
+ const res = await this.connection.execute(`show variables like 'auto_increment_increment'`, [], 'get', ctx, {
15
+ enabled: false,
16
+ });
17
+ /* v8 ignore next */
18
+ this.autoIncrementIncrement = res?.Value ? +res?.Value : 1;
10
19
  }
11
- async getAutoIncrementIncrement(ctx) {
12
- if (this.autoIncrementIncrement == null) {
13
- // the increment step may differ when running a cluster, see https://github.com/mikro-orm/mikro-orm/issues/3828
14
- const res = await this.connection.execute(`show variables like 'auto_increment_increment'`, [], 'get', ctx, { enabled: false });
15
- /* v8 ignore next */
16
- this.autoIncrementIncrement = res?.Value ? +res?.Value : 1;
17
- }
18
- return this.autoIncrementIncrement;
19
- }
20
- async nativeInsertMany(entityName, data, options = {}) {
21
- options.processCollections ??= true;
22
- const res = await super.nativeInsertMany(entityName, data, options);
23
- const meta = this.metadata.get(entityName);
24
- const pks = this.getPrimaryKeyFields(meta);
25
- const ctx = options.ctx;
26
- const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx);
27
- data.forEach((item, idx) => (res.rows[idx] = { [pks[0]]: item[pks[0]] ?? res.insertId + idx * autoIncrementIncrement }));
28
- res.row = res.rows[0];
29
- return res;
30
- }
31
- async nativeUpdateMany(entityName, where, data, options = {}) {
32
- const res = await super.nativeUpdateMany(entityName, where, data, options);
33
- const meta = this.metadata.get(entityName);
34
- const pks = this.getPrimaryKeyFields(meta);
35
- const ctx = options.ctx;
36
- const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx);
37
- let i = 0;
38
- const rows = where.map(cond => {
39
- if (res.insertId != null && Utils.isEmpty(cond)) {
40
- return { [pks[0]]: res.insertId + i++ * autoIncrementIncrement };
41
- }
42
- if (cond[pks[0]] == null) {
43
- return undefined;
44
- }
45
- return { [pks[0]]: cond[pks[0]] };
46
- });
47
- if (rows.every(i => i !== undefined)) {
48
- res.rows = rows;
49
- }
50
- res.row = res.rows[0];
51
- return res;
52
- }
53
- /** @inheritDoc */
54
- getORMClass() {
55
- return MySqlMikroORM;
20
+ return this.autoIncrementIncrement;
21
+ }
22
+ async nativeInsertMany(entityName, data, options = {}) {
23
+ options.processCollections ??= true;
24
+ const res = await super.nativeInsertMany(entityName, data, options);
25
+ const meta = this.metadata.get(entityName);
26
+ const pks = this.getPrimaryKeyFields(meta);
27
+ const ctx = options.ctx;
28
+ const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx);
29
+ data.forEach(
30
+ (item, idx) => (res.rows[idx] = { [pks[0]]: item[pks[0]] ?? res.insertId + idx * autoIncrementIncrement }),
31
+ );
32
+ res.row = res.rows[0];
33
+ return res;
34
+ }
35
+ async nativeUpdateMany(entityName, where, data, options = {}) {
36
+ const res = await super.nativeUpdateMany(entityName, where, data, options);
37
+ const meta = this.metadata.get(entityName);
38
+ const pks = this.getPrimaryKeyFields(meta);
39
+ const ctx = options.ctx;
40
+ const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx);
41
+ let i = 0;
42
+ const rows = where.map(cond => {
43
+ if (res.insertId != null && Utils.isEmpty(cond)) {
44
+ return { [pks[0]]: res.insertId + i++ * autoIncrementIncrement };
45
+ }
46
+ if (cond[pks[0]] == null) {
47
+ return undefined;
48
+ }
49
+ return { [pks[0]]: cond[pks[0]] };
50
+ });
51
+ if (rows.every(i => i !== undefined)) {
52
+ res.rows = rows;
56
53
  }
54
+ res.row = res.rows[0];
55
+ return res;
56
+ }
57
+ /** @inheritDoc */
58
+ getORMClass() {
59
+ return MySqlMikroORM;
60
+ }
57
61
  }
@@ -1,20 +1,58 @@
1
- import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
1
+ import {
2
+ type AnyEntity,
3
+ type EntityClass,
4
+ type EntitySchema,
5
+ MikroORM,
6
+ type Options,
7
+ type IDatabaseDriver,
8
+ type EntityManager,
9
+ type EntityManagerType,
10
+ } from '@mikro-orm/core';
2
11
  import type { SqlEntityManager } from '@mikro-orm/sql';
3
12
  import { MySqlDriver } from './MySqlDriver.js';
4
13
  /** Configuration options for the MySQL driver. */
5
- export type MySqlOptions<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MySqlDriver, EM, Entities>>;
14
+ export type MySqlOptions<
15
+ EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>,
16
+ Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
17
+ | string
18
+ | EntityClass<AnyEntity>
19
+ | EntitySchema
20
+ )[],
21
+ > = Partial<Options<MySqlDriver, EM, Entities>>;
6
22
  /** Creates a type-safe configuration object for the MySQL driver. */
7
- export declare function defineMySqlConfig<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<MySqlDriver, EM, Entities>>): Partial<Options<MySqlDriver, EM, Entities>>;
23
+ export declare function defineMySqlConfig<
24
+ EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>,
25
+ Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
26
+ | string
27
+ | EntityClass<AnyEntity>
28
+ | EntitySchema
29
+ )[],
30
+ >(options: Partial<Options<MySqlDriver, EM, Entities>>): Partial<Options<MySqlDriver, EM, Entities>>;
8
31
  /**
9
32
  * @inheritDoc
10
33
  */
11
- export declare class MySqlMikroORM<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MySqlDriver, EM, Entities> {
12
- /**
13
- * @inheritDoc
14
- */
15
- static init<D extends IDatabaseDriver = MySqlDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
16
- /**
17
- * @inheritDoc
18
- */
19
- constructor(options: Partial<Options<MySqlDriver, EM, Entities>>);
34
+ export declare class MySqlMikroORM<
35
+ EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>,
36
+ Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
37
+ | string
38
+ | EntityClass<AnyEntity>
39
+ | EntitySchema
40
+ )[],
41
+ > extends MikroORM<MySqlDriver, EM, Entities> {
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ static init<
46
+ D extends IDatabaseDriver = MySqlDriver,
47
+ EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>,
48
+ Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (
49
+ | string
50
+ | EntityClass<AnyEntity>
51
+ | EntitySchema
52
+ )[],
53
+ >(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ constructor(options: Partial<Options<MySqlDriver, EM, Entities>>);
20
58
  }
package/MySqlMikroORM.js CHANGED
@@ -1,23 +1,23 @@
1
- import { defineConfig, MikroORM, } from '@mikro-orm/core';
1
+ import { defineConfig, MikroORM } from '@mikro-orm/core';
2
2
  import { MySqlDriver } from './MySqlDriver.js';
3
3
  /** Creates a type-safe configuration object for the MySQL driver. */
4
4
  export function defineMySqlConfig(options) {
5
- return defineConfig({ driver: MySqlDriver, ...options });
5
+ return defineConfig({ driver: MySqlDriver, ...options });
6
6
  }
7
7
  /**
8
8
  * @inheritDoc
9
9
  */
10
10
  export class MySqlMikroORM extends MikroORM {
11
- /**
12
- * @inheritDoc
13
- */
14
- static async init(options) {
15
- return super.init(defineMySqlConfig(options));
16
- }
17
- /**
18
- * @inheritDoc
19
- */
20
- constructor(options) {
21
- super(defineMySqlConfig(options));
22
- }
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static async init(options) {
15
+ return super.init(defineMySqlConfig(options));
16
+ }
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ constructor(options) {
21
+ super(defineMySqlConfig(options));
22
+ }
23
23
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseMySqlPlatform } from '@mikro-orm/sql';
2
2
  /** Platform implementation for MySQL. */
3
3
  export declare class MySqlPlatform extends BaseMySqlPlatform {
4
- escape(value: any): string;
4
+ escape(value: any): string;
5
5
  }
package/MySqlPlatform.js CHANGED
@@ -2,7 +2,7 @@ import SqlString from 'sqlstring';
2
2
  import { BaseMySqlPlatform } from '@mikro-orm/sql';
3
3
  /** Platform implementation for MySQL. */
4
4
  export class MySqlPlatform extends BaseMySqlPlatform {
5
- escape(value) {
6
- return SqlString.escape(value, true, this.timezone);
7
- }
5
+ escape(value) {
6
+ return SqlString.escape(value, true, this.timezone);
7
+ }
8
8
  }
package/README.md CHANGED
@@ -64,7 +64,7 @@ export class Book extends BookSchema.class {}
64
64
  BookSchema.setClass(Book);
65
65
  ```
66
66
 
67
- You can also define entities using [decorators](https://mikro-orm.io/docs/defining-entities) or [`EntitySchema`](https://mikro-orm.io/docs/entity-schema). See the [defining entities guide](https://mikro-orm.io/docs/defining-entities) for all options.
67
+ You can also define entities using [decorators](https://mikro-orm.io/docs/using-decorators) or [`EntitySchema`](https://mikro-orm.io/docs/define-entity#entityschema-low-level-api). See the [defining entities guide](https://mikro-orm.io/docs/defining-entities) for all options.
68
68
 
69
69
  ### Initialize and Use
70
70
 
@@ -133,7 +133,7 @@ const author = await em.findOneOrFail(Author, 1, {
133
133
  populate: ['books'],
134
134
  });
135
135
  author.name = 'Jon Snow II';
136
- author.books.getItems().forEach(book => book.title += ' (2nd ed.)');
136
+ author.books.getItems().forEach(book => (book.title += ' (2nd ed.)'));
137
137
  author.books.add(orm.em.create(Book, { title: 'New Book', author }));
138
138
 
139
139
  // Flush computes change sets and executes them in a single transaction
package/index.d.ts CHANGED
@@ -2,4 +2,8 @@ export * from '@mikro-orm/sql';
2
2
  export * from './MySqlDriver.js';
3
3
  export * from './MySqlPlatform.js';
4
4
  export * from './MySqlConnection.js';
5
- export { MySqlMikroORM as MikroORM, type MySqlOptions as Options, defineMySqlConfig as defineConfig, } from './MySqlMikroORM.js';
5
+ export {
6
+ MySqlMikroORM as MikroORM,
7
+ type MySqlOptions as Options,
8
+ defineMySqlConfig as defineConfig,
9
+ } from './MySqlMikroORM.js';
package/index.js CHANGED
@@ -2,4 +2,4 @@ export * from '@mikro-orm/sql';
2
2
  export * from './MySqlDriver.js';
3
3
  export * from './MySqlPlatform.js';
4
4
  export * from './MySqlConnection.js';
5
- export { MySqlMikroORM as MikroORM, defineMySqlConfig as defineConfig, } from './MySqlMikroORM.js';
5
+ export { MySqlMikroORM as MikroORM, defineMySqlConfig as defineConfig } from './MySqlMikroORM.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mysql",
3
- "version": "7.0.3-dev.9",
3
+ "version": "7.0.3",
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
  "keywords": [
6
6
  "data-mapper",
@@ -47,16 +47,16 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.0.3-dev.9",
50
+ "@mikro-orm/sql": "7.0.3",
51
51
  "kysely": "0.28.12",
52
52
  "mysql2": "3.20.0",
53
53
  "sqlstring": "2.3.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^7.0.2"
56
+ "@mikro-orm/core": "^7.0.3"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.3-dev.9"
59
+ "@mikro-orm/core": "7.0.3"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 22.17.0"