@yandjin-mikro-orm/mysql 6.1.4-rc-sti-changes-1
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/LICENSE +21 -0
- package/MySqlConnection.d.ts +8 -0
- package/MySqlConnection.js +60 -0
- package/MySqlDriver.d.ts +10 -0
- package/MySqlDriver.js +36 -0
- package/MySqlExceptionConverter.d.ts +9 -0
- package/MySqlExceptionConverter.js +83 -0
- package/MySqlMikroORM.d.ts +19 -0
- package/MySqlMikroORM.js +29 -0
- package/MySqlPlatform.d.ts +25 -0
- package/MySqlPlatform.js +89 -0
- package/MySqlSchemaHelper.d.ts +38 -0
- package/MySqlSchemaHelper.js +320 -0
- package/README.md +383 -0
- package/index.d.ts +7 -0
- package/index.js +26 -0
- package/index.mjs +220 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Martin Adámek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractSqlConnection, type Knex } from "@yandjin-mikro-orm/knex";
|
|
2
|
+
export declare class MySqlConnection extends AbstractSqlConnection {
|
|
3
|
+
createKnex(): void;
|
|
4
|
+
private patchKnex;
|
|
5
|
+
getDefaultClientUrl(): string;
|
|
6
|
+
getConnectionOptions(): Knex.MySqlConnectionConfig;
|
|
7
|
+
protected transformRawResult<T>(res: any, method: "all" | "get" | "run"): T;
|
|
8
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlConnection = void 0;
|
|
4
|
+
const knex_1 = require("@yandjin-mikro-orm/knex");
|
|
5
|
+
class MySqlConnection extends knex_1.AbstractSqlConnection {
|
|
6
|
+
createKnex() {
|
|
7
|
+
this.patchKnex();
|
|
8
|
+
this.client = this.createKnexClient("mysql2");
|
|
9
|
+
this.connected = true;
|
|
10
|
+
}
|
|
11
|
+
patchKnex() {
|
|
12
|
+
const { MySqlColumnCompiler, MySqlQueryCompiler } = knex_1.MonkeyPatchable;
|
|
13
|
+
// we need the old behaviour to be able to add auto_increment to a column that is already PK
|
|
14
|
+
MySqlColumnCompiler.prototype.increments = function (options = { primaryKey: true }) {
|
|
15
|
+
return ("int unsigned not null auto_increment" +
|
|
16
|
+
(this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : ""));
|
|
17
|
+
};
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
MySqlColumnCompiler.prototype.bigincrements = function (options = { primaryKey: true }) {
|
|
20
|
+
return ("bigint unsigned not null auto_increment" +
|
|
21
|
+
(this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : ""));
|
|
22
|
+
};
|
|
23
|
+
// mysql dialect disallows query non scalar params, but we dont use it to execute the query, it always goes through the `platform.formatQuery()`
|
|
24
|
+
delete MySqlQueryCompiler.prototype.whereBasic;
|
|
25
|
+
delete MySqlQueryCompiler.prototype.whereRaw;
|
|
26
|
+
}
|
|
27
|
+
getDefaultClientUrl() {
|
|
28
|
+
return "mysql://root@127.0.0.1:3306";
|
|
29
|
+
}
|
|
30
|
+
getConnectionOptions() {
|
|
31
|
+
const ret = super.getConnectionOptions();
|
|
32
|
+
if (this.config.get("multipleStatements")) {
|
|
33
|
+
ret.multipleStatements = this.config.get("multipleStatements");
|
|
34
|
+
}
|
|
35
|
+
if (this.config.get("forceUtcTimezone")) {
|
|
36
|
+
ret.timezone = "Z";
|
|
37
|
+
}
|
|
38
|
+
if (this.config.get("timezone")) {
|
|
39
|
+
ret.timezone = this.config.get("timezone");
|
|
40
|
+
}
|
|
41
|
+
ret.supportBigNumbers = true;
|
|
42
|
+
ret.dateStrings = true;
|
|
43
|
+
return ret;
|
|
44
|
+
}
|
|
45
|
+
transformRawResult(res, method) {
|
|
46
|
+
if (method === "run" &&
|
|
47
|
+
["OkPacket", "ResultSetHeader"].includes(res[0].constructor.name)) {
|
|
48
|
+
return {
|
|
49
|
+
insertId: res[0].insertId,
|
|
50
|
+
affectedRows: res[0].affectedRows,
|
|
51
|
+
rows: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (method === "get") {
|
|
55
|
+
return res[0][0];
|
|
56
|
+
}
|
|
57
|
+
return res[0];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.MySqlConnection = MySqlConnection;
|
package/MySqlDriver.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Configuration, EntityDictionary, NativeInsertUpdateManyOptions, QueryResult } from "@yandjin-mikro-orm/core";
|
|
2
|
+
import { AbstractSqlDriver } from "@yandjin-mikro-orm/knex";
|
|
3
|
+
import { MySqlConnection } from "./MySqlConnection";
|
|
4
|
+
import { MySqlPlatform } from "./MySqlPlatform";
|
|
5
|
+
export declare class MySqlDriver extends AbstractSqlDriver<MySqlConnection, MySqlPlatform> {
|
|
6
|
+
protected autoIncrementIncrement?: number;
|
|
7
|
+
constructor(config: Configuration);
|
|
8
|
+
private getAutoIncrementIncrement;
|
|
9
|
+
nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
10
|
+
}
|
package/MySqlDriver.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlDriver = void 0;
|
|
4
|
+
const knex_1 = require("@yandjin-mikro-orm/knex");
|
|
5
|
+
const MySqlConnection_1 = require("./MySqlConnection");
|
|
6
|
+
const MySqlPlatform_1 = require("./MySqlPlatform");
|
|
7
|
+
class MySqlDriver extends knex_1.AbstractSqlDriver {
|
|
8
|
+
autoIncrementIncrement;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config, new MySqlPlatform_1.MySqlPlatform(), MySqlConnection_1.MySqlConnection, ["knex", "mysql2"]);
|
|
11
|
+
}
|
|
12
|
+
async getAutoIncrementIncrement() {
|
|
13
|
+
if (this.autoIncrementIncrement == null) {
|
|
14
|
+
// the increment step may differ when running a cluster, see https://github.com/mikro-orm/mikro-orm/issues/3828
|
|
15
|
+
const res = await this.connection.execute(`show variables like 'auto_increment_increment'`, [], "get", undefined, { enabled: false });
|
|
16
|
+
/* istanbul ignore next */
|
|
17
|
+
this.autoIncrementIncrement = res?.auto_increment_increment
|
|
18
|
+
? +res?.auto_increment_increment
|
|
19
|
+
: 1;
|
|
20
|
+
}
|
|
21
|
+
return this.autoIncrementIncrement;
|
|
22
|
+
}
|
|
23
|
+
async nativeInsertMany(entityName, data, options = {}) {
|
|
24
|
+
options.processCollections ??= true;
|
|
25
|
+
const res = await super.nativeInsertMany(entityName, data, options);
|
|
26
|
+
const pks = this.getPrimaryKeyFields(entityName);
|
|
27
|
+
const autoIncrementIncrement = await this.getAutoIncrementIncrement();
|
|
28
|
+
data.forEach((item, idx) => (res.rows[idx] = {
|
|
29
|
+
[pks[0]]: item[pks[0]] ??
|
|
30
|
+
res.insertId + idx * autoIncrementIncrement,
|
|
31
|
+
}));
|
|
32
|
+
res.row = res.rows[0];
|
|
33
|
+
return res;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.MySqlDriver = MySqlDriver;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExceptionConverter, type Dictionary, type DriverException } from "@yandjin-mikro-orm/core";
|
|
2
|
+
export declare class MySqlExceptionConverter extends ExceptionConverter {
|
|
3
|
+
/**
|
|
4
|
+
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
|
|
5
|
+
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
|
|
6
|
+
* @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
|
|
7
|
+
*/
|
|
8
|
+
convertException(exception: Error & Dictionary): DriverException;
|
|
9
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlExceptionConverter = void 0;
|
|
4
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
5
|
+
class MySqlExceptionConverter extends core_1.ExceptionConverter {
|
|
6
|
+
/* istanbul ignore next */
|
|
7
|
+
/**
|
|
8
|
+
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
|
|
9
|
+
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
|
|
10
|
+
* @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
|
|
11
|
+
*/
|
|
12
|
+
convertException(exception) {
|
|
13
|
+
switch (exception.errno) {
|
|
14
|
+
case 1213:
|
|
15
|
+
return new core_1.DeadlockException(exception);
|
|
16
|
+
case 1205:
|
|
17
|
+
return new core_1.LockWaitTimeoutException(exception);
|
|
18
|
+
case 1050:
|
|
19
|
+
return new core_1.TableExistsException(exception);
|
|
20
|
+
case 1051:
|
|
21
|
+
case 1146:
|
|
22
|
+
return new core_1.TableNotFoundException(exception);
|
|
23
|
+
case 1216:
|
|
24
|
+
case 1217:
|
|
25
|
+
case 1451:
|
|
26
|
+
case 1452:
|
|
27
|
+
case 1701:
|
|
28
|
+
return new core_1.ForeignKeyConstraintViolationException(exception);
|
|
29
|
+
case 3819:
|
|
30
|
+
return new core_1.CheckConstraintViolationException(exception);
|
|
31
|
+
case 1062:
|
|
32
|
+
case 1557:
|
|
33
|
+
case 1569:
|
|
34
|
+
case 1586:
|
|
35
|
+
return new core_1.UniqueConstraintViolationException(exception);
|
|
36
|
+
case 1054:
|
|
37
|
+
case 1166:
|
|
38
|
+
case 1611:
|
|
39
|
+
return new core_1.InvalidFieldNameException(exception);
|
|
40
|
+
case 1052:
|
|
41
|
+
case 1060:
|
|
42
|
+
case 1110:
|
|
43
|
+
return new core_1.NonUniqueFieldNameException(exception);
|
|
44
|
+
case 1064:
|
|
45
|
+
case 1149:
|
|
46
|
+
case 1287:
|
|
47
|
+
case 1341:
|
|
48
|
+
case 1342:
|
|
49
|
+
case 1343:
|
|
50
|
+
case 1344:
|
|
51
|
+
case 1382:
|
|
52
|
+
case 1479:
|
|
53
|
+
case 1541:
|
|
54
|
+
case 1554:
|
|
55
|
+
case 1626:
|
|
56
|
+
return new core_1.SyntaxErrorException(exception);
|
|
57
|
+
case 1044:
|
|
58
|
+
case 1045:
|
|
59
|
+
case 1046:
|
|
60
|
+
case 1049:
|
|
61
|
+
case 1095:
|
|
62
|
+
case 1142:
|
|
63
|
+
case 1143:
|
|
64
|
+
case 1227:
|
|
65
|
+
case 1370:
|
|
66
|
+
case 1429:
|
|
67
|
+
case 2002:
|
|
68
|
+
case 2005:
|
|
69
|
+
return new core_1.ConnectionException(exception);
|
|
70
|
+
case 1048:
|
|
71
|
+
case 1121:
|
|
72
|
+
case 1138:
|
|
73
|
+
case 1171:
|
|
74
|
+
case 1252:
|
|
75
|
+
case 1263:
|
|
76
|
+
case 1364:
|
|
77
|
+
case 1566:
|
|
78
|
+
return new core_1.NotNullConstraintViolationException(exception);
|
|
79
|
+
}
|
|
80
|
+
return super.convertException(exception);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.MySqlExceptionConverter = MySqlExceptionConverter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from "@yandjin-mikro-orm/core";
|
|
2
|
+
import { MySqlDriver } from "./MySqlDriver";
|
|
3
|
+
import type { SqlEntityManager } from "@yandjin-mikro-orm/knex";
|
|
4
|
+
/**
|
|
5
|
+
* @inheritDoc
|
|
6
|
+
*/
|
|
7
|
+
export declare class MySqlMikroORM<EM extends EntityManager = SqlEntityManager> extends MikroORM<MySqlDriver, EM> {
|
|
8
|
+
private static DRIVER;
|
|
9
|
+
/**
|
|
10
|
+
* @inheritDoc
|
|
11
|
+
*/
|
|
12
|
+
static init<D extends IDatabaseDriver = MySqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options?: Options<D, EM>): Promise<MikroORM<D, EM>>;
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
static initSync<D extends IDatabaseDriver = MySqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
|
|
17
|
+
}
|
|
18
|
+
export type MySqlOptions = Options<MySqlDriver>;
|
|
19
|
+
export declare function defineMySqlConfig(options: MySqlOptions): Options<MySqlDriver, SqlEntityManager<MySqlDriver> & EntityManager<IDatabaseDriver<import("@yandjin-mikro-orm/core").Connection>>>;
|
package/MySqlMikroORM.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineMySqlConfig = exports.MySqlMikroORM = void 0;
|
|
4
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
5
|
+
const MySqlDriver_1 = require("./MySqlDriver");
|
|
6
|
+
/**
|
|
7
|
+
* @inheritDoc
|
|
8
|
+
*/
|
|
9
|
+
class MySqlMikroORM extends core_1.MikroORM {
|
|
10
|
+
static DRIVER = MySqlDriver_1.MySqlDriver;
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
static async init(options) {
|
|
15
|
+
return super.init(options);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static initSync(options) {
|
|
21
|
+
return super.initSync(options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MySqlMikroORM = MySqlMikroORM;
|
|
25
|
+
/* istanbul ignore next */
|
|
26
|
+
function defineMySqlConfig(options) {
|
|
27
|
+
return (0, core_1.defineConfig)({ driver: MySqlDriver_1.MySqlDriver, ...options });
|
|
28
|
+
}
|
|
29
|
+
exports.defineMySqlConfig = defineMySqlConfig;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AbstractSqlPlatform, type IndexDef } from "@yandjin-mikro-orm/knex";
|
|
2
|
+
import { MySqlSchemaHelper } from "./MySqlSchemaHelper";
|
|
3
|
+
import { MySqlExceptionConverter } from "./MySqlExceptionConverter";
|
|
4
|
+
import { type SimpleColumnMeta, type Type, type TransformContext } from "@yandjin-mikro-orm/core";
|
|
5
|
+
export declare class MySqlPlatform extends AbstractSqlPlatform {
|
|
6
|
+
protected readonly schemaHelper: MySqlSchemaHelper;
|
|
7
|
+
protected readonly exceptionConverter: MySqlExceptionConverter;
|
|
8
|
+
getDefaultCharset(): string;
|
|
9
|
+
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
10
|
+
getJsonIndexDefinition(index: IndexDef): string[];
|
|
11
|
+
getBooleanTypeDeclarationSQL(): string;
|
|
12
|
+
getDefaultMappedType(type: string): Type<unknown>;
|
|
13
|
+
supportsUnsigned(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the default name of index for the given columns
|
|
16
|
+
* cannot go past 64 character length for identifiers in MySQL
|
|
17
|
+
*/
|
|
18
|
+
getIndexName(tableName: string, columns: string[], type: "index" | "unique" | "foreign" | "primary" | "sequence"): string;
|
|
19
|
+
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
20
|
+
supportsCreatingFullTextIndex(): boolean;
|
|
21
|
+
getFullTextWhereClause(): string;
|
|
22
|
+
getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
|
|
23
|
+
private readonly ORDER_BY_NULLS_TRANSLATE;
|
|
24
|
+
getOrderByExpression(column: string, direction: string): string[];
|
|
25
|
+
}
|
package/MySqlPlatform.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlPlatform = void 0;
|
|
4
|
+
const knex_1 = require("@yandjin-mikro-orm/knex");
|
|
5
|
+
const MySqlSchemaHelper_1 = require("./MySqlSchemaHelper");
|
|
6
|
+
const MySqlExceptionConverter_1 = require("./MySqlExceptionConverter");
|
|
7
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
8
|
+
class MySqlPlatform extends knex_1.AbstractSqlPlatform {
|
|
9
|
+
schemaHelper = new MySqlSchemaHelper_1.MySqlSchemaHelper(this);
|
|
10
|
+
exceptionConverter = new MySqlExceptionConverter_1.MySqlExceptionConverter();
|
|
11
|
+
getDefaultCharset() {
|
|
12
|
+
return "utf8mb4";
|
|
13
|
+
}
|
|
14
|
+
convertJsonToDatabaseValue(value, context) {
|
|
15
|
+
if (context?.mode === "query") {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return JSON.stringify(value);
|
|
19
|
+
}
|
|
20
|
+
getJsonIndexDefinition(index) {
|
|
21
|
+
return index.columnNames.map((column) => {
|
|
22
|
+
const [root, ...path] = column.split(".");
|
|
23
|
+
return `json_value(${this.quoteIdentifier(root)}, '$.${path.join(".")}' returning ${index.options?.returning ?? "char(255)"})`;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
getBooleanTypeDeclarationSQL() {
|
|
27
|
+
return "tinyint(1)";
|
|
28
|
+
}
|
|
29
|
+
getDefaultMappedType(type) {
|
|
30
|
+
if (type === "tinyint(1)") {
|
|
31
|
+
return super.getDefaultMappedType("boolean");
|
|
32
|
+
}
|
|
33
|
+
const normalizedType = this.extractSimpleType(type);
|
|
34
|
+
const map = {
|
|
35
|
+
int: "integer",
|
|
36
|
+
timestamp: "datetime",
|
|
37
|
+
};
|
|
38
|
+
return super.getDefaultMappedType(map[normalizedType] ?? type);
|
|
39
|
+
}
|
|
40
|
+
supportsUnsigned() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the default name of index for the given columns
|
|
45
|
+
* cannot go past 64 character length for identifiers in MySQL
|
|
46
|
+
*/
|
|
47
|
+
getIndexName(tableName, columns, type) {
|
|
48
|
+
if (type === "primary") {
|
|
49
|
+
return this.getDefaultPrimaryName(tableName, columns);
|
|
50
|
+
}
|
|
51
|
+
const indexName = super.getIndexName(tableName, columns, type);
|
|
52
|
+
if (indexName.length > 64) {
|
|
53
|
+
return `${indexName.substring(0, 56 - type.length)}_${core_1.Utils.hash(indexName, 5)}_${type}`;
|
|
54
|
+
}
|
|
55
|
+
return indexName;
|
|
56
|
+
}
|
|
57
|
+
getDefaultPrimaryName(tableName, columns) {
|
|
58
|
+
return "PRIMARY"; // https://dev.mysql.com/doc/refman/8.0/en/create-table.html#create-table-indexes-keys
|
|
59
|
+
}
|
|
60
|
+
supportsCreatingFullTextIndex() {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
getFullTextWhereClause() {
|
|
64
|
+
return `match(:column:) against (:query in boolean mode)`;
|
|
65
|
+
}
|
|
66
|
+
getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
|
|
67
|
+
/* istanbul ignore next */
|
|
68
|
+
const quotedTableName = this.quoteIdentifier(schemaName ? `${schemaName}.${tableName}` : tableName);
|
|
69
|
+
const quotedColumnNames = columns.map((c) => this.quoteIdentifier(c.name));
|
|
70
|
+
const quotedIndexName = this.quoteIdentifier(indexName);
|
|
71
|
+
return `alter table ${quotedTableName} add fulltext index ${quotedIndexName}(${quotedColumnNames.join(",")})`;
|
|
72
|
+
}
|
|
73
|
+
ORDER_BY_NULLS_TRANSLATE = {
|
|
74
|
+
[knex_1.QueryOrder.asc_nulls_first]: "is not null",
|
|
75
|
+
[knex_1.QueryOrder.asc_nulls_last]: "is null",
|
|
76
|
+
[knex_1.QueryOrder.desc_nulls_first]: "is not null",
|
|
77
|
+
[knex_1.QueryOrder.desc_nulls_last]: "is null",
|
|
78
|
+
};
|
|
79
|
+
getOrderByExpression(column, direction) {
|
|
80
|
+
const ret = [];
|
|
81
|
+
const dir = direction.toLowerCase();
|
|
82
|
+
if (dir in this.ORDER_BY_NULLS_TRANSLATE) {
|
|
83
|
+
ret.push(`${column} ${this.ORDER_BY_NULLS_TRANSLATE[dir]}`);
|
|
84
|
+
}
|
|
85
|
+
ret.push(`${column} ${dir.replace(/(\s|nulls|first|last)*/gi, "")}`);
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.MySqlPlatform = MySqlPlatform;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SchemaHelper, type AbstractSqlConnection, type CheckDef, type Column, type IndexDef, type Knex, type TableDifference, type DatabaseTable, type DatabaseSchema, type Table, type ForeignKey } from "@yandjin-mikro-orm/knex";
|
|
2
|
+
import { type Dictionary, type Type } from "@yandjin-mikro-orm/core";
|
|
3
|
+
export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
4
|
+
private readonly _cache;
|
|
5
|
+
static readonly DEFAULT_VALUES: {
|
|
6
|
+
"now()": string[];
|
|
7
|
+
"current_timestamp(?)": string[];
|
|
8
|
+
"0": string[];
|
|
9
|
+
};
|
|
10
|
+
getSchemaBeginning(charset: string): string;
|
|
11
|
+
disableForeignKeysSQL(): string;
|
|
12
|
+
enableForeignKeysSQL(): string;
|
|
13
|
+
finalizeTable(table: Knex.CreateTableBuilder, charset: string, collate?: string): void;
|
|
14
|
+
getListTablesSQL(): string;
|
|
15
|
+
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
|
|
16
|
+
getAllIndexes(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<IndexDef[]>>;
|
|
17
|
+
getAllColumns(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Column[]>>;
|
|
18
|
+
getAllChecks(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<CheckDef[]>>;
|
|
19
|
+
getAllForeignKeys(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
20
|
+
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
|
21
|
+
configureColumnDefault(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
22
|
+
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column): string;
|
|
23
|
+
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
|
|
24
|
+
getChangeColumnCommentSQL(tableName: string, to: Column, schemaName?: string): string;
|
|
25
|
+
createTableColumn(table: Knex.TableBuilder, column: Column, fromTable: DatabaseTable, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
26
|
+
configureColumn(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
27
|
+
private getColumnDeclarationSQL;
|
|
28
|
+
getForeignKeysSQL(tableName: string, schemaName?: string): string;
|
|
29
|
+
getAllEnumDefinitions(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<string[]>>>;
|
|
30
|
+
private supportsCheckConstraints;
|
|
31
|
+
private getChecksSQL;
|
|
32
|
+
getChecks(connection: AbstractSqlConnection, tableName: string, schemaName: string, columns?: Column[]): Promise<CheckDef[]>;
|
|
33
|
+
getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName: string, schemaName?: string): Promise<Dictionary<string[]>>;
|
|
34
|
+
getColumns(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Column[]>;
|
|
35
|
+
getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<IndexDef[]>;
|
|
36
|
+
normalizeDefaultValue(defaultValue: string, length: number): string | number;
|
|
37
|
+
protected wrap(val: string | undefined, type: Type<unknown>): string | undefined;
|
|
38
|
+
}
|