sasat 0.19.32 → 0.19.34
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/lib/generatorv2/codegen/ts/generateAutoGeneratedDatasource.js +6 -5
- package/lib/generatorv2/codegen/ts/generateQueryResolver.js +1 -2
- package/lib/generatorv2/codegen/ts/relationMap/makeJoinConditionValue.js +1 -4
- package/lib/generatorv2/codegen/ts/scripts/makeConditonValueExpr.js +1 -1
- package/lib/generatorv2/codegen/ts/scripts/makeQueryConditionExpr.js +1 -3
- package/lib/runtime/dsl/factory.d.ts +8 -5
- package/lib/runtime/dsl/factory.js +22 -4
- package/lib/runtime/dsl/query/query.d.ts +17 -4
- package/lib/runtime/dsl/query/query.js +2 -0
- package/lib/runtime/dsl/query/sql/nodeToSql.d.ts +3 -1
- package/lib/runtime/dsl/query/sql/nodeToSql.js +30 -8
- package/lib/runtime/pagingOption.d.ts +2 -2
- package/lib/runtime/sasatDBDatasource.d.ts +2 -1
- package/lib/runtime/sasatDBDatasource.js +3 -3
- package/lib/runtime/sql/runQuery.d.ts +4 -5
- package/lib/runtime/sql/runQuery.js +2 -2
- package/package.json +1 -1
|
@@ -71,12 +71,11 @@ const makeDefaultValueMethod = (node) => {
|
|
|
71
71
|
.modifiers(tsg.methodModifiers().protected());
|
|
72
72
|
};
|
|
73
73
|
const makeFindMethods = (node) => {
|
|
74
|
-
const qExpr = tsg.identifier('
|
|
74
|
+
const qExpr = tsg.identifier('qe').importFrom('sasat');
|
|
75
75
|
return node.findMethods.map(it => {
|
|
76
76
|
const bve = it.params.flatMap(it => {
|
|
77
77
|
if (!it.entity)
|
|
78
78
|
return qExpr
|
|
79
|
-
.property('conditions')
|
|
80
79
|
.property('eq')
|
|
81
80
|
.call(qExpr
|
|
82
81
|
.property('field')
|
|
@@ -85,7 +84,6 @@ const makeFindMethods = (node) => {
|
|
|
85
84
|
.call(tsg.identifier(it.fieldName.toString())));
|
|
86
85
|
return it.fields.map(field => {
|
|
87
86
|
return qExpr
|
|
88
|
-
.property('conditions')
|
|
89
87
|
.property('eq')
|
|
90
88
|
.call(qExpr
|
|
91
89
|
.property('field')
|
|
@@ -96,8 +94,11 @@ const makeFindMethods = (node) => {
|
|
|
96
94
|
});
|
|
97
95
|
const body = [
|
|
98
96
|
tsg.variable('const', 'tableName', tsg.identifier('fields?.tableAlias || "t0"')),
|
|
99
|
-
tsg.return(tsg
|
|
100
|
-
.
|
|
97
|
+
tsg.return(tsg
|
|
98
|
+
.identifier(it.isArray ? 'this.find' : 'this.first')
|
|
99
|
+
.call(tsg.identifier('fields'), tsg
|
|
100
|
+
.object()
|
|
101
|
+
.addProperties(tsg.spreadAssign(tsg.identifier('options')), tsg.propertyAssign('where', qExpr
|
|
101
102
|
.property('and')
|
|
102
103
|
.call(...bve, tsg.identifier('options?').property('where')))), tsg.identifier('context'))),
|
|
103
104
|
];
|
|
@@ -119,7 +119,7 @@ const makeTypeArgs = (args) => {
|
|
|
119
119
|
tsg.typeLiteral(args.map(it => tsg.propertySignature(it.name, getType(it, false)))),
|
|
120
120
|
];
|
|
121
121
|
};
|
|
122
|
-
const qExpr = tsg.identifier('
|
|
122
|
+
const qExpr = tsg.identifier('qe').importFrom('sasat');
|
|
123
123
|
const makeGQLQueryBody = (entity, query) => {
|
|
124
124
|
const fields = tsg.variable('const', 'fields', tsg
|
|
125
125
|
.identifier('gqlResolveInfoToField')
|
|
@@ -128,7 +128,6 @@ const makeGQLQueryBody = (entity, query) => {
|
|
|
128
128
|
.as(makeTypeRef(entity.name, 'fields', 'GENERATED')));
|
|
129
129
|
const where = query.conditions && query.conditions.length !== 0
|
|
130
130
|
? tsg.variable('const', 'where', qExpr
|
|
131
|
-
.property('conditions')
|
|
132
131
|
.property('and')
|
|
133
132
|
.call(...(query.conditions || []).map(makeQueryConditionExpr)))
|
|
134
133
|
: null;
|
|
@@ -2,7 +2,7 @@ import { tsg } from '../../../../tsg/index.js';
|
|
|
2
2
|
import { makeThrowExpressions } from './makeNoContexError.js';
|
|
3
3
|
import { makeConditionValueQExpr } from '../scripts/makeConditonValueExpr.js';
|
|
4
4
|
import { nonNullable } from '../../../../runtime/util.js';
|
|
5
|
-
const qExpr = tsg.identifier('
|
|
5
|
+
const qExpr = tsg.identifier('qe').importFrom('sasat');
|
|
6
6
|
const parentTableAlias = 'parentTableAlias';
|
|
7
7
|
const childTableAlias = 'childTableAlias';
|
|
8
8
|
export const makeJoinConditionValueQExpr = (node, cv) => {
|
|
@@ -53,12 +53,10 @@ const makeConditionExpr = (entity, condition) => {
|
|
|
53
53
|
}
|
|
54
54
|
if (condition.operator === 'BETWEEN') {
|
|
55
55
|
return qExpr
|
|
56
|
-
.property('conditions')
|
|
57
56
|
.property('between')
|
|
58
57
|
.call(makeJoinConditionValueQExpr(entity, condition.left), ...makeRangeCondition(entity, condition.right));
|
|
59
58
|
}
|
|
60
59
|
return qExpr
|
|
61
|
-
.property('conditions')
|
|
62
60
|
.property('comparison')
|
|
63
61
|
.call(makeJoinConditionValueQExpr(entity, condition.left), tsg.string(condition.operator), makeJoinConditionValueQExpr(entity, condition.right));
|
|
64
62
|
};
|
|
@@ -67,7 +65,6 @@ export const makeJoinConditionValue = (node, ref) => {
|
|
|
67
65
|
return tsg.propertyAssign('condition', tsg.arrowFunc([tsg.parameter(arg.toString())], tsg.typeRef('BooleanValueExpression').importFrom('sasat'), tsg.block(...ref.joinCondition
|
|
68
66
|
.flatMap(it => makeThrowExpressions(it))
|
|
69
67
|
.filter(nonNullable), tsg.return(qExpr
|
|
70
|
-
.property('conditions')
|
|
71
68
|
.property('and')
|
|
72
69
|
.call(...ref.joinCondition.map(it => makeConditionExpr(node, it)))))));
|
|
73
70
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tsg } from '../../../../tsg/index.js';
|
|
2
|
-
const qExpr = tsg.identifier('
|
|
2
|
+
const qExpr = tsg.identifier('qe').importFrom('sasat');
|
|
3
3
|
export const makeConditionValueQExpr = (cv) => {
|
|
4
4
|
const arg = tsg.identifier('arg');
|
|
5
5
|
const context = arg.property('context?');
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { tsg } from '../../../../tsg/index.js';
|
|
2
2
|
import { makeConditionValueQExpr } from './makeConditonValueExpr.js';
|
|
3
|
-
const qExpr = tsg.identifier('
|
|
3
|
+
const qExpr = tsg.identifier('qe').importFrom('sasat');
|
|
4
4
|
export const makeQueryConditionExpr = (condition) => {
|
|
5
5
|
if (condition.kind === 'between') {
|
|
6
6
|
return qExpr
|
|
7
|
-
.property('conditions')
|
|
8
7
|
.property('between')
|
|
9
8
|
.call(makeConditionValueQExpr(condition.left), makeConditionValueQExpr(condition.begin), makeConditionValueQExpr(condition.end));
|
|
10
9
|
}
|
|
11
10
|
return qExpr
|
|
12
|
-
.property('conditions')
|
|
13
11
|
.property('comparison')
|
|
14
12
|
.call(makeConditionValueQExpr(condition.left), tsg.string(condition.operator), makeConditionValueQExpr(condition.right));
|
|
15
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BetweenExpression, BooleanValueExpression, ComparisonExpression, Field, Fn, Identifier, InExpression, IsNullExpression, Join, JoinType, Literal, ParenthesisExpression, Query, QueryTable, Sort, SortDirection, Value } from './query/query.js';
|
|
1
|
+
import { BetweenExpression, BooleanValueExpression, ComparisonExpression, ExistsExpression, Field, Fn, Identifier, InExpression, IsNullExpression, Join, JoinType, Literal, ParenthesisExpression, Query, QueryTable, RawExpression, Sort, SortDirection, Value } from './query/query.js';
|
|
2
2
|
import { ComparisonOperators } from '../../db/sql/expression/comparison.js';
|
|
3
3
|
type StrOrNum = string | number;
|
|
4
4
|
type ValueType = string | boolean | number | null;
|
|
@@ -13,6 +13,7 @@ export declare const QExpr: {
|
|
|
13
13
|
readonly sort: (field: Field | Fn, direction?: SortDirection) => Sort;
|
|
14
14
|
readonly order: (field: Field | Fn, direction?: SortDirection) => Sort;
|
|
15
15
|
readonly ident: (identifier: string) => Identifier;
|
|
16
|
+
readonly raw: (sql: string) => RawExpression;
|
|
16
17
|
readonly simpleWhere: (tableNameOrAlias: string, where: {
|
|
17
18
|
[field: string]: ValueType | [ComparisonOperators, ValueType];
|
|
18
19
|
}, isOr?: boolean) => BooleanValueExpression;
|
|
@@ -31,11 +32,12 @@ export declare const QExpr: {
|
|
|
31
32
|
readonly notStatsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
32
33
|
readonly endsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
33
34
|
readonly notEndsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
34
|
-
readonly In: (left: Value,
|
|
35
|
-
readonly notIn: (left: Value, values:
|
|
35
|
+
readonly In: (left: Value, right: StrOrNum[] | Query | RawExpression) => BooleanValueExpression;
|
|
36
|
+
readonly notIn: (left: Value, values: StrOrNum[]) => InExpression;
|
|
36
37
|
readonly between: (left: Value, begin: Value, end: Value) => BetweenExpression;
|
|
37
38
|
readonly isNull: (expr: Value) => IsNullExpression;
|
|
38
39
|
readonly isNotNull: (expr: Value) => IsNullExpression;
|
|
40
|
+
readonly exists: (query: RawExpression | Query) => ExistsExpression;
|
|
39
41
|
readonly conditions: {
|
|
40
42
|
simpleWhere: (tableNameOrAlias: string, where: {
|
|
41
43
|
[field: string]: ValueType | [ComparisonOperators, ValueType];
|
|
@@ -55,11 +57,12 @@ export declare const QExpr: {
|
|
|
55
57
|
notStatsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
56
58
|
endsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
57
59
|
notEndsWiths: (left: Value, right: string) => BooleanValueExpression;
|
|
58
|
-
In: (left: Value,
|
|
59
|
-
notIn: (left: Value, values:
|
|
60
|
+
In: (left: Value, right: StrOrNum[] | Query | RawExpression) => BooleanValueExpression;
|
|
61
|
+
notIn: (left: Value, values: StrOrNum[]) => InExpression;
|
|
60
62
|
between: (left: Value, begin: Value, end: Value) => BetweenExpression;
|
|
61
63
|
isNull: (expr: Value) => IsNullExpression;
|
|
62
64
|
isNotNull: (expr: Value) => IsNullExpression;
|
|
65
|
+
exists: (query: RawExpression | Query) => ExistsExpression;
|
|
63
66
|
};
|
|
64
67
|
};
|
|
65
68
|
export {};
|
|
@@ -38,14 +38,22 @@ const paren = (expression) => ({
|
|
|
38
38
|
kind: QueryNodeKind.Parenthesis,
|
|
39
39
|
expression,
|
|
40
40
|
});
|
|
41
|
-
const In = (left,
|
|
42
|
-
if (
|
|
43
|
-
|
|
41
|
+
const In = (left, right) => {
|
|
42
|
+
if (Array.isArray(right)) {
|
|
43
|
+
if (right.length === 0)
|
|
44
|
+
return conditions.eq(literal(0), literal(1));
|
|
45
|
+
return {
|
|
46
|
+
kind: QueryNodeKind.InExpr,
|
|
47
|
+
left,
|
|
48
|
+
operator: 'IN',
|
|
49
|
+
right: right.map(literal),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
44
52
|
return {
|
|
45
53
|
kind: QueryNodeKind.InExpr,
|
|
46
54
|
left,
|
|
47
55
|
operator: 'IN',
|
|
48
|
-
|
|
56
|
+
query: right,
|
|
49
57
|
};
|
|
50
58
|
};
|
|
51
59
|
const notIn = (left, values) => ({
|
|
@@ -74,6 +82,14 @@ const simpleWhere = (tableNameOrAlias, where, isOr = false) => {
|
|
|
74
82
|
return conditions.eq(fe, literal(value));
|
|
75
83
|
}));
|
|
76
84
|
};
|
|
85
|
+
const exists = (query) => ({
|
|
86
|
+
kind: QueryNodeKind.Exists,
|
|
87
|
+
query,
|
|
88
|
+
});
|
|
89
|
+
const raw = (sql) => ({
|
|
90
|
+
kind: QueryNodeKind.Raw,
|
|
91
|
+
expr: sql,
|
|
92
|
+
});
|
|
77
93
|
const conditions = {
|
|
78
94
|
simpleWhere,
|
|
79
95
|
and,
|
|
@@ -96,6 +112,7 @@ const conditions = {
|
|
|
96
112
|
between,
|
|
97
113
|
isNull: isNull(false),
|
|
98
114
|
isNotNull: isNull(true),
|
|
115
|
+
exists,
|
|
99
116
|
};
|
|
100
117
|
const table = (name, joins, alias) => ({
|
|
101
118
|
kind: QueryNodeKind.Table,
|
|
@@ -143,4 +160,5 @@ export const QExpr = {
|
|
|
143
160
|
sort,
|
|
144
161
|
order: sort,
|
|
145
162
|
ident,
|
|
163
|
+
raw,
|
|
146
164
|
};
|
|
@@ -13,7 +13,9 @@ export declare enum QueryNodeKind {
|
|
|
13
13
|
ContainsExpr = 10,
|
|
14
14
|
Literal = 11,
|
|
15
15
|
Sort = 12,
|
|
16
|
-
Identifier = 13
|
|
16
|
+
Identifier = 13,
|
|
17
|
+
Exists = 14,
|
|
18
|
+
Raw = 15
|
|
17
19
|
}
|
|
18
20
|
export type LockMode = 'FOR UPDATE' | 'FOR SHARE';
|
|
19
21
|
export type Query = {
|
|
@@ -62,7 +64,15 @@ export type ParenthesisExpression = {
|
|
|
62
64
|
kind: QueryNodeKind.Parenthesis;
|
|
63
65
|
expression: BooleanValueExpression;
|
|
64
66
|
};
|
|
65
|
-
export type
|
|
67
|
+
export type RawExpression = {
|
|
68
|
+
kind: QueryNodeKind.Raw;
|
|
69
|
+
expr: string;
|
|
70
|
+
};
|
|
71
|
+
export type ExistsExpression = {
|
|
72
|
+
kind: QueryNodeKind.Exists;
|
|
73
|
+
query: Query | RawExpression;
|
|
74
|
+
};
|
|
75
|
+
export type BooleanValueExpression = CompoundExpression | ComparisonExpression | IsNullExpression | ParenthesisExpression | InExpression | BetweenExpression | ContainsExpression | ExistsExpression;
|
|
66
76
|
export type IsNullExpression = {
|
|
67
77
|
kind: QueryNodeKind.IsNullExpr;
|
|
68
78
|
expr: Value;
|
|
@@ -93,8 +103,11 @@ export type InExpression = {
|
|
|
93
103
|
kind: QueryNodeKind.InExpr;
|
|
94
104
|
left: Value;
|
|
95
105
|
operator: 'IN' | 'NOT IN';
|
|
106
|
+
} & ({
|
|
107
|
+
query: Query | RawExpression;
|
|
108
|
+
} | {
|
|
96
109
|
right: Value[];
|
|
97
|
-
};
|
|
110
|
+
});
|
|
98
111
|
export type BetweenExpression = {
|
|
99
112
|
kind: QueryNodeKind.BetweenExpr;
|
|
100
113
|
left: Value;
|
|
@@ -113,7 +126,7 @@ export type Literal = {
|
|
|
113
126
|
export type SortDirection = 'ASC' | 'DESC';
|
|
114
127
|
export type Sort = {
|
|
115
128
|
kind: QueryNodeKind.Sort;
|
|
116
|
-
field: Field | Fn;
|
|
129
|
+
field: Field | Fn | Identifier;
|
|
117
130
|
direction?: SortDirection;
|
|
118
131
|
};
|
|
119
132
|
export type QueryNode = Field | Fn | QueryTable | Literal | BooleanValueExpression | Join | Sort;
|
|
@@ -14,5 +14,7 @@ export var QueryNodeKind;
|
|
|
14
14
|
QueryNodeKind[QueryNodeKind["Literal"] = 11] = "Literal";
|
|
15
15
|
QueryNodeKind[QueryNodeKind["Sort"] = 12] = "Sort";
|
|
16
16
|
QueryNodeKind[QueryNodeKind["Identifier"] = 13] = "Identifier";
|
|
17
|
+
QueryNodeKind[QueryNodeKind["Exists"] = 14] = "Exists";
|
|
18
|
+
QueryNodeKind[QueryNodeKind["Raw"] = 15] = "Raw";
|
|
17
19
|
})(QueryNodeKind || (QueryNodeKind = {}));
|
|
18
20
|
export const NO_ALIAS = '__SASAT_NO_ALIAS';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BetweenExpression, BooleanValueExpression, ComparisonExpression, CompoundExpression, ContainsExpression, Field, Fn, Identifier, InExpression, IsNullExpression, Join, Literal, ParenthesisExpression, QueryTable, SelectExpr, Sort, Value } from '../query.js';
|
|
1
|
+
import { BetweenExpression, BooleanValueExpression, ComparisonExpression, CompoundExpression, ContainsExpression, ExistsExpression, Field, Fn, Identifier, InExpression, IsNullExpression, Join, Literal, ParenthesisExpression, Query, QueryTable, RawExpression, SelectExpr, Sort, Value } from '../query.js';
|
|
2
2
|
export declare const SELECT_ALIAS_SEPARATOR = "__";
|
|
3
3
|
export declare const Sql: {
|
|
4
4
|
select: (expr: SelectExpr) => string;
|
|
@@ -18,6 +18,8 @@ export declare const Sql: {
|
|
|
18
18
|
table: (table: QueryTable) => string;
|
|
19
19
|
join: (join: Join) => string;
|
|
20
20
|
booleanValue: (expr: BooleanValueExpression) => string;
|
|
21
|
+
exists: (expr: ExistsExpression) => string;
|
|
21
22
|
sort: (expr: Sort) => string;
|
|
22
23
|
sorts: (sorts: Sort[]) => string;
|
|
24
|
+
queryOrRaw: (expr: Query | RawExpression) => string;
|
|
23
25
|
};
|
|
@@ -42,9 +42,13 @@ export const Sql = {
|
|
|
42
42
|
};
|
|
43
43
|
return `${Sql.value(expr.left)} ${operator} ${SqlString.escape(val(expr.right, expr.type))}`;
|
|
44
44
|
},
|
|
45
|
-
in: (expr) =>
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
in: (expr) => {
|
|
46
|
+
if ('right' in expr)
|
|
47
|
+
return `${Sql.value(expr.left)} ${expr.operator} (${expr.right
|
|
48
|
+
.map(Sql.value)
|
|
49
|
+
.join(', ')})`;
|
|
50
|
+
return `${Sql.value(expr.left)} ${expr.operator} (${Sql.queryOrRaw(expr.query)})`;
|
|
51
|
+
},
|
|
48
52
|
comparison: (expr) => `${Sql.value(expr.left)} ${expr.operator} ${Sql.value(expr.right)}`,
|
|
49
53
|
compound: (expr) => `${Sql.booleanValue(expr.left)} ${expr.operator} ${Sql.booleanValue(expr.right)}`,
|
|
50
54
|
isNull: (expr) => `${Sql.value(expr.expr)} ${expr.isNot ? 'IS NOT NULL' : 'IS NULL'}`,
|
|
@@ -77,15 +81,33 @@ export const Sql = {
|
|
|
77
81
|
return Sql.in(expr);
|
|
78
82
|
case QueryNodeKind.IsNullExpr:
|
|
79
83
|
return Sql.isNull(expr);
|
|
84
|
+
case QueryNodeKind.Exists:
|
|
85
|
+
return Sql.exists(expr);
|
|
80
86
|
}
|
|
81
87
|
},
|
|
88
|
+
exists: (expr) => {
|
|
89
|
+
return `EXISTS (${Sql.queryOrRaw(expr.query)})`;
|
|
90
|
+
},
|
|
82
91
|
sort: (expr) => {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
const field = () => {
|
|
93
|
+
switch (expr.field.kind) {
|
|
94
|
+
case QueryNodeKind.Field:
|
|
95
|
+
return Sql.fieldInCondition(expr.field);
|
|
96
|
+
case QueryNodeKind.Identifier:
|
|
97
|
+
return Sql.identifier(expr.field);
|
|
98
|
+
default:
|
|
99
|
+
return Sql.fn(expr.field);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
86
102
|
if (expr.direction)
|
|
87
|
-
return `${
|
|
88
|
-
return
|
|
103
|
+
return `${field()} ${expr.direction === 'DESC' ? 'DESC' : 'ASC'}`;
|
|
104
|
+
return field();
|
|
89
105
|
},
|
|
90
106
|
sorts: (sorts) => sorts.map(Sql.sort).join(', '),
|
|
107
|
+
queryOrRaw: (expr) => {
|
|
108
|
+
if ('kind' in expr) {
|
|
109
|
+
return expr.expr;
|
|
110
|
+
}
|
|
111
|
+
return queryToSql(expr);
|
|
112
|
+
},
|
|
91
113
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BooleanValueExpression,
|
|
1
|
+
import { BooleanValueExpression, ListQueryOption } from '../index.js';
|
|
2
2
|
import { Sort } from './dsl/query/query.js';
|
|
3
3
|
type DsPagingOption = {
|
|
4
4
|
numberOfItem: number;
|
|
@@ -6,5 +6,5 @@ type DsPagingOption = {
|
|
|
6
6
|
offset?: number;
|
|
7
7
|
sort?: Sort[];
|
|
8
8
|
};
|
|
9
|
-
export declare const pagingOption: (option:
|
|
9
|
+
export declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
10
10
|
export {};
|
|
@@ -2,7 +2,7 @@ import { CommandResponse, RelationMap } from '../index.js';
|
|
|
2
2
|
import { Fields } from './field.js';
|
|
3
3
|
import { SQLExecutor, SqlValueType } from '../db/connectors/dbClient.js';
|
|
4
4
|
import { TableInfo } from './dsl/query/createQueryResolveInfo.js';
|
|
5
|
-
import { BooleanValueExpression, LockMode, Sort } from './dsl/query/query.js';
|
|
5
|
+
import { BooleanValueExpression, Join, LockMode, Sort } from './dsl/query/query.js';
|
|
6
6
|
import { PagingOption } from './sql/runQuery.js';
|
|
7
7
|
export type EntityType = Record<string, SqlValueType>;
|
|
8
8
|
export type EntityResult<Entity, Identifiable> = Identifiable & Partial<Entity>;
|
|
@@ -16,6 +16,7 @@ export type ListQueryOption = {
|
|
|
16
16
|
offset?: number;
|
|
17
17
|
order?: string;
|
|
18
18
|
asc?: boolean;
|
|
19
|
+
join?: Join[];
|
|
19
20
|
};
|
|
20
21
|
export type QueryOptions = {
|
|
21
22
|
where?: BooleanValueExpression;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDbClient,
|
|
1
|
+
import { getDbClient, qe } from '../index.js';
|
|
2
2
|
import { createQueryResolveInfo, } from './dsl/query/createQueryResolveInfo.js';
|
|
3
3
|
import { createToSql, deleteToSql, updateToSql, } from './dsl/mutation/mutation.js';
|
|
4
4
|
import { createPagingFieldQuery, createQuery, } from './sql/runQuery.js';
|
|
@@ -96,9 +96,9 @@ export class SasatDBDatasource {
|
|
|
96
96
|
const value = entity[it];
|
|
97
97
|
if (!value)
|
|
98
98
|
throw new Error(`field ${it} is required`);
|
|
99
|
-
return
|
|
99
|
+
return qe.eq(qe.field(this.tableName, this.tableInfo[this.tableName].columnMap[it]), qe.value(value));
|
|
100
100
|
});
|
|
101
|
-
return
|
|
101
|
+
return qe.and(...expr);
|
|
102
102
|
}
|
|
103
103
|
getRelationMap() {
|
|
104
104
|
return this.relationMap[this.tableName];
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { BooleanValueExpression, Query, Sort } from '../dsl/query/query.js';
|
|
1
|
+
import { BooleanValueExpression, Join, Query, Sort } from '../dsl/query/query.js';
|
|
2
2
|
import { SQLExecutor } from '../../db/connectors/dbClient.js';
|
|
3
3
|
import { RelationMap, TableInfo } from '../dsl/query/createQueryResolveInfo.js';
|
|
4
4
|
import { Fields } from '../field.js';
|
|
5
5
|
import { QueryResolveInfo } from '../dsl/query/sql/hydrate.js';
|
|
6
|
-
import {
|
|
6
|
+
import { QueryOptions } from '../sasatDBDatasource.js';
|
|
7
7
|
export declare const createQuery: (baseTableName: string, fields: Fields<unknown>, options: QueryOptions | undefined, tableInfo: TableInfo, relationMap: RelationMap, context?: unknown) => Query;
|
|
8
8
|
export type PagingOption = {
|
|
9
9
|
numberOfItem: number;
|
|
10
10
|
where?: BooleanValueExpression;
|
|
11
11
|
offset?: number;
|
|
12
12
|
sort?: Sort[];
|
|
13
|
+
join?: Join[];
|
|
13
14
|
};
|
|
14
15
|
export declare const createPagingInnerQuery: (tableName: string, tableAlias: string, fields: Fields<unknown>, option: PagingOption, tableInfo: TableInfo, relationMap: RelationMap) => Query;
|
|
15
16
|
export declare const runQuery: (client: SQLExecutor, query: Query, resolveInfo: QueryResolveInfo) => Promise<unknown[]>;
|
|
@@ -19,9 +20,7 @@ type CreatePagingFieldQueryArg = {
|
|
|
19
20
|
tableInfo: TableInfo;
|
|
20
21
|
relationMap: RelationMap;
|
|
21
22
|
queryOption?: QueryOptions;
|
|
22
|
-
pagingOption:
|
|
23
|
-
where?: BooleanValueExpression;
|
|
24
|
-
};
|
|
23
|
+
pagingOption: PagingOption;
|
|
25
24
|
context?: unknown;
|
|
26
25
|
};
|
|
27
26
|
export declare const createPagingFieldQuery: ({ baseTableName, fields, queryOption, pagingOption, tableInfo, relationMap, context, }: CreatePagingFieldQueryArg) => Query;
|
|
@@ -27,7 +27,7 @@ export const createQuery = (baseTableName, fields, options, tableInfo, relationM
|
|
|
27
27
|
const rel = relationMap[tableName][relationName];
|
|
28
28
|
if (!rel)
|
|
29
29
|
return undefined;
|
|
30
|
-
return QExpr.join(resolveFields(rel.table, table), QExpr.
|
|
30
|
+
return QExpr.join(resolveFields(rel.table, table), QExpr.and(rel.condition({
|
|
31
31
|
parentTableAlias: tableAlias,
|
|
32
32
|
childTableAlias: table.tableAlias || 't' + current,
|
|
33
33
|
context,
|
|
@@ -54,7 +54,7 @@ export const createPagingInnerQuery = (tableName, tableAlias, fields, option, ta
|
|
|
54
54
|
.filter(it => notTypeName(it) && map[it])
|
|
55
55
|
.map(it => map[it] || it),
|
|
56
56
|
]).map(it => QExpr.field(tableAlias, it)),
|
|
57
|
-
from: QExpr.table(tableName, [], tableAlias),
|
|
57
|
+
from: QExpr.table(tableName, option.join || [], tableAlias),
|
|
58
58
|
limit: option.numberOfItem,
|
|
59
59
|
offset: option.offset,
|
|
60
60
|
where: option.where,
|