sasat 0.21.5 → 0.21.7

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 CHANGED
@@ -164,8 +164,6 @@ class BaseColumn {
164
164
  return !this.data.notNull;
165
165
  }
166
166
  isNullableOnCreate() {
167
- if (this.data.hasReference)
168
- return false;
169
167
  return !this.data.notNull || this.data.default !== void 0 || this.data.autoIncrement;
170
168
  }
171
169
  isReference() {
@@ -4759,7 +4757,7 @@ class ReferenceNode {
4759
4757
  ref.parentTable,
4760
4758
  makeJoinCondition(ref.parentColumn, column.columnName()),
4761
4759
  false,
4762
- false,
4760
+ column.isNullable(),
4763
4761
  column.isPrimary(),
4764
4762
  column.table.gqlOption.enabled && parentTable.gqlOption.enabled
4765
4763
  );
package/dist/cli/cli.mjs CHANGED
@@ -139,8 +139,6 @@ class BaseColumn {
139
139
  return !this.data.notNull;
140
140
  }
141
141
  isNullableOnCreate() {
142
- if (this.data.hasReference)
143
- return false;
144
142
  return !this.data.notNull || this.data.default !== void 0 || this.data.autoIncrement;
145
143
  }
146
144
  isReference() {
@@ -4734,7 +4732,7 @@ class ReferenceNode {
4734
4732
  ref.parentTable,
4735
4733
  makeJoinCondition(ref.parentColumn, column.columnName()),
4736
4734
  false,
4737
- false,
4735
+ column.isNullable(),
4738
4736
  column.isPrimary(),
4739
4737
  column.table.gqlOption.enabled && parentTable.gqlOption.enabled
4740
4738
  );
package/dist/index.cjs CHANGED
@@ -43,30 +43,6 @@ var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
43
43
  return QueryNodeKind2;
44
44
  })(QueryNodeKind || {});
45
45
 
46
- const getJoin = (from) => {
47
- return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
48
- };
49
- const getLock = (lock) => {
50
- if (!lock)
51
- return "";
52
- if (lock === "FOR UPDATE")
53
- return " FOR UPDATE";
54
- return " FOR SHARE";
55
- };
56
- const queryToSql = (query) => {
57
- const select = query.select.map(Sql.select).join(", ");
58
- const join = getJoin(query.from).map(Sql.join).join(" ");
59
- const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
60
- const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
61
- const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
62
- const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
63
- const limit = query.limit ? " LIMIT " + query.limit : "";
64
- const offset = query.offset ? " OFFSET " + query.offset : "";
65
- if (offset && !limit)
66
- throw new Error("LIMIT is required to use OFFSET.");
67
- return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
68
- };
69
-
70
46
  const SELECT_ALIAS_SEPARATOR = "__";
71
47
  const Sql = {
72
48
  select: (expr) => {
@@ -183,6 +159,30 @@ const Sql = {
183
159
  }
184
160
  };
185
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
+
186
186
  const makeParamsMiddleware = (update) => {
187
187
  return (args) => {
188
188
  args[1] = update(args[1]);
@@ -1067,3 +1067,4 @@ exports.makeParamsMiddleware = makeParamsMiddleware;
1067
1067
  exports.makeResolver = makeResolver;
1068
1068
  exports.pagingOption = pagingOption;
1069
1069
  exports.qe = QExpr;
1070
+ exports.queryToSql = queryToSql;
package/dist/index.d.cts CHANGED
@@ -148,6 +148,8 @@ type Sort = {
148
148
  direction?: SortDirection;
149
149
  };
150
150
 
151
+ declare const queryToSql: (query: Query) => string;
152
+
151
153
  type QueryResponse = Array<{
152
154
  [key: string]: SqlValueType;
153
155
  }>;
@@ -1084,4 +1086,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
1084
1086
 
1085
1087
  type PagingOption = ListQueryOption;
1086
1088
 
1087
- 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 };
1089
+ 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, queryToSql };
package/dist/index.d.mts CHANGED
@@ -148,6 +148,8 @@ type Sort = {
148
148
  direction?: SortDirection;
149
149
  };
150
150
 
151
+ declare const queryToSql: (query: Query) => string;
152
+
151
153
  type QueryResponse = Array<{
152
154
  [key: string]: SqlValueType;
153
155
  }>;
@@ -1084,4 +1086,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
1084
1086
 
1085
1087
  type PagingOption = ListQueryOption;
1086
1088
 
1087
- 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 };
1089
+ 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, queryToSql };
package/dist/index.d.ts CHANGED
@@ -148,6 +148,8 @@ type Sort = {
148
148
  direction?: SortDirection;
149
149
  };
150
150
 
151
+ declare const queryToSql: (query: Query) => string;
152
+
151
153
  type QueryResponse = Array<{
152
154
  [key: string]: SqlValueType;
153
155
  }>;
@@ -1084,4 +1086,4 @@ declare const pagingOption: (option: ListQueryOption) => DsPagingOption;
1084
1086
 
1085
1087
  type PagingOption = ListQueryOption;
1086
1088
 
1087
- 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 };
1089
+ 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, queryToSql };
package/dist/index.mjs CHANGED
@@ -28,30 +28,6 @@ var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
28
28
  return QueryNodeKind2;
29
29
  })(QueryNodeKind || {});
30
30
 
31
- const getJoin = (from) => {
32
- return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
33
- };
34
- const getLock = (lock) => {
35
- if (!lock)
36
- return "";
37
- if (lock === "FOR UPDATE")
38
- return " FOR UPDATE";
39
- return " FOR SHARE";
40
- };
41
- const queryToSql = (query) => {
42
- const select = query.select.map(Sql.select).join(", ");
43
- const join = getJoin(query.from).map(Sql.join).join(" ");
44
- const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
45
- const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
46
- const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
47
- const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
48
- const limit = query.limit ? " LIMIT " + query.limit : "";
49
- const offset = query.offset ? " OFFSET " + query.offset : "";
50
- if (offset && !limit)
51
- throw new Error("LIMIT is required to use OFFSET.");
52
- return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
53
- };
54
-
55
31
  const SELECT_ALIAS_SEPARATOR = "__";
56
32
  const Sql = {
57
33
  select: (expr) => {
@@ -168,6 +144,30 @@ const Sql = {
168
144
  }
169
145
  };
170
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
+
171
171
  const makeParamsMiddleware = (update) => {
172
172
  return (args) => {
173
173
  args[1] = update(args[1]);
@@ -1026,4 +1026,4 @@ const pagingOption = (option) => {
1026
1026
  return { numberOfItem: option.numberOfItem, offset: option.offset, sort };
1027
1027
  };
1028
1028
 
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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.21.5",
3
+ "version": "0.21.7",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",