@mikro-orm/knex 6.3.11-dev.8 → 6.3.11
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/AbstractSqlDriver.js +2 -2
- package/README.md +1 -0
- package/dialects/mysql/MySqlColumnCompiler.d.ts +4 -6
- package/dialects/mysql/MySqlColumnCompiler.js +11 -4
- package/dialects/mysql/MySqlSchemaHelper.d.ts +0 -3
- package/dialects/mysql/MySqlSchemaHelper.js +0 -12
- package/package.json +3 -3
- package/schema/DatabaseTable.js +1 -1
- package/schema/SchemaHelper.d.ts +2 -2
- package/schema/SchemaHelper.js +3 -3
- package/typings.d.ts +9 -0
package/AbstractSqlDriver.js
CHANGED
|
@@ -261,7 +261,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
261
261
|
else if (prop.runtimeType === 'Date') {
|
|
262
262
|
const alias = `${relationAlias}__${prop.fieldNames[0]}`;
|
|
263
263
|
const value = root[alias];
|
|
264
|
-
if (tz && tz !== 'local' && typeof value === 'string' && !value.includes('+') && !value.endsWith('Z')) {
|
|
264
|
+
if (tz && tz !== 'local' && typeof value === 'string' && !value.includes('+') && value.lastIndexOf('-') < 11 && !value.endsWith('Z')) {
|
|
265
265
|
relationPojo[prop.name] = this.platform.parseDate(value + tz);
|
|
266
266
|
}
|
|
267
267
|
else if (['string', 'number'].includes(typeof value)) {
|
|
@@ -562,7 +562,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
562
562
|
params.push(value);
|
|
563
563
|
};
|
|
564
564
|
for (const key of keys) {
|
|
565
|
-
const prop = meta.properties[key];
|
|
565
|
+
const prop = meta.properties[key] ?? meta.root.properties[key];
|
|
566
566
|
prop.fieldNames.forEach((fieldName, fieldNameIdx) => {
|
|
567
567
|
if (fields.has(fieldName)) {
|
|
568
568
|
return;
|
package/README.md
CHANGED
|
@@ -164,6 +164,7 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
|
|
|
164
164
|
- [Accounts.js REST and GraphQL authentication + SQLite](https://github.com/darkbasic/mikro-orm-accounts-example)
|
|
165
165
|
- [Nest + Shopify + PostgreSQL + GraphQL](https://github.com/Cloudshelf/Shopify_CSConnector)
|
|
166
166
|
- [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
|
|
167
|
+
- [Electron.js + PostgreSQL](https://github.com/adnanlah/electron-mikro-orm-example-app)
|
|
167
168
|
|
|
168
169
|
### JavaScript Examples
|
|
169
170
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import BaseMySqlColumnCompiler from 'knex/lib/dialects/mysql/schema/mysql-columncompiler';
|
|
2
|
+
import type { IncrementOptions } from '../../typings';
|
|
2
3
|
export declare class MySqlColumnCompiler extends BaseMySqlColumnCompiler {
|
|
3
|
-
increments(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
bigincrements(this: any, options?: {
|
|
7
|
-
primaryKey: boolean;
|
|
8
|
-
}): string;
|
|
4
|
+
increments(options: IncrementOptions): string;
|
|
5
|
+
bigincrements(options: IncrementOptions): string;
|
|
6
|
+
private generateDDL;
|
|
9
7
|
}
|
|
@@ -8,12 +8,19 @@ exports.MySqlColumnCompiler = void 0;
|
|
|
8
8
|
const mysql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mysql/schema/mysql-columncompiler"));
|
|
9
9
|
class MySqlColumnCompiler extends mysql_columncompiler_1.default {
|
|
10
10
|
// we need the old behaviour to be able to add auto_increment to a column that is already PK
|
|
11
|
-
increments(options
|
|
12
|
-
return
|
|
11
|
+
increments(options) {
|
|
12
|
+
return this.generateDDL(options);
|
|
13
13
|
}
|
|
14
14
|
/* istanbul ignore next */
|
|
15
|
-
bigincrements(options
|
|
16
|
-
return
|
|
15
|
+
bigincrements(options) {
|
|
16
|
+
return this.generateDDL(options);
|
|
17
|
+
}
|
|
18
|
+
generateDDL(options = {}) {
|
|
19
|
+
const { primaryKey = true, unsigned = true, type = 'int' } = options;
|
|
20
|
+
return type
|
|
21
|
+
+ (unsigned ? ' unsigned' : '')
|
|
22
|
+
+ ' not null auto_increment'
|
|
23
|
+
+ (this.tableCompiler._canBeAddPrimaryKey({ primaryKey }) ? ' primary key' : '');
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
exports.MySqlColumnCompiler = MySqlColumnCompiler;
|
|
@@ -4,7 +4,6 @@ import { type Dictionary, type Type } from '@mikro-orm/core';
|
|
|
4
4
|
import type { AbstractSqlConnection } from '../../AbstractSqlConnection';
|
|
5
5
|
import { SchemaHelper } from '../../schema/SchemaHelper';
|
|
6
6
|
import type { DatabaseSchema } from '../../schema/DatabaseSchema';
|
|
7
|
-
import type { DatabaseTable } from '../../schema/DatabaseTable';
|
|
8
7
|
export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
9
8
|
private readonly _cache;
|
|
10
9
|
static readonly DEFAULT_VALUES: {
|
|
@@ -27,8 +26,6 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
27
26
|
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column): string;
|
|
28
27
|
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
|
|
29
28
|
getChangeColumnCommentSQL(tableName: string, to: Column, schemaName?: string): string;
|
|
30
|
-
createTableColumn(table: Knex.TableBuilder, column: Column, fromTable: DatabaseTable, changedProperties?: Set<string>): Knex.ColumnBuilder | undefined;
|
|
31
|
-
configureColumn(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
32
29
|
private getColumnDeclarationSQL;
|
|
33
30
|
getForeignKeysSQL(tableName: string, schemaName?: string): string;
|
|
34
31
|
getAllEnumDefinitions(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<string[]>>>;
|
|
@@ -208,18 +208,6 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
|
|
|
208
208
|
const columnName = this.platform.quoteIdentifier(to.name);
|
|
209
209
|
return `alter table ${tableName} modify ${columnName} ${this.getColumnDeclarationSQL(to)}`;
|
|
210
210
|
}
|
|
211
|
-
createTableColumn(table, column, fromTable, changedProperties) {
|
|
212
|
-
if (column.mappedType instanceof core_1.MediumIntType) {
|
|
213
|
-
return table.specificType(column.name, this.getColumnDeclarationSQL(column, true));
|
|
214
|
-
}
|
|
215
|
-
return super.createTableColumn(table, column, fromTable, changedProperties);
|
|
216
|
-
}
|
|
217
|
-
configureColumn(column, col, knex, changedProperties) {
|
|
218
|
-
if (column.mappedType instanceof core_1.MediumIntType) {
|
|
219
|
-
return col;
|
|
220
|
-
}
|
|
221
|
-
return super.configureColumn(column, col, knex, changedProperties);
|
|
222
|
-
}
|
|
223
211
|
getColumnDeclarationSQL(col, addPrimary = false) {
|
|
224
212
|
let ret = col.type;
|
|
225
213
|
ret += col.unsigned ? ' unsigned' : '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.3.11
|
|
3
|
+
"version": "6.3.11",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.3.
|
|
66
|
+
"@mikro-orm/core": "^6.3.11"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.
|
|
69
|
+
"@mikro-orm/core": "^6.0.0",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -96,7 +96,7 @@ class DatabaseTable {
|
|
|
96
96
|
extra: prop.extra,
|
|
97
97
|
ignoreSchemaChanges: prop.ignoreSchemaChanges,
|
|
98
98
|
};
|
|
99
|
-
this.columns[field].unsigned
|
|
99
|
+
this.columns[field].unsigned ??= this.columns[field].autoincrement;
|
|
100
100
|
const defaultValue = this.platform.getSchemaHelper().normalizeDefaultValue(prop.defaultRaw, prop.length);
|
|
101
101
|
this.columns[field].default = defaultValue;
|
|
102
102
|
});
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Connection, type Dictionary } from '@mikro-orm/core';
|
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
3
|
import type { AbstractSqlConnection } from '../AbstractSqlConnection';
|
|
4
4
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
5
|
-
import type { CheckDef, Column, ForeignKey, IndexDef, Table, TableDifference } from '../typings';
|
|
5
|
+
import type { CheckDef, Column, ExpandedTableBuilder, ForeignKey, IndexDef, Table, TableDifference } from '../typings';
|
|
6
6
|
import type { DatabaseSchema } from './DatabaseSchema';
|
|
7
7
|
import type { DatabaseTable } from './DatabaseTable';
|
|
8
8
|
export declare abstract class SchemaHelper {
|
|
@@ -30,7 +30,7 @@ export declare abstract class SchemaHelper {
|
|
|
30
30
|
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
|
|
31
31
|
getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
|
|
32
32
|
hasNonDefaultPrimaryKeyName(table: DatabaseTable): boolean;
|
|
33
|
-
createTableColumn(table:
|
|
33
|
+
createTableColumn(table: ExpandedTableBuilder, column: Column, fromTable: DatabaseTable, changedProperties?: Set<string>, alter?: boolean): Knex.ColumnBuilder | undefined;
|
|
34
34
|
configureColumn(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
35
35
|
configureColumnDefault(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
36
36
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -126,12 +126,12 @@ class SchemaHelper {
|
|
|
126
126
|
}
|
|
127
127
|
createTableColumn(table, column, fromTable, changedProperties, alter) {
|
|
128
128
|
const compositePK = fromTable.getPrimaryKey()?.composite;
|
|
129
|
-
if (column.autoincrement && !column.generated && !compositePK &&
|
|
129
|
+
if (column.autoincrement && !column.generated && !compositePK && column.primary) {
|
|
130
130
|
const primaryKey = !changedProperties && !this.hasNonDefaultPrimaryKeyName(fromTable);
|
|
131
131
|
if (column.mappedType instanceof core_1.BigIntType) {
|
|
132
|
-
return table.bigIncrements(column.name, { primaryKey });
|
|
132
|
+
return table.bigIncrements(column.name, { primaryKey, unsigned: column.unsigned, type: column.type });
|
|
133
133
|
}
|
|
134
|
-
return table.increments(column.name, { primaryKey });
|
|
134
|
+
return table.increments(column.name, { primaryKey, unsigned: column.unsigned, type: column.type });
|
|
135
135
|
}
|
|
136
136
|
if (column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) {
|
|
137
137
|
return table.enum(column.name, column.enumItems);
|
package/typings.d.ts
CHANGED
|
@@ -185,4 +185,13 @@ export interface ICriteriaNode<T extends object> {
|
|
|
185
185
|
getPath(addIndex?: boolean): string;
|
|
186
186
|
getPivotPath(path: string): string;
|
|
187
187
|
}
|
|
188
|
+
export type IncrementOptions = {
|
|
189
|
+
primaryKey?: boolean;
|
|
190
|
+
unsigned?: boolean;
|
|
191
|
+
type?: Column['type'];
|
|
192
|
+
};
|
|
193
|
+
export interface ExpandedTableBuilder extends Knex.TableBuilder {
|
|
194
|
+
increments(columnName?: string, options?: IncrementOptions): Knex.ColumnBuilder;
|
|
195
|
+
bigIncrements(columnName?: string, options?: IncrementOptions): Knex.ColumnBuilder;
|
|
196
|
+
}
|
|
188
197
|
export {};
|