@mikro-orm/knex 6.4.6-dev.9 → 7.0.0-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/AbstractSqlConnection.d.ts +15 -25
- package/AbstractSqlConnection.js +98 -126
- package/AbstractSqlDriver.d.ts +20 -13
- package/AbstractSqlDriver.js +73 -54
- package/AbstractSqlPlatform.d.ts +15 -3
- package/AbstractSqlPlatform.js +32 -11
- package/README.md +0 -2
- package/SqlEntityManager.d.ts +5 -6
- package/SqlEntityManager.js +5 -5
- package/SqlEntityRepository.d.ts +1 -6
- package/SqlEntityRepository.js +0 -6
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +161 -0
- package/dialects/mssql/index.d.ts +1 -1
- package/dialects/mssql/index.js +1 -1
- package/dialects/mysql/MySqlExceptionConverter.js +1 -0
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +7 -0
- package/dialects/mysql/MySqlNativeQueryBuilder.js +81 -0
- package/dialects/mysql/MySqlPlatform.d.ts +5 -1
- package/dialects/mysql/MySqlPlatform.js +9 -1
- package/dialects/mysql/MySqlSchemaHelper.d.ts +6 -12
- package/dialects/mysql/MySqlSchemaHelper.js +42 -75
- package/dialects/mysql/index.d.ts +1 -3
- package/dialects/mysql/index.js +1 -3
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +5 -0
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +12 -0
- package/dialects/postgresql/index.d.ts +1 -1
- package/dialects/postgresql/index.js +1 -1
- package/dialects/sqlite/BaseSqliteConnection.d.ts +0 -5
- package/dialects/sqlite/BaseSqliteConnection.js +4 -42
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +15 -3
- package/dialects/sqlite/BaseSqlitePlatform.js +20 -4
- package/dialects/sqlite/SqliteExceptionConverter.d.ts +9 -0
- package/dialects/sqlite/SqliteExceptionConverter.js +55 -0
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +6 -0
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +15 -0
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +38 -0
- package/dialects/sqlite/SqliteSchemaHelper.js +384 -0
- package/dialects/sqlite/index.d.ts +3 -5
- package/dialects/sqlite/index.js +3 -5
- package/index.d.ts +1 -2
- package/index.js +3 -5
- package/index.mjs +10 -13
- package/package.json +4 -18
- package/query/CriteriaNodeFactory.js +5 -5
- package/query/NativeQueryBuilder.d.ts +108 -0
- package/query/NativeQueryBuilder.js +429 -0
- package/query/ObjectCriteriaNode.js +3 -3
- package/query/QueryBuilder.d.ts +30 -34
- package/query/QueryBuilder.js +112 -123
- package/query/QueryBuilderHelper.d.ts +27 -23
- package/query/QueryBuilderHelper.js +174 -168
- package/query/ScalarCriteriaNode.js +4 -0
- package/query/index.d.ts +1 -0
- package/query/index.js +1 -0
- package/schema/DatabaseSchema.js +9 -6
- package/schema/DatabaseTable.d.ts +2 -1
- package/schema/DatabaseTable.js +9 -5
- package/schema/SchemaComparator.d.ts +1 -2
- package/schema/SchemaComparator.js +31 -18
- package/schema/SchemaHelper.d.ts +27 -33
- package/schema/SchemaHelper.js +294 -184
- package/schema/SqlSchemaGenerator.d.ts +3 -9
- package/schema/SqlSchemaGenerator.js +105 -229
- package/typings.d.ts +7 -17
- package/MonkeyPatchable.d.ts +0 -18
- package/MonkeyPatchable.js +0 -60
- package/dialects/mssql/MsSqlColumnCompiler.d.ts +0 -4
- package/dialects/mssql/MsSqlColumnCompiler.js +0 -10
- package/dialects/mssql/MsSqlKnexDialect.d.ts +0 -6
- package/dialects/mssql/MsSqlKnexDialect.js +0 -22
- package/dialects/mssql/MsSqlQueryCompiler.d.ts +0 -12
- package/dialects/mssql/MsSqlQueryCompiler.js +0 -94
- package/dialects/mssql/MsSqlTableCompiler.d.ts +0 -9
- package/dialects/mssql/MsSqlTableCompiler.js +0 -40
- package/dialects/mysql/MariaDbKnexDialect.d.ts +0 -6
- package/dialects/mysql/MariaDbKnexDialect.js +0 -16
- package/dialects/mysql/MySqlColumnCompiler.d.ts +0 -7
- package/dialects/mysql/MySqlColumnCompiler.js +0 -26
- package/dialects/mysql/MySqlConnection.d.ts +0 -8
- package/dialects/mysql/MySqlConnection.js +0 -43
- package/dialects/mysql/MySqlKnexDialect.d.ts +0 -5
- package/dialects/mysql/MySqlKnexDialect.js +0 -17
- package/dialects/mysql/MySqlQueryCompiler.d.ts +0 -5
- package/dialects/mysql/MySqlQueryCompiler.js +0 -23
- package/dialects/postgresql/PostgreSqlKnexDialect.d.ts +0 -7
- package/dialects/postgresql/PostgreSqlKnexDialect.js +0 -20
- package/dialects/postgresql/PostgreSqlQueryCompiler.d.ts +0 -4
- package/dialects/postgresql/PostgreSqlQueryCompiler.js +0 -13
- package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +0 -11
- package/dialects/postgresql/PostgreSqlTableCompiler.js +0 -89
- package/dialects/sqlite/BaseSqliteSchemaHelper.d.ts +0 -28
- package/dialects/sqlite/BaseSqliteSchemaHelper.js +0 -200
- package/dialects/sqlite/BetterSqliteKnexDialect.d.ts +0 -5
- package/dialects/sqlite/BetterSqliteKnexDialect.js +0 -15
- package/dialects/sqlite/LibSqlKnexDialect.d.ts +0 -11
- package/dialects/sqlite/LibSqlKnexDialect.js +0 -85
- package/dialects/sqlite/SqliteKnexDialect.d.ts +0 -8
- package/dialects/sqlite/SqliteKnexDialect.js +0 -67
- package/dialects/sqlite/SqliteTableCompiler.d.ts +0 -6
- package/dialects/sqlite/SqliteTableCompiler.js +0 -71
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MsSqlKnexDialect = void 0;
|
|
4
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
-
const MsSqlTableCompiler_1 = require("./MsSqlTableCompiler");
|
|
6
|
-
const MsSqlColumnCompiler_1 = require("./MsSqlColumnCompiler");
|
|
7
|
-
const MsSqlQueryCompiler_1 = require("./MsSqlQueryCompiler");
|
|
8
|
-
class MsSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.MsSqlDialect {
|
|
9
|
-
tableCompiler() {
|
|
10
|
-
// eslint-disable-next-line prefer-rest-params
|
|
11
|
-
return new MsSqlTableCompiler_1.MsSqlTableCompiler(this, ...arguments);
|
|
12
|
-
}
|
|
13
|
-
columnCompiler() {
|
|
14
|
-
// eslint-disable-next-line prefer-rest-params
|
|
15
|
-
return new MsSqlColumnCompiler_1.MsSqlColumnCompiler(this, ...arguments);
|
|
16
|
-
}
|
|
17
|
-
queryCompiler() {
|
|
18
|
-
// eslint-disable-next-line prefer-rest-params
|
|
19
|
-
return new MsSqlQueryCompiler_1.MsSqlQueryCompiler(this, ...arguments);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.MsSqlKnexDialect = MsSqlKnexDialect;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
2
|
-
export declare class MsSqlQueryCompiler extends MonkeyPatchable.MsSqlQueryCompiler {
|
|
3
|
-
constructor(client: any, builder: any, formatter: any);
|
|
4
|
-
insert(this: any): any;
|
|
5
|
-
_mergeAnd(this: any): string;
|
|
6
|
-
_mergeWhenMatched(this: any, columns: any, updates: any): string;
|
|
7
|
-
_mergeWhenNotMatched(this: any, columns: any): string;
|
|
8
|
-
_getParameters(this: any, params: any): any;
|
|
9
|
-
_mergeInsertIsEmpty(this: any, insert: any): boolean;
|
|
10
|
-
_mergeOn(this: any, conflict: any): string;
|
|
11
|
-
_insertWithMerge(this: any): string;
|
|
12
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MsSqlQueryCompiler = void 0;
|
|
4
|
-
/* istanbul ignore file */
|
|
5
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
6
|
-
const core_1 = require("@mikro-orm/core");
|
|
7
|
-
// upsert support from https://github.com/knex/knex/pull/6050
|
|
8
|
-
class MsSqlQueryCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlQueryCompiler {
|
|
9
|
-
constructor(client, builder, formatter) {
|
|
10
|
-
const onConflict = builder._single.onConflict;
|
|
11
|
-
delete builder._single.onConflict;
|
|
12
|
-
super(client, builder, formatter);
|
|
13
|
-
this.single.onConflict = onConflict;
|
|
14
|
-
}
|
|
15
|
-
// Compiles an "insert" query, allowing for multiple
|
|
16
|
-
// inserts using a single query statement.
|
|
17
|
-
insert() {
|
|
18
|
-
if (this.single.onConflict) {
|
|
19
|
-
return this._insertWithMerge();
|
|
20
|
-
}
|
|
21
|
-
return super.insert();
|
|
22
|
-
}
|
|
23
|
-
_mergeAnd() {
|
|
24
|
-
const wheres = this.where();
|
|
25
|
-
if (!wheres) {
|
|
26
|
-
return '';
|
|
27
|
-
}
|
|
28
|
-
return `and ${wheres.slice(6)} `;
|
|
29
|
-
}
|
|
30
|
-
_mergeWhenMatched(columns, updates) {
|
|
31
|
-
let columnsData = [];
|
|
32
|
-
if (!updates || Array.isArray(updates)) {
|
|
33
|
-
columnsData = columns
|
|
34
|
-
.map((column) => `${this.formatter.columnize(column)}=tsource.${this.formatter.columnize(column)}`)
|
|
35
|
-
.join(', ');
|
|
36
|
-
}
|
|
37
|
-
if (typeof updates === 'string') {
|
|
38
|
-
columnsData = `${this.formatter.columnize(updates)}=tsource.${this.formatter.columnize(updates)}`;
|
|
39
|
-
}
|
|
40
|
-
if (!Array.isArray(updates) && typeof updates === 'object') {
|
|
41
|
-
columnsData = Object.entries(updates)
|
|
42
|
-
.map(([key, value]) => `${this.tableName}.${this.formatter.columnize(key)}=(${this._getParameters([value])})`);
|
|
43
|
-
}
|
|
44
|
-
const sql = ` when matched ${this._mergeAnd()}then update set ${columnsData}`;
|
|
45
|
-
return sql;
|
|
46
|
-
}
|
|
47
|
-
_mergeWhenNotMatched(columns) {
|
|
48
|
-
const destinationColumns = this.formatter.columnize(columns);
|
|
49
|
-
const sourceColumns = this.formatter.columnizeWithPrefix('tsource.', columns);
|
|
50
|
-
const sql = ` when not matched then insert (${destinationColumns}) values (${sourceColumns})`;
|
|
51
|
-
return sql;
|
|
52
|
-
}
|
|
53
|
-
_getParameters(params) {
|
|
54
|
-
const sql = this.client.parameterize(params, this.client.valueForUndefined, this.builder, this.bindingsHolder);
|
|
55
|
-
return sql;
|
|
56
|
-
}
|
|
57
|
-
_mergeInsertIsEmpty(insert) {
|
|
58
|
-
return (Array.isArray(insert) && insert.length === 0)
|
|
59
|
-
|| (typeof insert === 'object' && core_1.Utils.isEmpty(insert));
|
|
60
|
-
}
|
|
61
|
-
_mergeOn(conflict) {
|
|
62
|
-
let sql = 'on 1=1';
|
|
63
|
-
if (Array.isArray(conflict)) {
|
|
64
|
-
const conflictColumn = this.formatter.columnize(conflict[0]);
|
|
65
|
-
sql = `on ${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`;
|
|
66
|
-
}
|
|
67
|
-
return sql;
|
|
68
|
-
}
|
|
69
|
-
_insertWithMerge() {
|
|
70
|
-
const { insert = [], onConflict, ignore, merge, returning, options = {} } = this.single;
|
|
71
|
-
if (this._mergeInsertIsEmpty(insert)) {
|
|
72
|
-
return '';
|
|
73
|
-
}
|
|
74
|
-
const insertData = this._prepInsert(insert);
|
|
75
|
-
const insertParameters = insertData.values.map((value) => `(${this._getParameters(value)})`).join(', ');
|
|
76
|
-
const sourceColumns = this.formatter.columnize(insertData.columns);
|
|
77
|
-
const returningSql = returning
|
|
78
|
-
? ` ${this._returning('insert', returning, options.includeTriggerModifications)}`
|
|
79
|
-
: '';
|
|
80
|
-
let sql = `merge into ${this.tableName} using (values ${insertParameters}) as tsource(${sourceColumns}) `;
|
|
81
|
-
sql += this._mergeOn(onConflict);
|
|
82
|
-
sql += this._mergeWhenNotMatched(insertData.columns);
|
|
83
|
-
if (!ignore) {
|
|
84
|
-
sql += this._mergeWhenMatched(insertData.columns, merge.updates);
|
|
85
|
-
}
|
|
86
|
-
sql += returningSql;
|
|
87
|
-
if (options.includeTriggerModifications) {
|
|
88
|
-
sql = this._buildTempTable(returning) + sql + this._buildReturningSelect(returning);
|
|
89
|
-
}
|
|
90
|
-
sql = this.with() + sql + ';';
|
|
91
|
-
return sql;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.MsSqlQueryCompiler = MsSqlQueryCompiler;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
2
|
-
export declare class MsSqlTableCompiler extends MonkeyPatchable.MsSqlTableCompiler {
|
|
3
|
-
lowerCase: boolean;
|
|
4
|
-
addColumnsPrefix: string;
|
|
5
|
-
dropColumnPrefix: string;
|
|
6
|
-
alterColumnPrefix: string;
|
|
7
|
-
alterColumns(this: any, columns: any, colBuilder: any): void;
|
|
8
|
-
dropForeign(this: any, columns: any, constraintName: any): void;
|
|
9
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MsSqlTableCompiler = void 0;
|
|
4
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
-
class MsSqlTableCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlTableCompiler {
|
|
6
|
-
lowerCase = true;
|
|
7
|
-
addColumnsPrefix = 'add ';
|
|
8
|
-
dropColumnPrefix = 'drop column ';
|
|
9
|
-
alterColumnPrefix = 'alter column ';
|
|
10
|
-
alterColumns(columns, colBuilder) {
|
|
11
|
-
for (let i = 0, l = colBuilder.length; i < l; i++) {
|
|
12
|
-
const builder = colBuilder[i];
|
|
13
|
-
if (builder.modified.defaultTo) {
|
|
14
|
-
const schema = this.schemaNameRaw || 'dbo';
|
|
15
|
-
const baseQuery = `declare @constraint${i} varchar(100) = (select default_constraints.name from sys.all_columns`
|
|
16
|
-
+ ' join sys.tables on all_columns.object_id = tables.object_id'
|
|
17
|
-
+ ' join sys.schemas on tables.schema_id = schemas.schema_id'
|
|
18
|
-
+ ' join sys.default_constraints on all_columns.default_object_id = default_constraints.object_id'
|
|
19
|
-
+ ` where schemas.name = '${schema}' and tables.name = '${this.tableNameRaw}' and all_columns.name = '${builder.getColumnName()}')`
|
|
20
|
-
+ ` if @constraint${i} is not null exec('alter table ${this.tableNameRaw} drop constraint ' + @constraint${i})`;
|
|
21
|
-
this.pushQuery(baseQuery);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// in SQL server only one column can be altered at a time
|
|
25
|
-
columns.sql.forEach((sql) => {
|
|
26
|
-
this.pushQuery({
|
|
27
|
-
sql: `alter table ${this.tableName()} ${this.alterColumnPrefix.toLowerCase()}${sql}`,
|
|
28
|
-
bindings: columns.bindings,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
dropForeign(columns, constraintName) {
|
|
33
|
-
/* istanbul ignore next */
|
|
34
|
-
constraintName = constraintName
|
|
35
|
-
? this.formatter.wrap(constraintName)
|
|
36
|
-
: this._indexCommand('foreign', this.tableNameRaw, columns);
|
|
37
|
-
this.pushQuery(`alter table ${this.tableName()} drop constraint ${constraintName}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.MsSqlTableCompiler = MsSqlTableCompiler;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MariaDbKnexDialect = void 0;
|
|
4
|
-
const MySqlKnexDialect_1 = require("./MySqlKnexDialect");
|
|
5
|
-
class MariaDbKnexDialect extends MySqlKnexDialect_1.MySqlKnexDialect {
|
|
6
|
-
get driverName() {
|
|
7
|
-
return 'mariadb';
|
|
8
|
-
}
|
|
9
|
-
_driver() {
|
|
10
|
-
return require('mariadb/callback');
|
|
11
|
-
}
|
|
12
|
-
validateConnection(connection) {
|
|
13
|
-
return connection.isValid();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.MariaDbKnexDialect = MariaDbKnexDialect;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BaseMySqlColumnCompiler from 'knex/lib/dialects/mysql/schema/mysql-columncompiler';
|
|
2
|
-
import type { MySqlIncrementOptions } from '../../typings';
|
|
3
|
-
export declare class MySqlColumnCompiler extends BaseMySqlColumnCompiler {
|
|
4
|
-
increments(options: MySqlIncrementOptions): string;
|
|
5
|
-
bigincrements(options: MySqlIncrementOptions): string;
|
|
6
|
-
private generateDDL;
|
|
7
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MySqlColumnCompiler = void 0;
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const mysql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mysql/schema/mysql-columncompiler"));
|
|
9
|
-
class MySqlColumnCompiler extends mysql_columncompiler_1.default {
|
|
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 this.generateDDL(options);
|
|
13
|
-
}
|
|
14
|
-
/* istanbul ignore next */
|
|
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' : '');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.MySqlColumnCompiler = MySqlColumnCompiler;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Knex } from 'knex';
|
|
2
|
-
import { AbstractSqlConnection } from '../../AbstractSqlConnection';
|
|
3
|
-
export declare class MySqlConnection extends AbstractSqlConnection {
|
|
4
|
-
createKnex(): void;
|
|
5
|
-
getDefaultClientUrl(): string;
|
|
6
|
-
getConnectionOptions(): Knex.MySqlConnectionConfig;
|
|
7
|
-
protected transformRawResult<T>(res: any, method: 'all' | 'get' | 'run'): T;
|
|
8
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MySqlConnection = void 0;
|
|
4
|
-
const MySqlKnexDialect_1 = require("./MySqlKnexDialect");
|
|
5
|
-
const AbstractSqlConnection_1 = require("../../AbstractSqlConnection");
|
|
6
|
-
class MySqlConnection extends AbstractSqlConnection_1.AbstractSqlConnection {
|
|
7
|
-
createKnex() {
|
|
8
|
-
this.client = this.createKnexClient(MySqlKnexDialect_1.MySqlKnexDialect);
|
|
9
|
-
this.connected = true;
|
|
10
|
-
}
|
|
11
|
-
getDefaultClientUrl() {
|
|
12
|
-
return 'mysql://root@127.0.0.1:3306';
|
|
13
|
-
}
|
|
14
|
-
getConnectionOptions() {
|
|
15
|
-
const ret = super.getConnectionOptions();
|
|
16
|
-
if (this.config.get('multipleStatements')) {
|
|
17
|
-
ret.multipleStatements = this.config.get('multipleStatements');
|
|
18
|
-
}
|
|
19
|
-
if (this.config.get('forceUtcTimezone')) {
|
|
20
|
-
ret.timezone = 'Z';
|
|
21
|
-
}
|
|
22
|
-
if (this.config.get('timezone')) {
|
|
23
|
-
ret.timezone = this.config.get('timezone');
|
|
24
|
-
}
|
|
25
|
-
ret.supportBigNumbers = true;
|
|
26
|
-
ret.dateStrings = true;
|
|
27
|
-
return ret;
|
|
28
|
-
}
|
|
29
|
-
transformRawResult(res, method) {
|
|
30
|
-
if (method === 'run' && ['OkPacket', 'ResultSetHeader'].includes(res[0].constructor.name)) {
|
|
31
|
-
return {
|
|
32
|
-
insertId: res[0].insertId,
|
|
33
|
-
affectedRows: res[0].affectedRows,
|
|
34
|
-
rows: [],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (method === 'get') {
|
|
38
|
-
return res[0][0];
|
|
39
|
-
}
|
|
40
|
-
return res[0];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.MySqlConnection = MySqlConnection;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MySqlKnexDialect = void 0;
|
|
4
|
-
const MySqlQueryCompiler_1 = require("./MySqlQueryCompiler");
|
|
5
|
-
const MySqlColumnCompiler_1 = require("./MySqlColumnCompiler");
|
|
6
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
7
|
-
class MySqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.MySqlDialect {
|
|
8
|
-
queryCompiler() {
|
|
9
|
-
// eslint-disable-next-line prefer-rest-params
|
|
10
|
-
return new MySqlQueryCompiler_1.MySqlQueryCompiler(this, ...arguments);
|
|
11
|
-
}
|
|
12
|
-
columnCompiler() {
|
|
13
|
-
// eslint-disable-next-line prefer-rest-params
|
|
14
|
-
return new MySqlColumnCompiler_1.MySqlColumnCompiler(this, ...arguments);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.MySqlKnexDialect = MySqlKnexDialect;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MySqlQueryCompiler = void 0;
|
|
7
|
-
/* istanbul ignore file */
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const mysql_querycompiler_1 = __importDefault(require("knex/lib/dialects/mysql/query/mysql-querycompiler"));
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
const querycompiler_1 = __importDefault(require("knex/lib/query/querycompiler"));
|
|
12
|
-
// upsert support from https://github.com/knex/knex/pull/6050
|
|
13
|
-
class MySqlQueryCompiler extends mysql_querycompiler_1.default {
|
|
14
|
-
// mysql dialect disallows query non scalar params, but we dont use it to execute the query, it always goes through the `platform.formatQuery()`
|
|
15
|
-
whereBasic(statement) {
|
|
16
|
-
return querycompiler_1.default.prototype.whereBasic.call(this, statement);
|
|
17
|
-
}
|
|
18
|
-
// mysql dialect disallows query non scalar params, but we dont use it to execute the query, it always goes through the `platform.formatQuery()`
|
|
19
|
-
whereRaw(statement) {
|
|
20
|
-
return querycompiler_1.default.prototype.whereRaw.call(this, statement);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.MySqlQueryCompiler = MySqlQueryCompiler;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Configuration } from '@mikro-orm/core';
|
|
2
|
-
import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
3
|
-
export declare class PostgreSqlKnexDialect extends MonkeyPatchable.PostgresDialect {
|
|
4
|
-
ormConfig: Configuration;
|
|
5
|
-
tableCompiler(): any;
|
|
6
|
-
queryCompiler(): any;
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgreSqlKnexDialect = void 0;
|
|
4
|
-
const PostgreSqlTableCompiler_1 = require("./PostgreSqlTableCompiler");
|
|
5
|
-
const PostgreSqlQueryCompiler_1 = require("./PostgreSqlQueryCompiler");
|
|
6
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
7
|
-
class PostgreSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.PostgresDialect {
|
|
8
|
-
ormConfig;
|
|
9
|
-
tableCompiler() {
|
|
10
|
-
// eslint-disable-next-line prefer-rest-params
|
|
11
|
-
const tableCompiler = new PostgreSqlTableCompiler_1.PostgreSqlTableCompiler(this, ...arguments);
|
|
12
|
-
tableCompiler.ormConfig = this.ormConfig;
|
|
13
|
-
return tableCompiler;
|
|
14
|
-
}
|
|
15
|
-
queryCompiler() {
|
|
16
|
-
// eslint-disable-next-line prefer-rest-params
|
|
17
|
-
return new PostgreSqlQueryCompiler_1.PostgreSqlQueryCompiler(this, ...arguments);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.PostgreSqlKnexDialect = PostgreSqlKnexDialect;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgreSqlQueryCompiler = void 0;
|
|
4
|
-
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
-
class PostgreSqlQueryCompiler extends MonkeyPatchable_1.MonkeyPatchable.PostgresQueryCompiler {
|
|
6
|
-
_lockingClause(lockMode) {
|
|
7
|
-
const tables = this.single.lockTables || [];
|
|
8
|
-
return lockMode + (tables.length
|
|
9
|
-
? ' of ' + tables.filter(Boolean).map((table) => this.formatter.wrap(table)).join(', ')
|
|
10
|
-
: '');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.PostgreSqlQueryCompiler = PostgreSqlQueryCompiler;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import PostgresDialectTableCompiler from 'knex/lib/dialects/postgres/schema/pg-tablecompiler';
|
|
2
|
-
import type { Configuration, Dictionary } from '@mikro-orm/core';
|
|
3
|
-
export declare class PostgreSqlTableCompiler extends PostgresDialectTableCompiler {
|
|
4
|
-
ormConfig: Configuration;
|
|
5
|
-
alterColumnsPrefix: string;
|
|
6
|
-
addColumns(columns: Dictionary[], prefix: string, colCompilers: Dictionary[]): any;
|
|
7
|
-
private addColumn;
|
|
8
|
-
private alterColumnNullable;
|
|
9
|
-
private addColumnDefault;
|
|
10
|
-
private dropColumnDefault;
|
|
11
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PostgreSqlTableCompiler = void 0;
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const pg_tablecompiler_1 = __importDefault(require("knex/lib/dialects/postgres/schema/pg-tablecompiler"));
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const tablecompiler_1 = __importDefault(require("knex/lib/schema/tablecompiler"));
|
|
11
|
-
class PostgreSqlTableCompiler extends pg_tablecompiler_1.default {
|
|
12
|
-
ormConfig;
|
|
13
|
-
addColumns(columns, prefix, colCompilers) {
|
|
14
|
-
if (prefix !== this.alterColumnsPrefix) {
|
|
15
|
-
// base class implementation for normal add
|
|
16
|
-
return tablecompiler_1.default.prototype.addColumns.call(this, columns, prefix);
|
|
17
|
-
}
|
|
18
|
-
// alter columns
|
|
19
|
-
for (const col of colCompilers) {
|
|
20
|
-
this.addColumn(col);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
addColumn(col) {
|
|
24
|
-
const options = this.ormConfig.get('schemaGenerator');
|
|
25
|
-
const quotedTableName = this.tableName();
|
|
26
|
-
const type = col.getColumnType();
|
|
27
|
-
const colName = this.client.wrapIdentifier(col.getColumnName(), col.columnBuilder.queryContext());
|
|
28
|
-
const constraintName = `${this.tableNameRaw.replace(/^.*\.(.*)$/, '$1')}_${col.getColumnName()}_check`;
|
|
29
|
-
const useNative = col.args?.[2]?.useNative;
|
|
30
|
-
const alterType = col.columnBuilder.alterType;
|
|
31
|
-
const alterNullable = col.columnBuilder.alterNullable;
|
|
32
|
-
const defaultTo = col.modified.defaultTo;
|
|
33
|
-
if (defaultTo != null) {
|
|
34
|
-
this.dropColumnDefault(col, colName);
|
|
35
|
-
}
|
|
36
|
-
/* istanbul ignore next */
|
|
37
|
-
if (col.type === 'enu' && !useNative) {
|
|
38
|
-
if (alterType) {
|
|
39
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} type text using (${colName}::text)`, bindings: [] });
|
|
40
|
-
}
|
|
41
|
-
/* istanbul ignore else */
|
|
42
|
-
if (options.createForeignKeyConstraints && alterNullable) {
|
|
43
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} add constraint "${constraintName}" ${type.replace(/^text /, '')}`, bindings: [] });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else if (type === 'uuid') {
|
|
47
|
-
// we need to drop the default as it would be invalid
|
|
48
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} drop default`, bindings: [] });
|
|
49
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} type ${type} using (${colName}::text::uuid)`, bindings: [] });
|
|
50
|
-
}
|
|
51
|
-
else if (alterType) {
|
|
52
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} type ${type} using (${colName}::${type})`, bindings: [] });
|
|
53
|
-
}
|
|
54
|
-
this.addColumnDefault(col, colName);
|
|
55
|
-
this.alterColumnNullable(col, colName);
|
|
56
|
-
}
|
|
57
|
-
alterColumnNullable(col, colName) {
|
|
58
|
-
const quotedTableName = this.tableName();
|
|
59
|
-
const nullable = col.modified.nullable;
|
|
60
|
-
if (!nullable) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (nullable[0] === false) {
|
|
64
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} set not null`, bindings: [] });
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} drop not null`, bindings: [] });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
addColumnDefault(col, colName) {
|
|
71
|
-
const quotedTableName = this.tableName();
|
|
72
|
-
const defaultTo = col.modified.defaultTo;
|
|
73
|
-
if (!defaultTo) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (defaultTo[0] !== null) {
|
|
77
|
-
const modifier = col.defaultTo(...defaultTo);
|
|
78
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} set ${modifier}`, bindings: [] });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
dropColumnDefault(col, colName) {
|
|
82
|
-
const quotedTableName = this.tableName();
|
|
83
|
-
const defaultTo = col.modified.defaultTo;
|
|
84
|
-
if (defaultTo?.[0] == null) {
|
|
85
|
-
this.pushQuery({ sql: `alter table ${quotedTableName} alter column ${colName} drop default`, bindings: [] });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.PostgreSqlTableCompiler = PostgreSqlTableCompiler;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Connection, Dictionary } from '@mikro-orm/core';
|
|
2
|
-
import type { AbstractSqlConnection } from '../../AbstractSqlConnection';
|
|
3
|
-
import { SchemaHelper } from '../../schema/SchemaHelper';
|
|
4
|
-
import type { CheckDef, Column, IndexDef, TableDifference } from '../../typings';
|
|
5
|
-
export declare abstract class BaseSqliteSchemaHelper extends SchemaHelper {
|
|
6
|
-
disableForeignKeysSQL(): string;
|
|
7
|
-
enableForeignKeysSQL(): string;
|
|
8
|
-
supportsSchemaConstraints(): boolean;
|
|
9
|
-
getListTablesSQL(): string;
|
|
10
|
-
getDropDatabaseSQL(name: string): string;
|
|
11
|
-
getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
|
|
12
|
-
private parseTableDefinition;
|
|
13
|
-
getColumns(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<any[]>;
|
|
14
|
-
getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName: string, schemaName: string): Promise<Dictionary<string[]>>;
|
|
15
|
-
getPrimaryKeys(connection: AbstractSqlConnection, indexes: IndexDef[], tableName: string, schemaName?: string): Promise<string[]>;
|
|
16
|
-
getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<IndexDef[]>;
|
|
17
|
-
getChecks(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<CheckDef[]>;
|
|
18
|
-
getForeignKeysSQL(tableName: string): string;
|
|
19
|
-
mapForeignKeys(fks: any[], tableName: string): Dictionary;
|
|
20
|
-
getManagementDbName(): string;
|
|
21
|
-
getCreateDatabaseSQL(name: string): string;
|
|
22
|
-
databaseExists(connection: Connection, name: string): Promise<boolean>;
|
|
23
|
-
/**
|
|
24
|
-
* Implicit indexes will be ignored when diffing
|
|
25
|
-
*/
|
|
26
|
-
isImplicitIndex(name: string): boolean;
|
|
27
|
-
getAlterTable(changedTable: TableDifference, wrap?: boolean): Promise<string>;
|
|
28
|
-
}
|