@mikro-orm/knex 6.0.0-dev.8 → 6.0.0-dev.81
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 +5 -2
- package/AbstractSqlConnection.js +25 -17
- package/AbstractSqlDriver.d.ts +18 -18
- package/AbstractSqlDriver.js +124 -49
- package/AbstractSqlPlatform.d.ts +1 -0
- package/AbstractSqlPlatform.js +20 -5
- package/MonkeyPatchable.d.ts +1 -0
- package/MonkeyPatchable.js +3 -0
- package/README.md +64 -107
- package/SqlEntityManager.d.ts +2 -5
- package/SqlEntityManager.js +5 -9
- package/SqlEntityRepository.d.ts +6 -4
- package/SqlEntityRepository.js +10 -8
- package/index.mjs +19 -6
- package/package.json +7 -7
- package/query/ArrayCriteriaNode.d.ts +3 -3
- package/query/CriteriaNode.d.ts +8 -8
- package/query/CriteriaNode.js +9 -9
- package/query/CriteriaNodeFactory.d.ts +6 -6
- package/query/CriteriaNodeFactory.js +10 -13
- package/query/ObjectCriteriaNode.d.ts +3 -3
- package/query/ObjectCriteriaNode.js +12 -8
- package/query/QueryBuilder.d.ts +25 -7
- package/query/QueryBuilder.js +237 -61
- package/query/QueryBuilderHelper.d.ts +3 -5
- package/query/QueryBuilderHelper.js +97 -75
- package/query/ScalarCriteriaNode.d.ts +3 -2
- package/query/ScalarCriteriaNode.js +9 -6
- package/schema/DatabaseSchema.d.ts +4 -1
- package/schema/DatabaseSchema.js +22 -6
- package/schema/DatabaseTable.d.ts +2 -1
- package/schema/DatabaseTable.js +25 -24
- package/schema/SchemaComparator.js +9 -2
- package/schema/SchemaHelper.d.ts +5 -3
- package/schema/SchemaHelper.js +10 -4
- package/schema/SqlSchemaGenerator.d.ts +3 -5
- package/schema/SqlSchemaGenerator.js +41 -20
- package/typings.d.ts +8 -5
package/query/CriteriaNode.js
CHANGED
|
@@ -40,7 +40,7 @@ class CriteriaNode {
|
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
shouldRename(payload) {
|
|
43
|
-
const type = this.prop ? this.prop.
|
|
43
|
+
const type = this.prop ? this.prop.kind : null;
|
|
44
44
|
const composite = this.prop?.joinColumns ? this.prop.joinColumns.length > 1 : false;
|
|
45
45
|
const customExpression = CriteriaNode.isCustomExpression(this.key);
|
|
46
46
|
const scalar = payload === null || core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
|
|
@@ -49,17 +49,17 @@ class CriteriaNode {
|
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
51
51
|
switch (type) {
|
|
52
|
-
case core_1.
|
|
53
|
-
case core_1.
|
|
54
|
-
case core_1.
|
|
55
|
-
case core_1.
|
|
52
|
+
case core_1.ReferenceKind.MANY_TO_ONE: return false;
|
|
53
|
+
case core_1.ReferenceKind.ONE_TO_ONE: return !this.prop.owner;
|
|
54
|
+
case core_1.ReferenceKind.ONE_TO_MANY: return scalar || operator;
|
|
55
|
+
case core_1.ReferenceKind.MANY_TO_MANY: return scalar || operator;
|
|
56
56
|
default: return false;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
renameFieldToPK(qb) {
|
|
60
60
|
const joinAlias = qb.getAliasForJoinPath(this.getPath());
|
|
61
61
|
const alias = joinAlias ?? qb.alias;
|
|
62
|
-
if (this.prop.
|
|
62
|
+
if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY) {
|
|
63
63
|
return core_1.Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
|
|
64
64
|
}
|
|
65
65
|
// if we found a matching join, we need to use the target table column names, as we use that alias instead of the root
|
|
@@ -70,7 +70,7 @@ class CriteriaNode {
|
|
|
70
70
|
}
|
|
71
71
|
getPath(addIndex = false) {
|
|
72
72
|
// use index on parent only if we are processing to-many relation
|
|
73
|
-
const addParentIndex = this.prop && [core_1.
|
|
73
|
+
const addParentIndex = this.prop && [core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(this.prop.kind);
|
|
74
74
|
const parentPath = this.parent?.getPath(addParentIndex) ?? this.entityName;
|
|
75
75
|
const index = addIndex && this.index != null ? `[${this.index}]` : '';
|
|
76
76
|
// ignore group operators to allow easier mapping (e.g. for orderBy)
|
|
@@ -89,7 +89,7 @@ class CriteriaNode {
|
|
|
89
89
|
const customExpression = CriteriaNode.isCustomExpression(this.key);
|
|
90
90
|
const scalar = this.payload === null || core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
|
|
91
91
|
const operator = core_1.Utils.isObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
|
|
92
|
-
return this.prop.
|
|
92
|
+
return this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY && (scalar || operator);
|
|
93
93
|
}
|
|
94
94
|
getPivotPath(path) {
|
|
95
95
|
return `${path}[pivot]`;
|
|
@@ -97,7 +97,7 @@ class CriteriaNode {
|
|
|
97
97
|
[util_1.inspect.custom]() {
|
|
98
98
|
const o = {};
|
|
99
99
|
['entityName', 'key', 'index', 'payload']
|
|
100
|
-
.filter(k => this[k]
|
|
100
|
+
.filter(k => this[k] !== undefined)
|
|
101
101
|
.forEach(k => o[k] = this[k]);
|
|
102
102
|
return `${this.constructor.name} ${(0, util_1.inspect)(o)}`;
|
|
103
103
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Dictionary, EntityMetadata, MetadataStorage } from '@mikro-orm/core';
|
|
1
|
+
import type { Dictionary, EntityKey, EntityMetadata, MetadataStorage } from '@mikro-orm/core';
|
|
2
2
|
import type { ICriteriaNode } from '../typings';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export declare class CriteriaNodeFactory {
|
|
7
|
-
static createNode(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode
|
|
8
|
-
static createScalarNode(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode
|
|
9
|
-
static createArrayNode(metadata: MetadataStorage, entityName: string, payload: any[], parent?: ICriteriaNode
|
|
10
|
-
static createObjectNode(metadata: MetadataStorage, entityName: string, payload: Dictionary, parent?: ICriteriaNode
|
|
11
|
-
static createObjectItemNode(metadata: MetadataStorage, entityName: string, node: ICriteriaNode
|
|
7
|
+
static createNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>;
|
|
8
|
+
static createScalarNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>;
|
|
9
|
+
static createArrayNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any[], parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>;
|
|
10
|
+
static createObjectNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: Dictionary, parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>;
|
|
11
|
+
static createObjectItemNode<T extends object>(metadata: MetadataStorage, entityName: string, node: ICriteriaNode<T>, payload: Dictionary, key: EntityKey<T>, meta?: EntityMetadata<T>): ICriteriaNode<T>;
|
|
12
12
|
}
|
|
@@ -12,7 +12,7 @@ const CriteriaNode_1 = require("./CriteriaNode");
|
|
|
12
12
|
class CriteriaNodeFactory {
|
|
13
13
|
static createNode(metadata, entityName, payload, parent, key) {
|
|
14
14
|
const customExpression = CriteriaNode_1.CriteriaNode.isCustomExpression(key || '');
|
|
15
|
-
const scalar = core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
|
|
15
|
+
const scalar = core_1.Utils.isPrimaryKey(payload) || core_1.Utils.isRawSql(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
|
|
16
16
|
if (Array.isArray(payload) && !scalar) {
|
|
17
17
|
return this.createArrayNode(metadata, entityName, payload, parent, key);
|
|
18
18
|
}
|
|
@@ -37,9 +37,6 @@ class CriteriaNodeFactory {
|
|
|
37
37
|
}
|
|
38
38
|
static createObjectNode(metadata, entityName, payload, parent, key) {
|
|
39
39
|
const meta = metadata.find(entityName);
|
|
40
|
-
if (!parent && Object.keys(payload).every(k => meta?.properties[k]?.reference === core_1.ReferenceType.SCALAR)) {
|
|
41
|
-
return this.createScalarNode(metadata, entityName, payload, parent, key);
|
|
42
|
-
}
|
|
43
40
|
const node = new ObjectCriteriaNode_1.ObjectCriteriaNode(metadata, entityName, parent, key);
|
|
44
41
|
node.payload = Object.keys(payload).reduce((o, item) => {
|
|
45
42
|
o[item] = this.createObjectItemNode(metadata, entityName, node, payload, item, meta);
|
|
@@ -47,24 +44,24 @@ class CriteriaNodeFactory {
|
|
|
47
44
|
}, {});
|
|
48
45
|
return node;
|
|
49
46
|
}
|
|
50
|
-
static createObjectItemNode(metadata, entityName, node, payload,
|
|
51
|
-
const prop = meta?.properties[
|
|
52
|
-
if (prop?.
|
|
53
|
-
const childEntity = prop && prop.
|
|
54
|
-
return this.createNode(metadata, childEntity, payload[
|
|
47
|
+
static createObjectItemNode(metadata, entityName, node, payload, key, meta) {
|
|
48
|
+
const prop = meta?.properties[key];
|
|
49
|
+
if (prop?.kind !== core_1.ReferenceKind.EMBEDDED) {
|
|
50
|
+
const childEntity = prop && prop.kind !== core_1.ReferenceKind.SCALAR ? prop.type : entityName;
|
|
51
|
+
return this.createNode(metadata, childEntity, payload[key], node, key);
|
|
55
52
|
}
|
|
56
|
-
const operator = Object.keys(payload[
|
|
53
|
+
const operator = Object.keys(payload[key]).some(f => core_1.Utils.isOperator(f));
|
|
57
54
|
if (operator) {
|
|
58
55
|
throw core_1.ValidationError.cannotUseOperatorsInsideEmbeddables(entityName, prop.name, payload);
|
|
59
56
|
}
|
|
60
|
-
const map = Object.keys(payload[
|
|
57
|
+
const map = Object.keys(payload[key]).reduce((oo, k) => {
|
|
61
58
|
if (!prop.embeddedProps[k]) {
|
|
62
59
|
throw core_1.ValidationError.invalidEmbeddableQuery(entityName, k, prop.type);
|
|
63
60
|
}
|
|
64
|
-
oo[prop.embeddedProps[k].name] = payload[
|
|
61
|
+
oo[prop.embeddedProps[k].name] = payload[key][k];
|
|
65
62
|
return oo;
|
|
66
63
|
}, {});
|
|
67
|
-
return this.createNode(metadata, entityName, map, node,
|
|
64
|
+
return this.createNode(metadata, entityName, map, node, key);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
exports.CriteriaNodeFactory = CriteriaNodeFactory;
|
|
@@ -3,9 +3,9 @@ import type { IQueryBuilder } from '../typings';
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
export declare class ObjectCriteriaNode extends CriteriaNode {
|
|
7
|
-
process
|
|
8
|
-
willAutoJoin
|
|
6
|
+
export declare class ObjectCriteriaNode<T extends object> extends CriteriaNode<T> {
|
|
7
|
+
process(qb: IQueryBuilder<T>, alias?: string): any;
|
|
8
|
+
willAutoJoin(qb: IQueryBuilder<T>, alias?: string): boolean;
|
|
9
9
|
shouldInline(payload: any): boolean;
|
|
10
10
|
private inlineChildPayload;
|
|
11
11
|
private shouldAutoJoin;
|
|
@@ -21,7 +21,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
21
21
|
const childNode = this.payload[field];
|
|
22
22
|
const payload = childNode.process(qb, this.prop ? alias : ownerAlias);
|
|
23
23
|
const operator = core_1.Utils.isOperator(field);
|
|
24
|
-
const
|
|
24
|
+
const isRawField = core_1.RawQueryFragment.isKnownFragment(field);
|
|
25
25
|
// we need to keep the prefixing for formulas otherwise we would lose aliasing context when nesting inside group operators
|
|
26
26
|
const virtual = childNode.prop?.persist === false && !childNode.prop?.formula;
|
|
27
27
|
// if key is missing, we are inside group operator and we need to prefix with alias
|
|
@@ -33,8 +33,12 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
33
33
|
else if (childNode.shouldRename(payload)) {
|
|
34
34
|
o[childNode.renameFieldToPK(qb)] = payload;
|
|
35
35
|
}
|
|
36
|
-
else if (
|
|
37
|
-
|
|
36
|
+
else if (isRawField) {
|
|
37
|
+
const rawField = core_1.RawQueryFragment.getKnownFragment(field);
|
|
38
|
+
o[(0, core_1.raw)(rawField.sql.replaceAll(core_1.ALIAS_REPLACEMENT, alias), rawField.params)] = payload;
|
|
39
|
+
}
|
|
40
|
+
else if (primaryKey || virtual || operator || field.includes('.') || ![enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type ?? enums_1.QueryType.SELECT)) {
|
|
41
|
+
o[field.replaceAll(core_1.ALIAS_REPLACEMENT, alias)] = payload;
|
|
38
42
|
}
|
|
39
43
|
else {
|
|
40
44
|
o[`${alias}.${field}`] = payload;
|
|
@@ -60,7 +64,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
60
64
|
const customExpression = ObjectCriteriaNode.isCustomExpression(this.key);
|
|
61
65
|
const scalar = core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
|
|
62
66
|
const operator = core_1.Utils.isObject(payload) && Object.keys(payload).every(k => core_1.Utils.isOperator(k, false));
|
|
63
|
-
return !!this.prop && this.prop.
|
|
67
|
+
return !!this.prop && this.prop.kind !== core_1.ReferenceKind.SCALAR && !scalar && !operator;
|
|
64
68
|
}
|
|
65
69
|
inlineChildPayload(o, payload, field, alias, childAlias) {
|
|
66
70
|
const prop = this.metadata.find(this.entityName).properties[field];
|
|
@@ -104,15 +108,15 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
104
108
|
if (!this.prop || !this.parent) {
|
|
105
109
|
return false;
|
|
106
110
|
}
|
|
107
|
-
const embeddable = this.prop.
|
|
108
|
-
const knownKey = [core_1.
|
|
111
|
+
const embeddable = this.prop.kind === core_1.ReferenceKind.EMBEDDED;
|
|
112
|
+
const knownKey = [core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.EMBEDDED].includes(this.prop.kind) || (this.prop.kind === core_1.ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
|
109
113
|
const operatorKeys = knownKey && Object.keys(this.payload).every(key => core_1.Utils.isOperator(key, false));
|
|
110
114
|
const primaryKeys = knownKey && Object.keys(this.payload).every(key => {
|
|
111
115
|
const meta = this.metadata.find(this.entityName);
|
|
112
116
|
if (!meta.primaryKeys.includes(key)) {
|
|
113
117
|
return false;
|
|
114
118
|
}
|
|
115
|
-
if (!core_1.Utils.isPlainObject(this.payload[key].payload) || ![core_1.
|
|
119
|
+
if (!core_1.Utils.isPlainObject(this.payload[key].payload) || ![core_1.ReferenceKind.ONE_TO_ONE, core_1.ReferenceKind.MANY_TO_ONE].includes(meta.properties[key].kind)) {
|
|
116
120
|
return true;
|
|
117
121
|
}
|
|
118
122
|
return Object.keys(this.payload[key].payload).every(k => meta.properties[key].targetMeta.primaryKeys.includes(k));
|
|
@@ -125,7 +129,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
125
129
|
const scalar = core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
|
|
126
130
|
const operator = core_1.Utils.isPlainObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
|
|
127
131
|
const field = `${alias}.${this.prop.name}`;
|
|
128
|
-
if (this.prop.
|
|
132
|
+
if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY && (scalar || operator)) {
|
|
129
133
|
qb.join(field, nestedAlias, undefined, 'pivotJoin', this.getPath());
|
|
130
134
|
}
|
|
131
135
|
else {
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { inspect } from 'util';
|
|
1
3
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
|
|
4
|
+
import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, LoggingOptions, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
|
|
3
5
|
import { LockMode, PopulateHint, QueryFlag } from '@mikro-orm/core';
|
|
4
6
|
import { QueryType } from './enums';
|
|
5
7
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver';
|
|
6
|
-
import { QueryBuilderHelper } from './QueryBuilderHelper';
|
|
7
8
|
import type { Alias } from './QueryBuilderHelper';
|
|
9
|
+
import { QueryBuilderHelper } from './QueryBuilderHelper';
|
|
8
10
|
import type { SqlEntityManager } from '../SqlEntityManager';
|
|
9
11
|
import type { Field } from '../typings';
|
|
10
12
|
/**
|
|
@@ -27,11 +29,13 @@ import type { Field } from '../typings';
|
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
31
|
export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
32
|
+
#private;
|
|
30
33
|
private readonly metadata;
|
|
31
34
|
private readonly driver;
|
|
32
35
|
private readonly context?;
|
|
33
36
|
private connectionType?;
|
|
34
37
|
private readonly em?;
|
|
38
|
+
private readonly logging?;
|
|
35
39
|
get mainAlias(): Alias;
|
|
36
40
|
get alias(): string;
|
|
37
41
|
get helper(): QueryBuilderHelper;
|
|
@@ -56,6 +60,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
56
60
|
private _orderBy;
|
|
57
61
|
private _groupBy;
|
|
58
62
|
private _having;
|
|
63
|
+
private _returning?;
|
|
59
64
|
private _onConflict?;
|
|
60
65
|
private _limit?;
|
|
61
66
|
private _offset?;
|
|
@@ -75,7 +80,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
75
80
|
/**
|
|
76
81
|
* @internal
|
|
77
82
|
*/
|
|
78
|
-
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("
|
|
83
|
+
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, import("..").AbstractSqlPlatform>> | undefined, logging?: LoggingOptions | undefined);
|
|
79
84
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
80
85
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
81
86
|
distinct(): SelectQueryBuilder<T>;
|
|
@@ -88,9 +93,10 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
88
93
|
count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
|
|
89
94
|
join(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): this;
|
|
90
95
|
leftJoin(field: string, alias: string, cond?: QBFilterQuery): this;
|
|
91
|
-
joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): SelectQueryBuilder<T>;
|
|
92
|
-
leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery): SelectQueryBuilder<T>;
|
|
93
|
-
|
|
96
|
+
joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string, fields?: string[]): SelectQueryBuilder<T>;
|
|
97
|
+
leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): SelectQueryBuilder<T>;
|
|
98
|
+
innerJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): SelectQueryBuilder<T>;
|
|
99
|
+
protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string, explicitFields?: string[]): Field<T>[];
|
|
94
100
|
withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
|
|
95
101
|
where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
|
|
96
102
|
where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
|
|
@@ -104,6 +110,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
104
110
|
onConflict(fields?: Field<T> | Field<T>[]): this;
|
|
105
111
|
ignore(): this;
|
|
106
112
|
merge(data?: EntityData<T> | Field<T>[]): this;
|
|
113
|
+
returning(fields?: Field<T> | Field<T>[]): this;
|
|
107
114
|
/**
|
|
108
115
|
* @internal
|
|
109
116
|
*/
|
|
@@ -114,7 +121,6 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
114
121
|
ref(field: string): Knex.Ref<string, {
|
|
115
122
|
[x: string]: string;
|
|
116
123
|
}>;
|
|
117
|
-
raw<R = Knex.Raw>(sql: string, bindings?: Knex.RawBinding[] | Knex.ValueDict): R;
|
|
118
124
|
limit(limit?: number, offset?: number): this;
|
|
119
125
|
offset(offset?: number): this;
|
|
120
126
|
withSchema(schema?: string): this;
|
|
@@ -138,6 +144,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
138
144
|
* Returns the query with parameters as wildcards.
|
|
139
145
|
*/
|
|
140
146
|
getQuery(): string;
|
|
147
|
+
toQuery(): {
|
|
148
|
+
sql: string;
|
|
149
|
+
_sql: Knex.Sql;
|
|
150
|
+
params: readonly unknown[];
|
|
151
|
+
};
|
|
141
152
|
/**
|
|
142
153
|
* Returns the list of all parameters for this query.
|
|
143
154
|
*/
|
|
@@ -179,6 +190,10 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
179
190
|
* Executes count query (without offset and limit), returning total count of results
|
|
180
191
|
*/
|
|
181
192
|
getCount(field?: string | string[], distinct?: boolean): Promise<number>;
|
|
193
|
+
/**
|
|
194
|
+
* Executes the query, returning both array of results and total count query (without offset and limit).
|
|
195
|
+
*/
|
|
196
|
+
getResultAndCount(): Promise<[T[], number]>;
|
|
182
197
|
/**
|
|
183
198
|
* Provides promise-like interface so we can await the QB instance.
|
|
184
199
|
*/
|
|
@@ -194,7 +209,9 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
194
209
|
private prepareFields;
|
|
195
210
|
private init;
|
|
196
211
|
private getQueryBase;
|
|
212
|
+
private applyDiscriminatorCondition;
|
|
197
213
|
private finalize;
|
|
214
|
+
private processPopulateWhere;
|
|
198
215
|
private hasToManyJoins;
|
|
199
216
|
private wrapPaginateSubQuery;
|
|
200
217
|
private wrapModifySubQuery;
|
|
@@ -207,6 +224,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
207
224
|
private createQueryBuilderHelper;
|
|
208
225
|
private ensureFromClause;
|
|
209
226
|
private ensureNotFinalized;
|
|
227
|
+
[inspect.custom](depth: number): string;
|
|
210
228
|
}
|
|
211
229
|
export interface RunQueryBuilder<T extends object> extends Omit<QueryBuilder<T>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
|
|
212
230
|
where(cond: QBFilterQuery<T> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|