@mikro-orm/mysql
Advanced tools
+1
-5
@@ -5,6 +5,2 @@ export * from '@mikro-orm/sql'; | ||
| export * from './MySqlConnection.js'; | ||
| export { | ||
| MySqlMikroORM as MikroORM, | ||
| type MySqlOptions as Options, | ||
| defineMySqlConfig as defineConfig, | ||
| } from './MySqlMikroORM.js'; | ||
| export { MySqlMikroORM as MikroORM, type MySqlOptions as Options, defineMySqlConfig as defineConfig, } from './MySqlMikroORM.js'; |
+1
-1
@@ -5,2 +5,2 @@ export * from '@mikro-orm/sql'; | ||
| export * from './MySqlConnection.js'; | ||
| export { MySqlMikroORM as MikroORM, defineMySqlConfig as defineConfig } from './MySqlMikroORM.js'; | ||
| export { MySqlMikroORM as MikroORM, defineMySqlConfig as defineConfig, } from './MySqlMikroORM.js'; |
@@ -6,5 +6,5 @@ import { type ControlledTransaction, MysqlDialect } from 'kysely'; | ||
| export declare class MySqlConnection extends AbstractSqlConnection { | ||
| createKyselyDialect(overrides: PoolOptions): MysqlDialect; | ||
| mapOptions(overrides: PoolOptions): PoolOptions; | ||
| commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>; | ||
| createKyselyDialect(overrides: PoolOptions): MysqlDialect; | ||
| mapOptions(overrides: PoolOptions): PoolOptions; | ||
| commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>; | ||
| } |
+47
-47
@@ -6,53 +6,53 @@ import { MysqlDialect } from 'kysely'; | ||
| export class MySqlConnection extends AbstractSqlConnection { | ||
| createKyselyDialect(overrides) { | ||
| const options = this.mapOptions(overrides); | ||
| const password = options.password; | ||
| if (typeof password === 'function') { | ||
| return new MysqlDialect({ | ||
| pool: async () => | ||
| createPool({ | ||
| ...options, | ||
| password: await password(), | ||
| }), | ||
| onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'), | ||
| }); | ||
| createKyselyDialect(overrides) { | ||
| const options = this.mapOptions(overrides); | ||
| const password = options.password; | ||
| if (typeof password === 'function') { | ||
| return new MysqlDialect({ | ||
| pool: async () => createPool({ | ||
| ...options, | ||
| password: await password(), | ||
| }), | ||
| onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'), | ||
| }); | ||
| } | ||
| return new MysqlDialect({ | ||
| pool: createPool(options), | ||
| onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'), | ||
| }); | ||
| } | ||
| return new MysqlDialect({ | ||
| pool: createPool(options), | ||
| onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'), | ||
| }); | ||
| } | ||
| mapOptions(overrides) { | ||
| const ret = { ...this.getConnectionOptions() }; | ||
| const pool = this.config.get('pool'); | ||
| ret.connectionLimit = pool?.max; | ||
| ret.idleTimeout = pool?.idleTimeoutMillis; | ||
| if (this.config.get('multipleStatements')) { | ||
| ret.multipleStatements = this.config.get('multipleStatements'); | ||
| mapOptions(overrides) { | ||
| const ret = { ...this.getConnectionOptions() }; | ||
| const pool = this.config.get('pool'); | ||
| ret.connectionLimit = pool?.max; | ||
| ret.idleTimeout = pool?.idleTimeoutMillis; | ||
| if (this.config.get('multipleStatements')) { | ||
| ret.multipleStatements = this.config.get('multipleStatements'); | ||
| } | ||
| if (this.config.get('forceUtcTimezone')) { | ||
| ret.timezone = 'Z'; | ||
| } | ||
| if (this.config.get('timezone')) { | ||
| ret.timezone = this.config.get('timezone'); | ||
| } | ||
| ret.supportBigNumbers = true; | ||
| ret.dateStrings = true; | ||
| return Utils.mergeConfig(ret, overrides); | ||
| } | ||
| if (this.config.get('forceUtcTimezone')) { | ||
| ret.timezone = 'Z'; | ||
| } | ||
| if (this.config.get('timezone')) { | ||
| ret.timezone = this.config.get('timezone'); | ||
| } | ||
| ret.supportBigNumbers = true; | ||
| ret.dateStrings = true; | ||
| return Utils.mergeConfig(ret, overrides); | ||
| } | ||
| async commit(ctx, eventBroadcaster) { | ||
| if (!ctx.isRolledBack && 'savepointName' in ctx) { | ||
| try { | ||
| await ctx.releaseSavepoint(ctx.savepointName).execute(); | ||
| } catch (e) { | ||
| /* v8 ignore next */ | ||
| // https://github.com/knex/knex/issues/805 | ||
| if (e.errno !== 1305) { | ||
| throw e; | ||
| async commit(ctx, eventBroadcaster) { | ||
| if (!ctx.isRolledBack && 'savepointName' in ctx) { | ||
| try { | ||
| await ctx.releaseSavepoint(ctx.savepointName).execute(); | ||
| } | ||
| catch (e) { | ||
| /* v8 ignore next */ | ||
| // https://github.com/knex/knex/issues/805 | ||
| if (e.errno !== 1305) { | ||
| throw e; | ||
| } | ||
| } | ||
| return this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName)); | ||
| } | ||
| } | ||
| return this.logQuery(this.platform.getReleaseSavepointSQL(ctx.savepointName)); | ||
| await super.commit(ctx, eventBroadcaster); | ||
| } | ||
| await super.commit(ctx, eventBroadcaster); | ||
| } | ||
| } |
+8
-26
@@ -1,11 +0,2 @@ | ||
| import type { | ||
| Configuration, | ||
| Constructor, | ||
| EntityDictionary, | ||
| EntityName, | ||
| FilterQuery, | ||
| NativeInsertUpdateManyOptions, | ||
| QueryResult, | ||
| UpsertManyOptions, | ||
| } from '@mikro-orm/core'; | ||
| import type { Configuration, Constructor, EntityDictionary, EntityName, FilterQuery, NativeInsertUpdateManyOptions, QueryResult, UpsertManyOptions } from '@mikro-orm/core'; | ||
| import { AbstractSqlDriver } from '@mikro-orm/sql'; | ||
@@ -17,18 +8,9 @@ import { MySqlConnection } from './MySqlConnection.js'; | ||
| export declare class MySqlDriver extends AbstractSqlDriver<MySqlConnection, MySqlPlatform> { | ||
| private autoIncrementIncrement?; | ||
| constructor(config: Configuration); | ||
| private getAutoIncrementIncrement; | ||
| nativeInsertMany<T extends object>( | ||
| entityName: EntityName<T>, | ||
| data: EntityDictionary<T>[], | ||
| options?: NativeInsertUpdateManyOptions<T>, | ||
| ): Promise<QueryResult<T>>; | ||
| nativeUpdateMany<T extends object>( | ||
| entityName: EntityName<T>, | ||
| where: FilterQuery<T>[], | ||
| data: EntityDictionary<T>[], | ||
| options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>, | ||
| ): Promise<QueryResult<T>>; | ||
| /** @inheritDoc */ | ||
| getORMClass(): Constructor<MySqlMikroORM>; | ||
| private autoIncrementIncrement?; | ||
| constructor(config: Configuration); | ||
| private getAutoIncrementIncrement; | ||
| nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>; | ||
| nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>; | ||
| /** @inheritDoc */ | ||
| getORMClass(): Constructor<MySqlMikroORM>; | ||
| } |
+48
-52
@@ -7,56 +7,52 @@ import { AbstractSqlDriver, Utils } from '@mikro-orm/sql'; | ||
| export class MySqlDriver extends AbstractSqlDriver { | ||
| autoIncrementIncrement; | ||
| constructor(config) { | ||
| super(config, new MySqlPlatform(), MySqlConnection, ['kysely', 'mysql2']); | ||
| } | ||
| async getAutoIncrementIncrement(ctx) { | ||
| if (this.autoIncrementIncrement == null) { | ||
| // the increment step may differ when running a cluster, see https://github.com/mikro-orm/mikro-orm/issues/3828 | ||
| const res = await this.connection.execute(`show variables like 'auto_increment_increment'`, [], 'get', ctx, { | ||
| enabled: false, | ||
| }); | ||
| /* v8 ignore next */ | ||
| this.autoIncrementIncrement = res?.Value ? +res?.Value : 1; | ||
| autoIncrementIncrement; | ||
| constructor(config) { | ||
| super(config, new MySqlPlatform(), MySqlConnection, ['kysely', 'mysql2']); | ||
| } | ||
| return this.autoIncrementIncrement; | ||
| } | ||
| async nativeInsertMany(entityName, data, options = {}) { | ||
| options.processCollections ??= true; | ||
| const res = await super.nativeInsertMany(entityName, data, options); | ||
| const meta = this.metadata.get(entityName); | ||
| const pks = this.getPrimaryKeyFields(meta); | ||
| const ctx = options.ctx; | ||
| const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx); | ||
| data.forEach( | ||
| (item, idx) => (res.rows[idx] = { [pks[0]]: item[pks[0]] ?? res.insertId + idx * autoIncrementIncrement }), | ||
| ); | ||
| res.row = res.rows[0]; | ||
| return res; | ||
| } | ||
| async nativeUpdateMany(entityName, where, data, options = {}) { | ||
| const res = await super.nativeUpdateMany(entityName, where, data, options); | ||
| const meta = this.metadata.get(entityName); | ||
| const pks = this.getPrimaryKeyFields(meta); | ||
| const ctx = options.ctx; | ||
| const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx); | ||
| let i = 0; | ||
| const rows = where.map(cond => { | ||
| if (res.insertId != null && Utils.isEmpty(cond)) { | ||
| return { [pks[0]]: res.insertId + i++ * autoIncrementIncrement }; | ||
| } | ||
| if (cond[pks[0]] == null) { | ||
| return undefined; | ||
| } | ||
| return { [pks[0]]: cond[pks[0]] }; | ||
| }); | ||
| if (rows.every(i => i !== undefined)) { | ||
| res.rows = rows; | ||
| async getAutoIncrementIncrement(ctx) { | ||
| if (this.autoIncrementIncrement == null) { | ||
| // the increment step may differ when running a cluster, see https://github.com/mikro-orm/mikro-orm/issues/3828 | ||
| const res = await this.connection.execute(`show variables like 'auto_increment_increment'`, [], 'get', ctx, { enabled: false }); | ||
| /* v8 ignore next */ | ||
| this.autoIncrementIncrement = res?.Value ? +res?.Value : 1; | ||
| } | ||
| return this.autoIncrementIncrement; | ||
| } | ||
| res.row = res.rows[0]; | ||
| return res; | ||
| } | ||
| /** @inheritDoc */ | ||
| getORMClass() { | ||
| return MySqlMikroORM; | ||
| } | ||
| async nativeInsertMany(entityName, data, options = {}) { | ||
| options.processCollections ??= true; | ||
| const res = await super.nativeInsertMany(entityName, data, options); | ||
| const meta = this.metadata.get(entityName); | ||
| const pks = this.getPrimaryKeyFields(meta); | ||
| const ctx = options.ctx; | ||
| const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx); | ||
| data.forEach((item, idx) => (res.rows[idx] = { [pks[0]]: item[pks[0]] ?? res.insertId + idx * autoIncrementIncrement })); | ||
| res.row = res.rows[0]; | ||
| return res; | ||
| } | ||
| async nativeUpdateMany(entityName, where, data, options = {}) { | ||
| const res = await super.nativeUpdateMany(entityName, where, data, options); | ||
| const meta = this.metadata.get(entityName); | ||
| const pks = this.getPrimaryKeyFields(meta); | ||
| const ctx = options.ctx; | ||
| const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx); | ||
| let i = 0; | ||
| const rows = where.map(cond => { | ||
| if (res.insertId != null && Utils.isEmpty(cond)) { | ||
| return { [pks[0]]: res.insertId + i++ * autoIncrementIncrement }; | ||
| } | ||
| if (cond[pks[0]] == null) { | ||
| return undefined; | ||
| } | ||
| return { [pks[0]]: cond[pks[0]] }; | ||
| }); | ||
| if (rows.every(i => i !== undefined)) { | ||
| res.rows = rows; | ||
| } | ||
| res.row = res.rows[0]; | ||
| return res; | ||
| } | ||
| /** @inheritDoc */ | ||
| getORMClass() { | ||
| return MySqlMikroORM; | ||
| } | ||
| } |
+12
-50
@@ -1,58 +0,20 @@ | ||
| import { | ||
| type AnyEntity, | ||
| type EntityClass, | ||
| type EntitySchema, | ||
| MikroORM, | ||
| type Options, | ||
| type IDatabaseDriver, | ||
| type EntityManager, | ||
| type EntityManagerType, | ||
| } from '@mikro-orm/core'; | ||
| import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core'; | ||
| import type { SqlEntityManager } from '@mikro-orm/sql'; | ||
| import { MySqlDriver } from './MySqlDriver.js'; | ||
| /** Configuration options for the MySQL driver. */ | ||
| export type MySqlOptions< | ||
| EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, | ||
| Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = ( | ||
| | string | ||
| | EntityClass<AnyEntity> | ||
| | EntitySchema | ||
| )[], | ||
| > = Partial<Options<MySqlDriver, EM, Entities>>; | ||
| export type MySqlOptions<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MySqlDriver, EM, Entities>>; | ||
| /** Creates a type-safe configuration object for the MySQL driver. */ | ||
| 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>>; | ||
| 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>>; | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| 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> { | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| 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>>; | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| constructor(options: Partial<Options<MySqlDriver, EM, Entities>>); | ||
| 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> { | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| 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>>; | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| constructor(options: Partial<Options<MySqlDriver, EM, Entities>>); | ||
| } |
+14
-14
@@ -1,6 +0,6 @@ | ||
| import { defineConfig, MikroORM } from '@mikro-orm/core'; | ||
| import { defineConfig, MikroORM, } from '@mikro-orm/core'; | ||
| import { MySqlDriver } from './MySqlDriver.js'; | ||
| /** Creates a type-safe configuration object for the MySQL driver. */ | ||
| export function defineMySqlConfig(options) { | ||
| return defineConfig({ driver: MySqlDriver, ...options }); | ||
| return defineConfig({ driver: MySqlDriver, ...options }); | ||
| } | ||
@@ -11,14 +11,14 @@ /** | ||
| export class MySqlMikroORM extends MikroORM { | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| static async init(options) { | ||
| return super.init(defineMySqlConfig(options)); | ||
| } | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| constructor(options) { | ||
| super(defineMySqlConfig(options)); | ||
| } | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| static async init(options) { | ||
| return super.init(defineMySqlConfig(options)); | ||
| } | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| constructor(options) { | ||
| super(defineMySqlConfig(options)); | ||
| } | ||
| } |
| import { BaseMySqlPlatform } from '@mikro-orm/sql'; | ||
| /** Platform implementation for MySQL. */ | ||
| export declare class MySqlPlatform extends BaseMySqlPlatform { | ||
| escape(value: any): string; | ||
| escape(value: any): string; | ||
| } |
+3
-3
@@ -5,5 +5,5 @@ import SqlString from 'sqlstring'; | ||
| export class MySqlPlatform extends BaseMySqlPlatform { | ||
| escape(value) { | ||
| return SqlString.escape(value, true, this.timezone); | ||
| } | ||
| escape(value) { | ||
| return SqlString.escape(value, true, this.timezone); | ||
| } | ||
| } |
+3
-3
| { | ||
| "name": "@mikro-orm/mysql", | ||
| "version": "7.0.3", | ||
| "version": "7.0.4-dev.0", | ||
| "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.", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@mikro-orm/sql": "7.0.3", | ||
| "@mikro-orm/sql": "7.0.4-dev.0", | ||
| "kysely": "0.28.12", | ||
@@ -60,3 +60,3 @@ "mysql2": "3.20.0", | ||
| "peerDependencies": { | ||
| "@mikro-orm/core": "7.0.3" | ||
| "@mikro-orm/core": "7.0.4-dev.0" | ||
| }, | ||
@@ -63,0 +63,0 @@ "engines": { |
+1
-1
@@ -136,3 +136,3 @@ <h1 align="center"> | ||
| author.name = 'Jon Snow II'; | ||
| author.books.getItems().forEach(book => (book.title += ' (2nd ed.)')); | ||
| author.books.getItems().forEach(book => book.title += ' (2nd ed.)'); | ||
| author.books.add(orm.em.create(Book, { title: 'New Book', author })); | ||
@@ -139,0 +139,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21828
1.54%206
-23.13%1
Infinity%+ Added
+ Added
- Removed
- Removed
Updated