@mikro-orm/knex 6.3.5-dev.9 → 6.3.6-dev.0
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 +13 -2
- package/README.md +2 -1
- package/dialects/mysql/MySqlPlatform.d.ts +5 -0
- package/dialects/mysql/MySqlPlatform.js +7 -0
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +5 -0
- package/dialects/sqlite/BaseSqlitePlatform.js +7 -0
- package/package.json +3 -3
- package/schema/DatabaseTable.js +8 -8
- package/schema/SchemaComparator.js +2 -2
package/AbstractSqlDriver.js
CHANGED
|
@@ -135,11 +135,19 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
135
135
|
.indexHint(options.indexHint)
|
|
136
136
|
.comment(options.comments)
|
|
137
137
|
.hintComment(options.hintComments);
|
|
138
|
+
const { first, last, before, after } = options;
|
|
139
|
+
const isCursorPagination = [first, last, before, after].some(v => v != null);
|
|
138
140
|
if (type !== query_1.QueryType.COUNT) {
|
|
139
|
-
qb.limit(options?.limit, options?.offset);
|
|
140
141
|
if (options.orderBy) {
|
|
141
|
-
|
|
142
|
+
if (isCursorPagination) {
|
|
143
|
+
const { orderBy: newOrderBy, where } = this.processCursorOptions(meta, options, options.orderBy);
|
|
144
|
+
qb.andWhere(where).orderBy(newOrderBy);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
qb.orderBy(options.orderBy);
|
|
148
|
+
}
|
|
142
149
|
}
|
|
150
|
+
qb.limit(options?.limit, options?.offset);
|
|
143
151
|
}
|
|
144
152
|
qb.where(where);
|
|
145
153
|
const kqb = qb.getKnexQuery(false).clear('select');
|
|
@@ -154,6 +162,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
154
162
|
if (type === query_1.QueryType.COUNT) {
|
|
155
163
|
return res[0].count;
|
|
156
164
|
}
|
|
165
|
+
if (isCursorPagination && !first && !!last) {
|
|
166
|
+
res.reverse();
|
|
167
|
+
}
|
|
157
168
|
return res.map(row => this.mapResult(row, meta));
|
|
158
169
|
}
|
|
159
170
|
mapResult(result, meta, populate = [], qb, map = {}) {
|
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
143
143
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
144
|
- [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
|
|
145
145
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
|
-
- [Lifecycle Hooks](https://mikro-orm.io/docs/
|
|
146
|
+
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
147
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
148
148
|
- [Schema Generator](https://mikro-orm.io/docs/schema-generator)
|
|
149
149
|
- [Entity Generator](https://mikro-orm.io/docs/entity-generator)
|
|
@@ -163,6 +163,7 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
|
|
|
163
163
|
- [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
|
|
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
|
+
- [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
|
|
166
167
|
|
|
167
168
|
### JavaScript Examples
|
|
168
169
|
|
|
@@ -16,6 +16,11 @@ export declare class MySqlPlatform extends AbstractSqlPlatform {
|
|
|
16
16
|
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
17
17
|
getJsonIndexDefinition(index: IndexDef): string[];
|
|
18
18
|
getBooleanTypeDeclarationSQL(): string;
|
|
19
|
+
normalizeColumnType(type: string, options?: {
|
|
20
|
+
length?: number;
|
|
21
|
+
precision?: number;
|
|
22
|
+
scale?: number;
|
|
23
|
+
}): string;
|
|
19
24
|
getDefaultMappedType(type: string): Type<unknown>;
|
|
20
25
|
supportsUnsigned(): boolean;
|
|
21
26
|
/**
|
|
@@ -36,6 +36,13 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
|
|
|
36
36
|
getBooleanTypeDeclarationSQL() {
|
|
37
37
|
return 'tinyint(1)';
|
|
38
38
|
}
|
|
39
|
+
normalizeColumnType(type, options = {}) {
|
|
40
|
+
const simpleType = this.extractSimpleType(type);
|
|
41
|
+
if (['decimal', 'numeric'].includes(simpleType)) {
|
|
42
|
+
return this.getDecimalTypeDeclarationSQL(options);
|
|
43
|
+
}
|
|
44
|
+
return type;
|
|
45
|
+
}
|
|
39
46
|
getDefaultMappedType(type) {
|
|
40
47
|
if (type === 'tinyint(1)') {
|
|
41
48
|
return super.getDefaultMappedType('boolean');
|
|
@@ -36,6 +36,11 @@ export declare abstract class BaseSqlitePlatform extends AbstractSqlPlatform {
|
|
|
36
36
|
getVarcharTypeDeclarationSQL(column: {
|
|
37
37
|
length?: number;
|
|
38
38
|
}): string;
|
|
39
|
+
normalizeColumnType(type: string, options?: {
|
|
40
|
+
length?: number;
|
|
41
|
+
precision?: number;
|
|
42
|
+
scale?: number;
|
|
43
|
+
}): string;
|
|
39
44
|
convertsJsonAutomatically(): boolean;
|
|
40
45
|
/**
|
|
41
46
|
* This is used to narrow the value of Date properties as they will be stored as timestamps in sqlite.
|
|
@@ -44,6 +44,13 @@ class BaseSqlitePlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
|
|
|
44
44
|
getVarcharTypeDeclarationSQL(column) {
|
|
45
45
|
return 'text';
|
|
46
46
|
}
|
|
47
|
+
normalizeColumnType(type, options = {}) {
|
|
48
|
+
const simpleType = this.extractSimpleType(type);
|
|
49
|
+
if (['varchar', 'text'].includes(simpleType)) {
|
|
50
|
+
return this.getVarcharTypeDeclarationSQL(options);
|
|
51
|
+
}
|
|
52
|
+
return simpleType;
|
|
53
|
+
}
|
|
47
54
|
convertsJsonAutomatically() {
|
|
48
55
|
return false;
|
|
49
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.6-dev.0",
|
|
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.5"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.3.
|
|
69
|
+
"@mikro-orm/core": "6.3.6-dev.0",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -421,12 +421,9 @@ class DatabaseTable {
|
|
|
421
421
|
findFkIndex(currentFk) {
|
|
422
422
|
const fkColumnsLength = currentFk.columnNames.length;
|
|
423
423
|
const possibleIndexes = this.indexes.filter(index => {
|
|
424
|
-
return index.columnNames.length
|
|
424
|
+
return index.columnNames.length === fkColumnsLength && !currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName);
|
|
425
425
|
});
|
|
426
426
|
possibleIndexes.sort((a, b) => {
|
|
427
|
-
if (a.columnNames.length !== b.columnNames.length) {
|
|
428
|
-
return a.columnNames.length < b.columnNames.length ? -1 : 1;
|
|
429
|
-
}
|
|
430
427
|
if (a.primary !== b.primary) {
|
|
431
428
|
return a.primary ? -1 : 1;
|
|
432
429
|
}
|
|
@@ -594,6 +591,11 @@ class DatabaseTable {
|
|
|
594
591
|
const unique = compositeFkUniques[prop] || this.indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary);
|
|
595
592
|
const kind = this.getReferenceKind(fk, unique);
|
|
596
593
|
const runtimeType = this.getPropertyTypeForColumn(namingStrategy, column, fk);
|
|
594
|
+
const type = fk ? runtimeType : (core_1.Utils.keys(core_1.t).find(k => {
|
|
595
|
+
const typeInCoreMap = this.platform.getMappedType(k);
|
|
596
|
+
return (typeInCoreMap !== core_1.Type.getType(core_1.UnknownType) || k === 'unknown') && typeInCoreMap === column.mappedType;
|
|
597
|
+
}) ?? runtimeType);
|
|
598
|
+
const ignoreSchemaChanges = (type === 'unknown' && column.length) ? (column.extra ? ['type', 'extra'] : ['type']) : undefined;
|
|
597
599
|
const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, runtimeType, true);
|
|
598
600
|
const defaultParsed = this.getPropertyDefaultValue(schemaHelper, column, runtimeType);
|
|
599
601
|
const defaultTs = defaultRaw !== defaultParsed ? defaultParsed : undefined;
|
|
@@ -608,12 +610,10 @@ class DatabaseTable {
|
|
|
608
610
|
}
|
|
609
611
|
return {
|
|
610
612
|
name: prop,
|
|
611
|
-
type
|
|
612
|
-
const typeInCoreMap = this.platform.getMappedType(k);
|
|
613
|
-
return (typeInCoreMap !== core_1.Type.getType(core_1.UnknownType) || k === 'unknown') && typeInCoreMap === column.mappedType;
|
|
614
|
-
}) ?? runtimeType),
|
|
613
|
+
type,
|
|
615
614
|
runtimeType,
|
|
616
615
|
kind,
|
|
616
|
+
ignoreSchemaChanges,
|
|
617
617
|
generated: column.generated,
|
|
618
618
|
optional: defaultRaw !== 'null' || defaultTs != null || typeof column.generated !== 'undefined',
|
|
619
619
|
columnType: column.type,
|
|
@@ -385,9 +385,9 @@ class SchemaComparator {
|
|
|
385
385
|
const changedProperties = new Set();
|
|
386
386
|
const fromProp = this.mapColumnToProperty({ ...fromColumn, autoincrement: false });
|
|
387
387
|
const toProp = this.mapColumnToProperty({ ...toColumn, autoincrement: false });
|
|
388
|
-
const fromColumnType = fromColumn.mappedType.getColumnType(fromProp, this.platform).toLowerCase();
|
|
388
|
+
const fromColumnType = this.platform.normalizeColumnType(fromColumn.mappedType.getColumnType(fromProp, this.platform).toLowerCase(), fromProp);
|
|
389
389
|
const fromNativeEnum = fromTable.nativeEnums[fromColumnType] ?? Object.values(fromTable.nativeEnums).find(e => e.name === fromColumnType && e.schema !== '*');
|
|
390
|
-
const toColumnType = toColumn.mappedType.getColumnType(toProp, this.platform).toLowerCase();
|
|
390
|
+
const toColumnType = this.platform.normalizeColumnType(toColumn.mappedType.getColumnType(toProp, this.platform).toLowerCase(), toProp);
|
|
391
391
|
const log = (msg, params) => {
|
|
392
392
|
if (tableName) {
|
|
393
393
|
const copy = core_1.Utils.copy(params);
|