@mikro-orm/mariadb 7.1.0-dev.4 → 7.1.0-dev.41

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.
@@ -1,5 +1,5 @@
1
- import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
2
- import type { SqlEntityManager } from '@mikro-orm/mysql';
1
+ import { type AnyEntity, type EntityClass, type EntitySchema, type MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
2
+ import { SqlMikroORM, type SqlEntityManager } from '@mikro-orm/mysql';
3
3
  import { MariaDbDriver } from './MariaDbDriver.js';
4
4
  /** Configuration options for the MariaDB driver. */
5
5
  export type MariaDbOptions<EM extends SqlEntityManager<MariaDbDriver> = SqlEntityManager<MariaDbDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MariaDbDriver, EM, Entities>>;
@@ -8,7 +8,7 @@ export declare function defineMariaDbConfig<EM extends SqlEntityManager<MariaDbD
8
8
  /**
9
9
  * @inheritDoc
10
10
  */
11
- export declare class MariaDbMikroORM<EM extends SqlEntityManager<MariaDbDriver> = SqlEntityManager<MariaDbDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MariaDbDriver, EM, Entities> {
11
+ export declare class MariaDbMikroORM<EM extends SqlEntityManager<MariaDbDriver> = SqlEntityManager<MariaDbDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<MariaDbDriver, EM, Entities> {
12
12
  /**
13
13
  * @inheritDoc
14
14
  */
@@ -1,4 +1,5 @@
1
- import { defineConfig, MikroORM, } from '@mikro-orm/core';
1
+ import { defineConfig, } from '@mikro-orm/core';
2
+ import { SqlMikroORM } from '@mikro-orm/mysql';
2
3
  import { MariaDbDriver } from './MariaDbDriver.js';
3
4
  /** Creates a type-safe configuration object for the MariaDB driver. */
4
5
  export function defineMariaDbConfig(options) {
@@ -7,7 +8,7 @@ export function defineMariaDbConfig(options) {
7
8
  /**
8
9
  * @inheritDoc
9
10
  */
10
- export class MariaDbMikroORM extends MikroORM {
11
+ export class MariaDbMikroORM extends SqlMikroORM {
11
12
  /**
12
13
  * @inheritDoc
13
14
  */
@@ -2,6 +2,12 @@ import { type AbstractSqlConnection, type CheckDef, type Column, type IndexDef,
2
2
  import { type Dictionary, type Transaction, type Type } from '@mikro-orm/core';
3
3
  /** Schema introspection helper for MariaDB. */
4
4
  export declare class MariaDbSchemaHelper extends MySqlSchemaHelper {
5
+ /**
6
+ * MariaDB does not support inline expression indexes the way MySQL 8.0+ does, so the
7
+ * `(CASE WHEN <pred> THEN <col> END)` emulation MikroORM uses on MySQL would error out.
8
+ * For partial indexes on MariaDB, define a virtual generated column and index that instead.
9
+ */
10
+ protected getIndexColumns(index: IndexDef): string;
5
11
  protected appendMySqlIndexSuffix(sql: string, index: IndexDef): string;
6
12
  loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[], ctx?: Transaction): Promise<void>;
7
13
  getAllIndexes(connection: AbstractSqlConnection, tables: Table[], ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
@@ -1,6 +1,18 @@
1
1
  import { MySqlSchemaHelper, } from '@mikro-orm/mysql';
2
2
  /** Schema introspection helper for MariaDB. */
3
3
  export class MariaDbSchemaHelper extends MySqlSchemaHelper {
4
+ /**
5
+ * MariaDB does not support inline expression indexes the way MySQL 8.0+ does, so the
6
+ * `(CASE WHEN <pred> THEN <col> END)` emulation MikroORM uses on MySQL would error out.
7
+ * For partial indexes on MariaDB, define a virtual generated column and index that instead.
8
+ */
9
+ getIndexColumns(index) {
10
+ if (index.where) {
11
+ throw new Error(`Index '${index.keyName}': partial indexes (\`where\`) are not supported on MariaDB. ` +
12
+ `MariaDB does not support inline expression indexes; define a virtual generated column with the predicate and index that column instead.`);
13
+ }
14
+ return super.getIndexColumns(index);
15
+ }
4
16
  appendMySqlIndexSuffix(sql, index) {
5
17
  // MariaDB uses IGNORED instead of MySQL's INVISIBLE keyword
6
18
  if (index.invisible) {
@@ -24,11 +36,16 @@ export class MariaDbSchemaHelper extends MySqlSchemaHelper {
24
36
  const checks = await this.getAllChecks(connection, tables, ctx, columns);
25
37
  const fks = await this.getAllForeignKeys(connection, tables, ctx);
26
38
  const enums = await this.getAllEnumDefinitions(connection, tables, ctx);
39
+ const triggers = await this.getAllTriggers(connection, tables);
27
40
  for (const t of tables) {
28
41
  const key = this.getTableKey(t);
29
42
  const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
43
+ table.collation = t.table_collation ?? undefined;
30
44
  const pks = await this.getPrimaryKeys(connection, indexes[key], table.name, table.schema);
31
45
  table.init(columns[key], indexes[key], checks[key], pks, fks[key], enums[key]);
46
+ if (triggers[key]) {
47
+ table.setTriggers(triggers[key]);
48
+ }
32
49
  }
33
50
  }
34
51
  async getAllIndexes(connection, tables, ctx) {
@@ -79,22 +96,25 @@ export class MariaDbSchemaHelper extends MySqlSchemaHelper {
79
96
  return ret;
80
97
  }
81
98
  async getAllColumns(connection, tables, ctx) {
82
- const sql = `select table_name as table_name,
83
- nullif(table_schema, schema()) as schema_name,
84
- column_name as column_name,
85
- column_default as column_default,
86
- nullif(column_comment, '') as column_comment,
87
- is_nullable as is_nullable,
88
- data_type as data_type,
89
- column_type as column_type,
90
- column_key as column_key,
91
- extra as extra,
92
- generation_expression as generation_expression,
93
- numeric_precision as numeric_precision,
94
- numeric_scale as numeric_scale,
95
- ifnull(datetime_precision, character_maximum_length) length
96
- from information_schema.columns where table_schema = database() and table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(', ')})
97
- order by ordinal_position`;
99
+ const sql = `select c.table_name as table_name,
100
+ nullif(c.table_schema, schema()) as schema_name,
101
+ c.column_name as column_name,
102
+ c.column_default as column_default,
103
+ nullif(c.column_comment, '') as column_comment,
104
+ c.is_nullable as is_nullable,
105
+ c.data_type as data_type,
106
+ c.column_type as column_type,
107
+ c.column_key as column_key,
108
+ c.extra as extra,
109
+ c.generation_expression as generation_expression,
110
+ c.numeric_precision as numeric_precision,
111
+ c.numeric_scale as numeric_scale,
112
+ ifnull(c.datetime_precision, c.character_maximum_length) length,
113
+ nullif(c.collation_name, t.table_collation) as collation_name
114
+ from information_schema.columns c
115
+ join information_schema.tables t on t.table_schema = c.table_schema and t.table_name = c.table_name
116
+ where c.table_schema = database() and c.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(', ')})
117
+ order by c.ordinal_position`;
98
118
  const allColumns = await connection.execute(sql, [], 'all', ctx);
99
119
  const str = (val) => (val != null ? '' + val : val);
100
120
  const extra = (val) => val.replace(/auto_increment|default_generated|(stored|virtual) generated/i, '').trim() || undefined;
@@ -126,6 +146,7 @@ export class MariaDbSchemaHelper extends MySqlSchemaHelper {
126
146
  precision: col.numeric_precision,
127
147
  scale: col.numeric_scale,
128
148
  comment: col.column_comment,
149
+ collation: col.collation_name ?? undefined,
129
150
  extra: extra(col.extra),
130
151
  generated,
131
152
  });
@@ -144,6 +165,11 @@ export class MariaDbSchemaHelper extends MySqlSchemaHelper {
144
165
  col.type = 'json';
145
166
  col.mappedType = this.platform.getMappedType('json');
146
167
  delete col.length;
168
+ // MariaDB JSON columns are stored as LONGTEXT with `utf8mb4_bin` regardless of the
169
+ // table default, so introspection picks up a non-default `collation_name`. After the
170
+ // rewrite to `type = 'json'`, the column has no user-facing collation — drop the
171
+ // introspected value so the comparator doesn't emit a phantom MODIFY on every diff.
172
+ col.collation = undefined;
147
173
  continue;
148
174
  }
149
175
  ret[key] ??= [];
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mariadb",
3
- "version": "7.1.0-dev.4",
3
+ "version": "7.1.0-dev.41",
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,14 +47,14 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/mysql": "7.1.0-dev.4",
51
- "kysely": "0.28.16"
50
+ "@mikro-orm/mysql": "7.1.0-dev.41",
51
+ "kysely": "0.29.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@mikro-orm/core": "^7.0.11"
54
+ "@mikro-orm/core": "^7.0.16"
55
55
  },
56
56
  "peerDependencies": {
57
- "@mikro-orm/core": "7.1.0-dev.4"
57
+ "@mikro-orm/core": "7.1.0-dev.41"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">= 22.17.0"