@mikro-orm/sql 7.1.5-dev.1 → 7.1.5-dev.10
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.5-dev.
|
|
3
|
+
"version": "7.1.5-dev.10",
|
|
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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.1.4"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.5-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.5-dev.10"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -389,7 +389,7 @@ export class NativeQueryBuilder {
|
|
|
389
389
|
}
|
|
390
390
|
processInsertData() {
|
|
391
391
|
const dataAsArray = Utils.asArray(this.options.data);
|
|
392
|
-
const keys = Object.keys(dataAsArray[0]);
|
|
392
|
+
const keys = dataAsArray.length > 1 ? [...new Set(dataAsArray.flatMap(row => Object.keys(row)))] : Object.keys(dataAsArray[0]);
|
|
393
393
|
const values = keys.map(() => '?');
|
|
394
394
|
const parts = [];
|
|
395
395
|
this.parts.push(`(${keys.map(key => this.quote(key)).join(', ')})`);
|
package/schema/DatabaseSchema.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, isRaw, } from '@mikro-orm/core';
|
|
2
2
|
import { DatabaseTable } from './DatabaseTable.js';
|
|
3
|
+
import { normalizeViewDefinition } from './SchemaHelper.js';
|
|
3
4
|
import { getTablePartitioning } from './partitioning.js';
|
|
4
5
|
/**
|
|
5
6
|
* @internal
|
|
@@ -364,7 +365,7 @@ export class DatabaseSchema {
|
|
|
364
365
|
}
|
|
365
366
|
static getViewDefinition(meta, em, platform) {
|
|
366
367
|
if (typeof meta.expression === 'string') {
|
|
367
|
-
return meta.expression;
|
|
368
|
+
return normalizeViewDefinition(meta.expression);
|
|
368
369
|
}
|
|
369
370
|
// Expression is a function, need to evaluate it
|
|
370
371
|
/* v8 ignore next */
|
|
@@ -378,7 +379,7 @@ export class DatabaseSchema {
|
|
|
378
379
|
}
|
|
379
380
|
/* v8 ignore next */
|
|
380
381
|
if (typeof result === 'string') {
|
|
381
|
-
return result;
|
|
382
|
+
return normalizeViewDefinition(result);
|
|
382
383
|
}
|
|
383
384
|
/* v8 ignore next */
|
|
384
385
|
if (isRaw(result)) {
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -6,6 +6,17 @@ import type { DatabaseSchema } from './DatabaseSchema.js';
|
|
|
6
6
|
import type { DatabaseTable } from './DatabaseTable.js';
|
|
7
7
|
/** Flattens `;\n` boundaries so the schema-generator's statement splitter doesn't break the routine DDL apart. Other whitespace is preserved. */
|
|
8
8
|
export declare function stripStatementNewlines(body: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Strips SQL line comments and blank lines from a view definition. Comments are dropped by the
|
|
11
|
+
* database on `create view` anyway, and a `--` comment would otherwise comment out the rest of the
|
|
12
|
+
* definition once newlines are collapsed; blank lines act as statement separators in the
|
|
13
|
+
* schema-generator's statement splitter, which would break the view DDL apart.
|
|
14
|
+
*
|
|
15
|
+
* Comment stripping is not string-literal aware, so a `--` inside a string literal (or `a--b` style
|
|
16
|
+
* arithmetic) is treated as a comment — an accepted tradeoff to avoid a full SQL tokenizer.
|
|
17
|
+
* @see https://github.com/mikro-orm/mikro-orm/issues/7875
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeViewDefinition(definition: string): string;
|
|
9
20
|
/** Base class for database-specific schema helpers. Provides SQL generation for DDL operations. */
|
|
10
21
|
export declare abstract class SchemaHelper {
|
|
11
22
|
protected readonly platform: AbstractSqlPlatform;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -3,6 +3,24 @@ import { isRaw, Utils, } from '@mikro-orm/core';
|
|
|
3
3
|
export function stripStatementNewlines(body) {
|
|
4
4
|
return body.replace(/;[\t ]*\r?\n/g, '; ');
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Strips SQL line comments and blank lines from a view definition. Comments are dropped by the
|
|
8
|
+
* database on `create view` anyway, and a `--` comment would otherwise comment out the rest of the
|
|
9
|
+
* definition once newlines are collapsed; blank lines act as statement separators in the
|
|
10
|
+
* schema-generator's statement splitter, which would break the view DDL apart.
|
|
11
|
+
*
|
|
12
|
+
* Comment stripping is not string-literal aware, so a `--` inside a string literal (or `a--b` style
|
|
13
|
+
* arithmetic) is treated as a comment — an accepted tradeoff to avoid a full SQL tokenizer.
|
|
14
|
+
* @see https://github.com/mikro-orm/mikro-orm/issues/7875
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeViewDefinition(definition) {
|
|
17
|
+
return definition
|
|
18
|
+
.replace(/--[^\n]*/g, '')
|
|
19
|
+
.split('\n')
|
|
20
|
+
.filter(line => line.trim() !== '')
|
|
21
|
+
.join('\n')
|
|
22
|
+
.trim();
|
|
23
|
+
}
|
|
6
24
|
/** Base class for database-specific schema helpers. Provides SQL generation for DDL operations. */
|
|
7
25
|
export class SchemaHelper {
|
|
8
26
|
platform;
|
|
@@ -130,7 +130,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
130
130
|
await this.execute(this.helper.disableForeignKeysSQL());
|
|
131
131
|
}
|
|
132
132
|
const schema = options?.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
|
|
133
|
-
for (const meta of this.
|
|
133
|
+
for (const meta of this.getOrderedMetadataForClear(schema).reverse()) {
|
|
134
134
|
try {
|
|
135
135
|
await this.driver
|
|
136
136
|
.createQueryBuilder(meta.class, this.em?.getTransactionContext(), 'write', false)
|