@yandjin-mikro-orm/knex 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/AbstractSqlConnection.d.ts +58 -0
- package/AbstractSqlConnection.js +206 -0
- package/AbstractSqlDriver.d.ts +73 -0
- package/AbstractSqlDriver.js +1378 -0
- package/AbstractSqlPlatform.d.ts +25 -0
- package/AbstractSqlPlatform.js +86 -0
- package/LICENSE +21 -0
- package/MonkeyPatchable.d.ts +11 -0
- package/MonkeyPatchable.js +39 -0
- package/PivotCollectionPersister.d.ts +17 -0
- package/PivotCollectionPersister.js +131 -0
- package/README.md +383 -0
- package/SqlEntityManager.d.ts +25 -0
- package/SqlEntityManager.js +40 -0
- package/SqlEntityRepository.d.ts +24 -0
- package/SqlEntityRepository.js +36 -0
- package/index.d.ts +18 -0
- package/index.js +40 -0
- package/index.mjs +215 -0
- package/package.json +71 -0
- package/query/ArrayCriteriaNode.d.ts +10 -0
- package/query/ArrayCriteriaNode.js +25 -0
- package/query/CriteriaNode.d.ts +31 -0
- package/query/CriteriaNode.js +147 -0
- package/query/CriteriaNodeFactory.d.ts +12 -0
- package/query/CriteriaNodeFactory.js +90 -0
- package/query/ObjectCriteriaNode.d.ts +15 -0
- package/query/ObjectCriteriaNode.js +233 -0
- package/query/QueryBuilder.d.ts +291 -0
- package/query/QueryBuilder.js +1445 -0
- package/query/QueryBuilderHelper.d.ts +64 -0
- package/query/QueryBuilderHelper.js +747 -0
- package/query/ScalarCriteriaNode.d.ts +10 -0
- package/query/ScalarCriteriaNode.js +56 -0
- package/query/enums.d.ts +15 -0
- package/query/enums.js +20 -0
- package/query/index.d.ts +8 -0
- package/query/index.js +24 -0
- package/schema/DatabaseSchema.d.ts +29 -0
- package/schema/DatabaseSchema.js +140 -0
- package/schema/DatabaseTable.d.ts +61 -0
- package/schema/DatabaseTable.js +727 -0
- package/schema/SchemaComparator.d.ts +59 -0
- package/schema/SchemaComparator.js +603 -0
- package/schema/SchemaHelper.d.ts +56 -0
- package/schema/SchemaHelper.js +274 -0
- package/schema/SqlSchemaGenerator.d.ts +63 -0
- package/schema/SqlSchemaGenerator.js +598 -0
- package/schema/index.d.ts +5 -0
- package/schema/index.js +21 -0
- package/typings.d.ts +174 -0
- package/typings.js +2 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Platform, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type MikroORM } from "@yandjin-mikro-orm/core";
|
|
2
|
+
import { SqlSchemaGenerator, type SchemaHelper } from "./schema";
|
|
3
|
+
import type { IndexDef } from "./typings";
|
|
4
|
+
export declare abstract class AbstractSqlPlatform extends Platform {
|
|
5
|
+
protected readonly schemaHelper?: SchemaHelper;
|
|
6
|
+
usesPivotTable(): boolean;
|
|
7
|
+
indexForeignKeys(): boolean;
|
|
8
|
+
getRepositoryClass<T extends object>(): Constructor<EntityRepository<T>>;
|
|
9
|
+
getSchemaHelper(): SchemaHelper | undefined;
|
|
10
|
+
/** @inheritDoc */
|
|
11
|
+
lookupExtensions(orm: MikroORM): void;
|
|
12
|
+
getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): SqlSchemaGenerator;
|
|
13
|
+
quoteValue(value: any): string;
|
|
14
|
+
getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string;
|
|
15
|
+
getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string;
|
|
16
|
+
getJsonIndexDefinition(index: IndexDef): string[];
|
|
17
|
+
isRaw(value: any): boolean;
|
|
18
|
+
supportsSchemas(): boolean;
|
|
19
|
+
/** @inheritDoc */
|
|
20
|
+
generateCustomOrder(escapedColumn: string, values: unknown[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
getOrderByExpression(column: string, direction: string): string[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractSqlPlatform = void 0;
|
|
4
|
+
const sqlstring_1 = require("sqlstring");
|
|
5
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
6
|
+
const SqlEntityRepository_1 = require("./SqlEntityRepository");
|
|
7
|
+
const schema_1 = require("./schema");
|
|
8
|
+
class AbstractSqlPlatform extends core_1.Platform {
|
|
9
|
+
schemaHelper;
|
|
10
|
+
usesPivotTable() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
indexForeignKeys() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
getRepositoryClass() {
|
|
17
|
+
return SqlEntityRepository_1.SqlEntityRepository;
|
|
18
|
+
}
|
|
19
|
+
getSchemaHelper() {
|
|
20
|
+
return this.schemaHelper;
|
|
21
|
+
}
|
|
22
|
+
/** @inheritDoc */
|
|
23
|
+
lookupExtensions(orm) {
|
|
24
|
+
schema_1.SqlSchemaGenerator.register(orm);
|
|
25
|
+
}
|
|
26
|
+
/* istanbul ignore next: kept for type inference only */
|
|
27
|
+
getSchemaGenerator(driver, em) {
|
|
28
|
+
return new schema_1.SqlSchemaGenerator(em ?? driver);
|
|
29
|
+
}
|
|
30
|
+
quoteValue(value) {
|
|
31
|
+
if (core_1.Utils.isRawSql(value)) {
|
|
32
|
+
return this.formatQuery(value.sql, value.params ?? []);
|
|
33
|
+
}
|
|
34
|
+
if (this.isRaw(value)) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
/* istanbul ignore if */
|
|
38
|
+
if (core_1.Utils.isPlainObject(value) || value?.[core_1.JsonProperty]) {
|
|
39
|
+
return (0, sqlstring_1.escape)(JSON.stringify(value));
|
|
40
|
+
}
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
return (0, sqlstring_1.escape)(value, true, this.timezone);
|
|
43
|
+
}
|
|
44
|
+
getSearchJsonPropertySQL(path, type, aliased) {
|
|
45
|
+
return this.getSearchJsonPropertyKey(path.split("->"), type, aliased);
|
|
46
|
+
}
|
|
47
|
+
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
48
|
+
const [a, ...b] = path;
|
|
49
|
+
const quoteKey = (key) => key.match(/^[a-z]\w*$/i) ? key : `"${key}"`;
|
|
50
|
+
if (aliased) {
|
|
51
|
+
return (0, core_1.raw)((alias) => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.map(quoteKey).join(".")}')`);
|
|
52
|
+
}
|
|
53
|
+
return (0, core_1.raw)(`json_extract(${this.quoteIdentifier(a)}, '$.${b.map(quoteKey).join(".")}')`);
|
|
54
|
+
}
|
|
55
|
+
getJsonIndexDefinition(index) {
|
|
56
|
+
return index.columnNames.map((column) => {
|
|
57
|
+
const [root, ...path] = column.split(".");
|
|
58
|
+
return `json_extract(${root}, '$.${path.join(".")}')`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
isRaw(value) {
|
|
62
|
+
return (super.isRaw(value) ||
|
|
63
|
+
(typeof value === "object" &&
|
|
64
|
+
value !== null &&
|
|
65
|
+
value.client &&
|
|
66
|
+
["Ref", "Raw"].includes(value.constructor.name)));
|
|
67
|
+
}
|
|
68
|
+
supportsSchemas() {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
/** @inheritDoc */
|
|
72
|
+
generateCustomOrder(escapedColumn, values) {
|
|
73
|
+
let ret = "(case ";
|
|
74
|
+
values.forEach((v, i) => {
|
|
75
|
+
ret += `when ${escapedColumn} = ${this.quoteValue(v)} then ${i} `;
|
|
76
|
+
});
|
|
77
|
+
return ret + "else null end)";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
getOrderByExpression(column, direction) {
|
|
83
|
+
return [`${column} ${direction.toLowerCase()}`];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.AbstractSqlPlatform = AbstractSqlPlatform;
|
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,11 @@
|
|
|
1
|
+
export declare const MonkeyPatchable: {
|
|
2
|
+
Client: any;
|
|
3
|
+
QueryExecutioner: any;
|
|
4
|
+
MySqlDialect: any;
|
|
5
|
+
MySqlColumnCompiler: any;
|
|
6
|
+
MySqlQueryCompiler: any;
|
|
7
|
+
PostgresDialectTableCompiler: any;
|
|
8
|
+
Sqlite3Dialect: any;
|
|
9
|
+
Sqlite3DialectTableCompiler: any;
|
|
10
|
+
TableCompiler: any;
|
|
11
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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.MonkeyPatchable = void 0;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const client_1 = __importDefault(require("knex/lib/client"));
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const query_executioner_1 = __importDefault(require("knex/lib/execution/internal/query-executioner"));
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const mysql_1 = __importDefault(require("knex/lib/dialects/mysql"));
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const mysql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mysql/schema/mysql-columncompiler"));
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const mysql_querycompiler_1 = __importDefault(require("knex/lib/dialects/mysql/query/mysql-querycompiler"));
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const pg_tablecompiler_1 = __importDefault(require("knex/lib/dialects/postgres/schema/pg-tablecompiler"));
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const sqlite3_1 = __importDefault(require("knex/lib/dialects/sqlite3"));
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const sqlite_tablecompiler_1 = __importDefault(require("knex/lib/dialects/sqlite3/schema/sqlite-tablecompiler"));
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const tablecompiler_1 = __importDefault(require("knex/lib/schema/tablecompiler"));
|
|
25
|
+
// These specific portions of knex are overridden by the different
|
|
26
|
+
// database packages. We need to be sure the knex files they get to
|
|
27
|
+
// monkey patch are the same version as our overall knex instance
|
|
28
|
+
// which is why we need to import them in this package.
|
|
29
|
+
exports.MonkeyPatchable = {
|
|
30
|
+
Client: client_1.default,
|
|
31
|
+
QueryExecutioner: query_executioner_1.default,
|
|
32
|
+
MySqlDialect: mysql_1.default,
|
|
33
|
+
MySqlColumnCompiler: mysql_columncompiler_1.default,
|
|
34
|
+
MySqlQueryCompiler: mysql_querycompiler_1.default,
|
|
35
|
+
PostgresDialectTableCompiler: pg_tablecompiler_1.default,
|
|
36
|
+
Sqlite3Dialect: sqlite3_1.default,
|
|
37
|
+
Sqlite3DialectTableCompiler: sqlite_tablecompiler_1.default,
|
|
38
|
+
TableCompiler: tablecompiler_1.default,
|
|
39
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type EntityMetadata, type EntityProperty, type Primary } from "@yandjin-mikro-orm/core";
|
|
2
|
+
import { type AbstractSqlDriver } from "./AbstractSqlDriver";
|
|
3
|
+
export declare class PivotCollectionPersister<Entity extends object> {
|
|
4
|
+
private readonly meta;
|
|
5
|
+
private readonly driver;
|
|
6
|
+
private readonly ctx?;
|
|
7
|
+
private readonly schema?;
|
|
8
|
+
private readonly platform;
|
|
9
|
+
private readonly inserts;
|
|
10
|
+
private readonly deletes;
|
|
11
|
+
private order;
|
|
12
|
+
constructor(meta: EntityMetadata<Entity>, driver: AbstractSqlDriver, ctx?: any, schema?: string | undefined);
|
|
13
|
+
enqueueUpdate(prop: EntityProperty<Entity>, insertDiff: Primary<Entity>[][], deleteDiff: Primary<Entity>[][] | boolean, pks: Primary<Entity>[]): void;
|
|
14
|
+
private enqueueInsert;
|
|
15
|
+
private enqueueDelete;
|
|
16
|
+
execute(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PivotCollectionPersister = void 0;
|
|
4
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
5
|
+
class InsertStatement {
|
|
6
|
+
keys;
|
|
7
|
+
data;
|
|
8
|
+
order;
|
|
9
|
+
constructor(keys, data, order) {
|
|
10
|
+
this.keys = keys;
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.order = order;
|
|
13
|
+
}
|
|
14
|
+
getHash() {
|
|
15
|
+
return JSON.stringify(this.data);
|
|
16
|
+
}
|
|
17
|
+
getData() {
|
|
18
|
+
const data = {};
|
|
19
|
+
this.keys.forEach((key, idx) => (data[key] = this.data[idx]));
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class DeleteStatement {
|
|
24
|
+
keys;
|
|
25
|
+
cond;
|
|
26
|
+
constructor(keys, cond) {
|
|
27
|
+
this.keys = keys;
|
|
28
|
+
this.cond = cond;
|
|
29
|
+
}
|
|
30
|
+
getHash() {
|
|
31
|
+
return JSON.stringify(this.cond);
|
|
32
|
+
}
|
|
33
|
+
getCondition() {
|
|
34
|
+
const cond = {};
|
|
35
|
+
this.keys.forEach((key, idx) => (cond[key] = this.cond[idx]));
|
|
36
|
+
return cond;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class PivotCollectionPersister {
|
|
40
|
+
meta;
|
|
41
|
+
driver;
|
|
42
|
+
ctx;
|
|
43
|
+
schema;
|
|
44
|
+
platform;
|
|
45
|
+
inserts = new Map();
|
|
46
|
+
deletes = new Map();
|
|
47
|
+
order = 0;
|
|
48
|
+
constructor(meta, driver, ctx, schema) {
|
|
49
|
+
this.meta = meta;
|
|
50
|
+
this.driver = driver;
|
|
51
|
+
this.ctx = ctx;
|
|
52
|
+
this.schema = schema;
|
|
53
|
+
this.platform = this.driver.getPlatform();
|
|
54
|
+
}
|
|
55
|
+
enqueueUpdate(prop, insertDiff, deleteDiff, pks) {
|
|
56
|
+
if (insertDiff.length) {
|
|
57
|
+
this.enqueueInsert(prop, insertDiff, pks);
|
|
58
|
+
}
|
|
59
|
+
if (deleteDiff === true ||
|
|
60
|
+
(Array.isArray(deleteDiff) && deleteDiff.length)) {
|
|
61
|
+
this.enqueueDelete(prop, deleteDiff, pks);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
enqueueInsert(prop, insertDiff, pks) {
|
|
65
|
+
for (const fks of insertDiff) {
|
|
66
|
+
const data = prop.owner ? [...fks, ...pks] : [...pks, ...fks];
|
|
67
|
+
const keys = prop.owner
|
|
68
|
+
? [...prop.inverseJoinColumns, ...prop.joinColumns]
|
|
69
|
+
: [...prop.joinColumns, ...prop.inverseJoinColumns];
|
|
70
|
+
const statement = new InsertStatement(keys, data, this.order++);
|
|
71
|
+
const hash = statement.getHash();
|
|
72
|
+
if (prop.owner || !this.inserts.has(hash)) {
|
|
73
|
+
this.inserts.set(hash, statement);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
enqueueDelete(prop, deleteDiff, pks) {
|
|
78
|
+
if (deleteDiff === true) {
|
|
79
|
+
const statement = new DeleteStatement(prop.joinColumns, pks);
|
|
80
|
+
this.deletes.set(statement.getHash(), statement);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const fks of deleteDiff) {
|
|
84
|
+
const data = prop.owner ? [...fks, ...pks] : [...pks, ...fks];
|
|
85
|
+
const keys = prop.owner
|
|
86
|
+
? [...prop.inverseJoinColumns, ...prop.joinColumns]
|
|
87
|
+
: [...prop.joinColumns, ...prop.inverseJoinColumns];
|
|
88
|
+
const statement = new DeleteStatement(keys, data);
|
|
89
|
+
this.deletes.set(statement.getHash(), statement);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async execute() {
|
|
93
|
+
if (this.deletes.size > 0) {
|
|
94
|
+
const knex = this.driver
|
|
95
|
+
.createQueryBuilder(this.meta.className, this.ctx, "write")
|
|
96
|
+
.withSchema(this.schema)
|
|
97
|
+
.getKnex();
|
|
98
|
+
for (const item of this.deletes.values()) {
|
|
99
|
+
knex.orWhere(item.getCondition());
|
|
100
|
+
}
|
|
101
|
+
await this.driver.execute(knex.delete());
|
|
102
|
+
}
|
|
103
|
+
if (this.inserts.size === 0) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let items = [];
|
|
107
|
+
for (const insert of this.inserts.values()) {
|
|
108
|
+
items[insert.order] = insert.getData();
|
|
109
|
+
}
|
|
110
|
+
items = items.filter((i) => i);
|
|
111
|
+
/* istanbul ignore else */
|
|
112
|
+
if (this.platform.allowsMultiInsert()) {
|
|
113
|
+
await this.driver.nativeInsertMany(this.meta.className, items, {
|
|
114
|
+
ctx: this.ctx,
|
|
115
|
+
schema: this.schema,
|
|
116
|
+
convertCustomTypes: false,
|
|
117
|
+
processCollections: false,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
await core_1.Utils.runSerial(items, (item) => {
|
|
122
|
+
return this.driver
|
|
123
|
+
.createQueryBuilder(this.meta.className, this.ctx, "write")
|
|
124
|
+
.withSchema(this.schema)
|
|
125
|
+
.insert(item)
|
|
126
|
+
.execute("run", false);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.PivotCollectionPersister = PivotCollectionPersister;
|