sasat 0.21.6 → 0.21.8
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/dist/cli/cli.cjs +13 -3
- package/dist/cli/cli.mjs +13 -3
- package/dist/index.cjs +26 -27
- package/dist/index.d.cts +9 -2
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.mjs +27 -28
- package/dist/shared/{sasat.f544328b.cjs → sasat.19043592.cjs} +13 -1
- package/dist/shared/{sasat.01289068.mjs → sasat.f15e60f6.mjs} +13 -1
- package/package.json +1 -1
package/dist/cli/cli.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const cac = require('cac');
|
|
5
|
-
const error = require('../shared/sasat.
|
|
5
|
+
const error = require('../shared/sasat.19043592.cjs');
|
|
6
6
|
require('pluralize');
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
@@ -1398,7 +1398,6 @@ const writeDiagram = async () => {
|
|
|
1398
1398
|
const result = `erDiagram
|
|
1399
1399
|
${entities.join("\n")}
|
|
1400
1400
|
`;
|
|
1401
|
-
console.log();
|
|
1402
1401
|
fs__default.writeFileSync(
|
|
1403
1402
|
path__default.join(
|
|
1404
1403
|
error.config().migration.out,
|
|
@@ -1431,7 +1430,7 @@ function processTable(store, table) {
|
|
|
1431
1430
|
const rel2 = it;
|
|
1432
1431
|
const ref = rel2.data.reference;
|
|
1433
1432
|
const parent = store.table(ref.parentTable).column(ref.parentColumn);
|
|
1434
|
-
return `${ref.parentTable} ${getRefType(parent, ref.relation)} ${table.tableName} : ${ref.relationName}`;
|
|
1433
|
+
return `${ref.parentTable} ${getRefType(parent, ref.relation)} ${table.tableName} : ${ref.relationName ?? rel2.data.reference.parentTable + "<->" + rel2.table.tableName}`;
|
|
1435
1434
|
});
|
|
1436
1435
|
return `${table.tableName} {
|
|
1437
1436
|
${table.columns.map((it) => ` ${it.columnName()} ${it.dataType()}`).join("\n")}
|
|
@@ -3625,6 +3624,9 @@ const makeConditionExpr = (entity, condition) => {
|
|
|
3625
3624
|
if (condition.kind === "custom") {
|
|
3626
3625
|
return tsg.identifier(condition.conditionName).importFrom("../conditions").call(tsg.identifier("arg"));
|
|
3627
3626
|
}
|
|
3627
|
+
if (condition.kind === "isNull") {
|
|
3628
|
+
return qExpr.property(condition.not ? "isNotNull" : "isNull").call(makeJoinConditionValueQExpr(entity, condition.value));
|
|
3629
|
+
}
|
|
3628
3630
|
if (condition.operator === "BETWEEN") {
|
|
3629
3631
|
return qExpr.property("between").call(
|
|
3630
3632
|
makeJoinConditionValueQExpr(entity, condition.left),
|
|
@@ -3669,6 +3671,8 @@ const getChildConditionValue = (cv) => {
|
|
|
3669
3671
|
const getConditionChildColumnNames = (getConditionValue) => (c) => {
|
|
3670
3672
|
if (c.kind === "custom")
|
|
3671
3673
|
return c.childRequiredFields || [];
|
|
3674
|
+
if (c.kind === "isNull")
|
|
3675
|
+
return [];
|
|
3672
3676
|
const result = [getConditionValue(c.left)];
|
|
3673
3677
|
if (c.operator === "IN") {
|
|
3674
3678
|
result.push(getConditionValue(c.left));
|
|
@@ -4850,6 +4854,12 @@ const reverseConditionNode = (condition) => {
|
|
|
4850
4854
|
parentRequiredFields: condition.childRequiredFields,
|
|
4851
4855
|
childRequiredFields: condition.parentRequiredFields
|
|
4852
4856
|
};
|
|
4857
|
+
if (condition.kind === "isNull") {
|
|
4858
|
+
if (condition.not) {
|
|
4859
|
+
return error.Conditions.rel.isNotNull(reverseConditionValue(condition.value));
|
|
4860
|
+
}
|
|
4861
|
+
return error.Conditions.rel.isNull(reverseConditionValue(condition.value));
|
|
4862
|
+
}
|
|
4853
4863
|
if (condition.operator === "BETWEEN") {
|
|
4854
4864
|
return error.Conditions.rel.between(
|
|
4855
4865
|
reverseConditionValue(condition.left),
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cac } from 'cac';
|
|
3
|
-
import { S as SqlString, a as SasatError, c as config, r as readInitialSchema, g as getDbClient, m as mkDirIfNotExist, n as nonNullable, u as unique, C as Conditions, w as writeFileIfNotExist, b as writeCurrentSchema, d as writeYmlFile, e as defaultConf } from '../shared/sasat.
|
|
3
|
+
import { S as SqlString, a as SasatError, c as config, r as readInitialSchema, g as getDbClient, m as mkDirIfNotExist, n as nonNullable, u as unique, C as Conditions, w as writeFileIfNotExist, b as writeCurrentSchema, d as writeYmlFile, e as defaultConf } from '../shared/sasat.f15e60f6.mjs';
|
|
4
4
|
import 'pluralize';
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import fs__default from 'fs';
|
|
@@ -1373,7 +1373,6 @@ const writeDiagram = async () => {
|
|
|
1373
1373
|
const result = `erDiagram
|
|
1374
1374
|
${entities.join("\n")}
|
|
1375
1375
|
`;
|
|
1376
|
-
console.log();
|
|
1377
1376
|
fs__default.writeFileSync(
|
|
1378
1377
|
path__default.join(
|
|
1379
1378
|
config().migration.out,
|
|
@@ -1406,7 +1405,7 @@ function processTable(store, table) {
|
|
|
1406
1405
|
const rel2 = it;
|
|
1407
1406
|
const ref = rel2.data.reference;
|
|
1408
1407
|
const parent = store.table(ref.parentTable).column(ref.parentColumn);
|
|
1409
|
-
return `${ref.parentTable} ${getRefType(parent, ref.relation)} ${table.tableName} : ${ref.relationName}`;
|
|
1408
|
+
return `${ref.parentTable} ${getRefType(parent, ref.relation)} ${table.tableName} : ${ref.relationName ?? rel2.data.reference.parentTable + "<->" + rel2.table.tableName}`;
|
|
1410
1409
|
});
|
|
1411
1410
|
return `${table.tableName} {
|
|
1412
1411
|
${table.columns.map((it) => ` ${it.columnName()} ${it.dataType()}`).join("\n")}
|
|
@@ -3600,6 +3599,9 @@ const makeConditionExpr = (entity, condition) => {
|
|
|
3600
3599
|
if (condition.kind === "custom") {
|
|
3601
3600
|
return tsg.identifier(condition.conditionName).importFrom("../conditions").call(tsg.identifier("arg"));
|
|
3602
3601
|
}
|
|
3602
|
+
if (condition.kind === "isNull") {
|
|
3603
|
+
return qExpr.property(condition.not ? "isNotNull" : "isNull").call(makeJoinConditionValueQExpr(entity, condition.value));
|
|
3604
|
+
}
|
|
3603
3605
|
if (condition.operator === "BETWEEN") {
|
|
3604
3606
|
return qExpr.property("between").call(
|
|
3605
3607
|
makeJoinConditionValueQExpr(entity, condition.left),
|
|
@@ -3644,6 +3646,8 @@ const getChildConditionValue = (cv) => {
|
|
|
3644
3646
|
const getConditionChildColumnNames = (getConditionValue) => (c) => {
|
|
3645
3647
|
if (c.kind === "custom")
|
|
3646
3648
|
return c.childRequiredFields || [];
|
|
3649
|
+
if (c.kind === "isNull")
|
|
3650
|
+
return [];
|
|
3647
3651
|
const result = [getConditionValue(c.left)];
|
|
3648
3652
|
if (c.operator === "IN") {
|
|
3649
3653
|
result.push(getConditionValue(c.left));
|
|
@@ -4825,6 +4829,12 @@ const reverseConditionNode = (condition) => {
|
|
|
4825
4829
|
parentRequiredFields: condition.childRequiredFields,
|
|
4826
4830
|
childRequiredFields: condition.parentRequiredFields
|
|
4827
4831
|
};
|
|
4832
|
+
if (condition.kind === "isNull") {
|
|
4833
|
+
if (condition.not) {
|
|
4834
|
+
return Conditions.rel.isNotNull(reverseConditionValue(condition.value));
|
|
4835
|
+
}
|
|
4836
|
+
return Conditions.rel.isNull(reverseConditionValue(condition.value));
|
|
4837
|
+
}
|
|
4828
4838
|
if (condition.operator === "BETWEEN") {
|
|
4829
4839
|
return Conditions.rel.between(
|
|
4830
4840
|
reverseConditionValue(condition.left),
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const error = require('./shared/sasat.f544328b.cjs');
|
|
3
|
+
const error = require('./shared/sasat.19043592.cjs');
|
|
5
4
|
const SqlString = require('sqlstring');
|
|
6
5
|
require('mysql2');
|
|
7
6
|
require('util');
|
|
@@ -44,30 +43,6 @@ var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
|
|
|
44
43
|
return QueryNodeKind2;
|
|
45
44
|
})(QueryNodeKind || {});
|
|
46
45
|
|
|
47
|
-
const getJoin = (from) => {
|
|
48
|
-
return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
|
|
49
|
-
};
|
|
50
|
-
const getLock = (lock) => {
|
|
51
|
-
if (!lock)
|
|
52
|
-
return "";
|
|
53
|
-
if (lock === "FOR UPDATE")
|
|
54
|
-
return " FOR UPDATE";
|
|
55
|
-
return " FOR SHARE";
|
|
56
|
-
};
|
|
57
|
-
const queryToSql = (query) => {
|
|
58
|
-
const select = query.select.map(Sql.select).join(", ");
|
|
59
|
-
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
60
|
-
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
61
|
-
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
62
|
-
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
63
|
-
const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
|
|
64
|
-
const limit = query.limit ? " LIMIT " + query.limit : "";
|
|
65
|
-
const offset = query.offset ? " OFFSET " + query.offset : "";
|
|
66
|
-
if (offset && !limit)
|
|
67
|
-
throw new Error("LIMIT is required to use OFFSET.");
|
|
68
|
-
return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
46
|
const SELECT_ALIAS_SEPARATOR = "__";
|
|
72
47
|
const Sql = {
|
|
73
48
|
select: (expr) => {
|
|
@@ -184,6 +159,30 @@ const Sql = {
|
|
|
184
159
|
}
|
|
185
160
|
};
|
|
186
161
|
|
|
162
|
+
const getJoin = (from) => {
|
|
163
|
+
return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
|
|
164
|
+
};
|
|
165
|
+
const getLock = (lock) => {
|
|
166
|
+
if (!lock)
|
|
167
|
+
return "";
|
|
168
|
+
if (lock === "FOR UPDATE")
|
|
169
|
+
return " FOR UPDATE";
|
|
170
|
+
return " FOR SHARE";
|
|
171
|
+
};
|
|
172
|
+
const queryToSql = (query) => {
|
|
173
|
+
const select = query.select.map(Sql.select).join(", ");
|
|
174
|
+
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
175
|
+
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
176
|
+
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
177
|
+
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
178
|
+
const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
|
|
179
|
+
const limit = query.limit ? " LIMIT " + query.limit : "";
|
|
180
|
+
const offset = query.offset ? " OFFSET " + query.offset : "";
|
|
181
|
+
if (offset && !limit)
|
|
182
|
+
throw new Error("LIMIT is required to use OFFSET.");
|
|
183
|
+
return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
|
|
184
|
+
};
|
|
185
|
+
|
|
187
186
|
const makeParamsMiddleware = (update) => {
|
|
188
187
|
return (args) => {
|
|
189
188
|
args[1] = update(args[1]);
|
|
@@ -1042,7 +1041,6 @@ const pagingOption = (option) => {
|
|
|
1042
1041
|
return { numberOfItem: option.numberOfItem, offset: option.offset, sort };
|
|
1043
1042
|
};
|
|
1044
1043
|
|
|
1045
|
-
exports.queryToSql = queryToSql_js.queryToSql;
|
|
1046
1044
|
exports.Conditions = error.Conditions;
|
|
1047
1045
|
exports.SqlString = error.SqlString;
|
|
1048
1046
|
exports.getDbClient = error.getDbClient;
|
|
@@ -1069,3 +1067,4 @@ exports.makeParamsMiddleware = makeParamsMiddleware;
|
|
|
1069
1067
|
exports.makeResolver = makeResolver;
|
|
1070
1068
|
exports.pagingOption = pagingOption;
|
|
1071
1069
|
exports.qe = QExpr;
|
|
1070
|
+
exports.queryToSql = queryToSql;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { queryToSql } from 'runtime/dsl/query/sql/queryToSql.js';
|
|
2
1
|
import pkg from 'sqlstring';
|
|
3
2
|
import { GraphQLResolveInfo } from 'graphql/type';
|
|
4
3
|
import Hashids from 'hashids';
|
|
@@ -149,6 +148,8 @@ type Sort = {
|
|
|
149
148
|
direction?: SortDirection;
|
|
150
149
|
};
|
|
151
150
|
|
|
151
|
+
declare const queryToSql: (query: Query) => string;
|
|
152
|
+
|
|
152
153
|
type QueryResponse = Array<{
|
|
153
154
|
[key: string]: SqlValueType;
|
|
154
155
|
}>;
|
|
@@ -513,6 +514,10 @@ type JoinConditionNode = {
|
|
|
513
514
|
left: JoinConditionValue;
|
|
514
515
|
operator: 'IN';
|
|
515
516
|
right: JoinConditionValue[];
|
|
517
|
+
} | {
|
|
518
|
+
kind: 'isNull';
|
|
519
|
+
value: JoinConditionValue;
|
|
520
|
+
not: boolean;
|
|
516
521
|
} | JoinCustomConditionNode;
|
|
517
522
|
type JoinCustomConditionNode = {
|
|
518
523
|
kind: 'custom';
|
|
@@ -716,6 +721,8 @@ declare const Conditions: {
|
|
|
716
721
|
readonly between: (left: JoinConditionValue, range: JoinConditionRangeValue) => JoinConditionNode;
|
|
717
722
|
readonly comparison: (left: JoinConditionValue, operator: ComparisonOperators, right: JoinConditionValue) => JoinConditionNode;
|
|
718
723
|
readonly in: (left: JoinConditionValue, right: JoinConditionValue[]) => JoinConditionNode;
|
|
724
|
+
readonly isNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
725
|
+
readonly isNotNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
719
726
|
};
|
|
720
727
|
readonly query: {
|
|
721
728
|
readonly between: (left: QueryConditionValue, begin: QueryConditionValue, end: QueryConditionValue) => QueryConditionNode;
|
|
@@ -1085,4 +1092,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1085
1092
|
|
|
1086
1093
|
type PagingOption = ListQueryOption;
|
|
1087
1094
|
|
|
1088
|
-
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe };
|
|
1095
|
+
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLClient, type SQLExecutor, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { queryToSql } from 'runtime/dsl/query/sql/queryToSql.js';
|
|
2
1
|
import pkg from 'sqlstring';
|
|
3
2
|
import { GraphQLResolveInfo } from 'graphql/type';
|
|
4
3
|
import Hashids from 'hashids';
|
|
@@ -149,6 +148,8 @@ type Sort = {
|
|
|
149
148
|
direction?: SortDirection;
|
|
150
149
|
};
|
|
151
150
|
|
|
151
|
+
declare const queryToSql: (query: Query) => string;
|
|
152
|
+
|
|
152
153
|
type QueryResponse = Array<{
|
|
153
154
|
[key: string]: SqlValueType;
|
|
154
155
|
}>;
|
|
@@ -513,6 +514,10 @@ type JoinConditionNode = {
|
|
|
513
514
|
left: JoinConditionValue;
|
|
514
515
|
operator: 'IN';
|
|
515
516
|
right: JoinConditionValue[];
|
|
517
|
+
} | {
|
|
518
|
+
kind: 'isNull';
|
|
519
|
+
value: JoinConditionValue;
|
|
520
|
+
not: boolean;
|
|
516
521
|
} | JoinCustomConditionNode;
|
|
517
522
|
type JoinCustomConditionNode = {
|
|
518
523
|
kind: 'custom';
|
|
@@ -716,6 +721,8 @@ declare const Conditions: {
|
|
|
716
721
|
readonly between: (left: JoinConditionValue, range: JoinConditionRangeValue) => JoinConditionNode;
|
|
717
722
|
readonly comparison: (left: JoinConditionValue, operator: ComparisonOperators, right: JoinConditionValue) => JoinConditionNode;
|
|
718
723
|
readonly in: (left: JoinConditionValue, right: JoinConditionValue[]) => JoinConditionNode;
|
|
724
|
+
readonly isNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
725
|
+
readonly isNotNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
719
726
|
};
|
|
720
727
|
readonly query: {
|
|
721
728
|
readonly between: (left: QueryConditionValue, begin: QueryConditionValue, end: QueryConditionValue) => QueryConditionNode;
|
|
@@ -1085,4 +1092,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1085
1092
|
|
|
1086
1093
|
type PagingOption = ListQueryOption;
|
|
1087
1094
|
|
|
1088
|
-
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe };
|
|
1095
|
+
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLClient, type SQLExecutor, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { queryToSql } from 'runtime/dsl/query/sql/queryToSql.js';
|
|
2
1
|
import pkg from 'sqlstring';
|
|
3
2
|
import { GraphQLResolveInfo } from 'graphql/type';
|
|
4
3
|
import Hashids from 'hashids';
|
|
@@ -149,6 +148,8 @@ type Sort = {
|
|
|
149
148
|
direction?: SortDirection;
|
|
150
149
|
};
|
|
151
150
|
|
|
151
|
+
declare const queryToSql: (query: Query) => string;
|
|
152
|
+
|
|
152
153
|
type QueryResponse = Array<{
|
|
153
154
|
[key: string]: SqlValueType;
|
|
154
155
|
}>;
|
|
@@ -513,6 +514,10 @@ type JoinConditionNode = {
|
|
|
513
514
|
left: JoinConditionValue;
|
|
514
515
|
operator: 'IN';
|
|
515
516
|
right: JoinConditionValue[];
|
|
517
|
+
} | {
|
|
518
|
+
kind: 'isNull';
|
|
519
|
+
value: JoinConditionValue;
|
|
520
|
+
not: boolean;
|
|
516
521
|
} | JoinCustomConditionNode;
|
|
517
522
|
type JoinCustomConditionNode = {
|
|
518
523
|
kind: 'custom';
|
|
@@ -716,6 +721,8 @@ declare const Conditions: {
|
|
|
716
721
|
readonly between: (left: JoinConditionValue, range: JoinConditionRangeValue) => JoinConditionNode;
|
|
717
722
|
readonly comparison: (left: JoinConditionValue, operator: ComparisonOperators, right: JoinConditionValue) => JoinConditionNode;
|
|
718
723
|
readonly in: (left: JoinConditionValue, right: JoinConditionValue[]) => JoinConditionNode;
|
|
724
|
+
readonly isNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
725
|
+
readonly isNotNull: (value: JoinConditionValue) => JoinConditionNode;
|
|
719
726
|
};
|
|
720
727
|
readonly query: {
|
|
721
728
|
readonly between: (left: QueryConditionValue, begin: QueryConditionValue, end: QueryConditionValue) => QueryConditionNode;
|
|
@@ -1085,4 +1092,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
|
|
|
1085
1092
|
|
|
1086
1093
|
type PagingOption = ListQueryOption;
|
|
1087
1094
|
|
|
1088
|
-
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe };
|
|
1095
|
+
export { type BooleanValueExpression, type CommandResponse, type ComparisonOperators, CompositeCondition, Conditions, type CustomCondition, type EntityResult, type EntityType, type Fields, type ListQueryOption, type LockMode, type MigrationStore, Mutations, type PagingOption, QExpr, Queries, type Query, type QueryOptions, type QueryResponse, type Relation, type RelationMap, type ResolverMiddleware, SQLClient, type SQLExecutor, SQLTransaction, SasatDBDatasource, type SasatMigration, Sql, SqlString, type TableInfo, type TypeFieldDefinition, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, pick, QExpr as qe, queryToSql };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { C as Conditions, p as pick } from './shared/sasat.01289068.mjs';
|
|
1
|
+
import { S as SqlString$1, n as nonNullable, u as unique, g as getDbClient, a as SasatError } from './shared/sasat.f15e60f6.mjs';
|
|
2
|
+
export { C as Conditions, p as pick } from './shared/sasat.f15e60f6.mjs';
|
|
4
3
|
import * as SqlString from 'sqlstring';
|
|
5
4
|
import 'mysql2';
|
|
6
5
|
import 'util';
|
|
@@ -29,30 +28,6 @@ var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
|
|
|
29
28
|
return QueryNodeKind2;
|
|
30
29
|
})(QueryNodeKind || {});
|
|
31
30
|
|
|
32
|
-
const getJoin = (from) => {
|
|
33
|
-
return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
|
|
34
|
-
};
|
|
35
|
-
const getLock = (lock) => {
|
|
36
|
-
if (!lock)
|
|
37
|
-
return "";
|
|
38
|
-
if (lock === "FOR UPDATE")
|
|
39
|
-
return " FOR UPDATE";
|
|
40
|
-
return " FOR SHARE";
|
|
41
|
-
};
|
|
42
|
-
const queryToSql = (query) => {
|
|
43
|
-
const select = query.select.map(Sql.select).join(", ");
|
|
44
|
-
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
45
|
-
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
46
|
-
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
47
|
-
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
48
|
-
const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
|
|
49
|
-
const limit = query.limit ? " LIMIT " + query.limit : "";
|
|
50
|
-
const offset = query.offset ? " OFFSET " + query.offset : "";
|
|
51
|
-
if (offset && !limit)
|
|
52
|
-
throw new Error("LIMIT is required to use OFFSET.");
|
|
53
|
-
return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
31
|
const SELECT_ALIAS_SEPARATOR = "__";
|
|
57
32
|
const Sql = {
|
|
58
33
|
select: (expr) => {
|
|
@@ -169,6 +144,30 @@ const Sql = {
|
|
|
169
144
|
}
|
|
170
145
|
};
|
|
171
146
|
|
|
147
|
+
const getJoin = (from) => {
|
|
148
|
+
return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
|
|
149
|
+
};
|
|
150
|
+
const getLock = (lock) => {
|
|
151
|
+
if (!lock)
|
|
152
|
+
return "";
|
|
153
|
+
if (lock === "FOR UPDATE")
|
|
154
|
+
return " FOR UPDATE";
|
|
155
|
+
return " FOR SHARE";
|
|
156
|
+
};
|
|
157
|
+
const queryToSql = (query) => {
|
|
158
|
+
const select = query.select.map(Sql.select).join(", ");
|
|
159
|
+
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
160
|
+
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
161
|
+
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
162
|
+
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
163
|
+
const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
|
|
164
|
+
const limit = query.limit ? " LIMIT " + query.limit : "";
|
|
165
|
+
const offset = query.offset ? " OFFSET " + query.offset : "";
|
|
166
|
+
if (offset && !limit)
|
|
167
|
+
throw new Error("LIMIT is required to use OFFSET.");
|
|
168
|
+
return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
|
|
169
|
+
};
|
|
170
|
+
|
|
172
171
|
const makeParamsMiddleware = (update) => {
|
|
173
172
|
return (args) => {
|
|
174
173
|
args[1] = update(args[1]);
|
|
@@ -1027,4 +1026,4 @@ const pagingOption = (option) => {
|
|
|
1027
1026
|
return { numberOfItem: option.numberOfItem, offset: option.offset, sort };
|
|
1028
1027
|
};
|
|
1029
1028
|
|
|
1030
|
-
export { CompositeCondition, Mutations, QExpr, Queries, SasatDBDatasource, Sql, SqlString$1 as SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, QExpr as qe };
|
|
1029
|
+
export { CompositeCondition, Mutations, QExpr, Queries, SasatDBDatasource, Sql, SqlString$1 as SqlString, assignDeep, createTypeDef, dateOffset, dateToDateString, dateToDatetimeString, getCurrentDateTimeString, getDayRange, getDayRangeQExpr, getDbClient, getTodayDateString, getTodayDateTimeString, gqlResolveInfoToField, makeNumberIdEncoder, makeParamsMiddleware, makeResolver, pagingOption, QExpr as qe, queryToSql };
|
|
@@ -119,6 +119,16 @@ const inRel = (left, right) => ({
|
|
|
119
119
|
right,
|
|
120
120
|
operator: "IN"
|
|
121
121
|
});
|
|
122
|
+
const isNullRel = (value) => ({
|
|
123
|
+
kind: "isNull",
|
|
124
|
+
value,
|
|
125
|
+
not: false
|
|
126
|
+
});
|
|
127
|
+
const isNotNullRel = (value) => ({
|
|
128
|
+
kind: "isNull",
|
|
129
|
+
value,
|
|
130
|
+
not: true
|
|
131
|
+
});
|
|
122
132
|
const comparisonQuery = (left, operator, right) => ({
|
|
123
133
|
kind: "comparison",
|
|
124
134
|
left,
|
|
@@ -132,7 +142,9 @@ const Conditions = {
|
|
|
132
142
|
rel: {
|
|
133
143
|
between: betweenRel,
|
|
134
144
|
comparison: comparisonRel,
|
|
135
|
-
in: inRel
|
|
145
|
+
in: inRel,
|
|
146
|
+
isNull: isNullRel,
|
|
147
|
+
isNotNull: isNotNullRel
|
|
136
148
|
},
|
|
137
149
|
query: {
|
|
138
150
|
between: betweenQuery,
|
|
@@ -97,6 +97,16 @@ const inRel = (left, right) => ({
|
|
|
97
97
|
right,
|
|
98
98
|
operator: "IN"
|
|
99
99
|
});
|
|
100
|
+
const isNullRel = (value) => ({
|
|
101
|
+
kind: "isNull",
|
|
102
|
+
value,
|
|
103
|
+
not: false
|
|
104
|
+
});
|
|
105
|
+
const isNotNullRel = (value) => ({
|
|
106
|
+
kind: "isNull",
|
|
107
|
+
value,
|
|
108
|
+
not: true
|
|
109
|
+
});
|
|
100
110
|
const comparisonQuery = (left, operator, right) => ({
|
|
101
111
|
kind: "comparison",
|
|
102
112
|
left,
|
|
@@ -110,7 +120,9 @@ const Conditions = {
|
|
|
110
120
|
rel: {
|
|
111
121
|
between: betweenRel,
|
|
112
122
|
comparison: comparisonRel,
|
|
113
|
-
in: inRel
|
|
123
|
+
in: inRel,
|
|
124
|
+
isNull: isNullRel,
|
|
125
|
+
isNotNull: isNotNullRel
|
|
114
126
|
},
|
|
115
127
|
query: {
|
|
116
128
|
between: betweenQuery,
|