@sqb/builder 4.26.1 → 5.0.0

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.
Files changed (210) hide show
  1. package/index.d.ts +4 -14
  2. package/index.js +4 -14
  3. package/op.ns.d.ts +64 -0
  4. package/op.ns.js +65 -0
  5. package/package.json +1 -1
  6. package/serializable.d.ts +10 -3
  7. package/serializable.js +7 -2
  8. package/serialize-context.d.ts +2 -2
  9. package/serialize-context.js +1 -1
  10. package/{query/delete-query.d.ts → sql/delete.d.ts} +14 -6
  11. package/{query/delete-query.js → sql/delete.js} +24 -20
  12. package/sql/elements/base-field.d.ts +18 -0
  13. package/sql/elements/base-field.js +12 -0
  14. package/{sql-objects/case-statement.d.ts → sql/elements/case.d.ts} +17 -9
  15. package/{sql-objects/case-statement.js → sql/elements/case.js} +13 -9
  16. package/sql/elements/coalesce.d.ts +30 -0
  17. package/{sql-objects/coalesce-statement.js → sql/elements/coalesce.js} +11 -7
  18. package/sql/elements/count.d.ts +29 -0
  19. package/{sql-objects/count-statement.js → sql/elements/count.js} +10 -3
  20. package/sql/elements/field.d.ts +27 -0
  21. package/sql/elements/field.js +54 -0
  22. package/sql/elements/group-column.d.ts +16 -0
  23. package/{sql-objects → sql/elements}/group-column.js +19 -15
  24. package/sql/elements/index.d.ts +26 -0
  25. package/sql/elements/index.js +26 -0
  26. package/sql/elements/join-cross.d.ts +15 -0
  27. package/sql/elements/join-cross.js +11 -0
  28. package/sql/elements/join-full-outer.d.ts +15 -0
  29. package/sql/elements/join-full-outer.js +11 -0
  30. package/sql/elements/join-inner.d.ts +15 -0
  31. package/sql/elements/join-inner.js +11 -0
  32. package/sql/elements/join-left-outer.d.ts +15 -0
  33. package/sql/elements/join-left-outer.js +11 -0
  34. package/sql/elements/join-left.d.ts +15 -0
  35. package/sql/elements/join-left.js +11 -0
  36. package/sql/elements/join-outer.d.ts +15 -0
  37. package/sql/elements/join-outer.js +11 -0
  38. package/sql/elements/join-right-outer.d.ts +15 -0
  39. package/sql/elements/join-right-outer.js +11 -0
  40. package/sql/elements/join-right.d.ts +15 -0
  41. package/sql/elements/join-right.js +11 -0
  42. package/sql/elements/join.d.ts +25 -0
  43. package/{sql-objects/join-statement.js → sql/elements/join.js} +24 -19
  44. package/sql/elements/lower.d.ts +30 -0
  45. package/{sql-objects/lower-statement.js → sql/elements/lower.js} +11 -7
  46. package/{sql-objects/min-statement.d.ts → sql/elements/max.d.ts} +13 -5
  47. package/{sql-objects/max-statement.js → sql/elements/max.js} +11 -7
  48. package/{sql-objects/lower-statement.d.ts → sql/elements/min.d.ts} +13 -4
  49. package/{sql-objects/min-statement.js → sql/elements/min.js} +10 -3
  50. package/sql/elements/order-column.d.ts +17 -0
  51. package/sql/elements/order-column.js +43 -0
  52. package/sql/elements/param.d.ts +36 -0
  53. package/{sql-objects/param-expression.js → sql/elements/param.js} +26 -13
  54. package/sql/elements/raw.d.ts +17 -0
  55. package/sql/elements/raw.js +19 -0
  56. package/sql/elements/returning-column.d.ts +17 -0
  57. package/sql/elements/returning-column.js +32 -0
  58. package/sql/elements/sequence.d.ts +32 -0
  59. package/{sql-objects/sequence-getter-statement.js → sql/elements/sequence.js} +12 -8
  60. package/{sql-objects/string-agg-statement.d.ts → sql/elements/string-agg.d.ts} +13 -5
  61. package/{sql-objects/string-agg-statement.js → sql/elements/string-agg.js} +15 -12
  62. package/sql/elements/table-name.d.ts +32 -0
  63. package/sql/elements/table-name.js +59 -0
  64. package/sql/elements/upper.d.ts +30 -0
  65. package/{sql-objects/upper-statement.js → sql/elements/upper.js} +11 -7
  66. package/sql/index.d.ts +9 -0
  67. package/sql/index.js +9 -0
  68. package/sql/insert.d.ts +37 -0
  69. package/{query/insert-query.js → sql/insert.js} +33 -18
  70. package/sql/operators/and.d.ts +14 -0
  71. package/sql/operators/and.js +13 -0
  72. package/sql/operators/between.d.ts +18 -0
  73. package/{sql-objects/operators/op-between.js → sql/operators/between.js} +20 -8
  74. package/sql/operators/comp-operator.d.ts +24 -0
  75. package/{sql-objects → sql}/operators/comp-operator.js +27 -21
  76. package/sql/operators/eq.d.ts +13 -0
  77. package/sql/operators/eq.js +23 -0
  78. package/sql/operators/exists.d.ts +17 -0
  79. package/sql/operators/exists.js +31 -0
  80. package/sql/operators/gt.d.ts +13 -0
  81. package/sql/operators/gt.js +20 -0
  82. package/sql/operators/gte.d.ts +13 -0
  83. package/sql/operators/gte.js +20 -0
  84. package/sql/operators/i-like.d.ts +13 -0
  85. package/sql/operators/i-like.js +21 -0
  86. package/sql/operators/in.d.ts +15 -0
  87. package/sql/operators/in.js +27 -0
  88. package/sql/operators/index.d.ts +24 -0
  89. package/sql/operators/index.js +24 -0
  90. package/sql/operators/is-not.d.ts +13 -0
  91. package/sql/operators/is-not.js +13 -0
  92. package/sql/operators/is.d.ts +13 -0
  93. package/sql/operators/is.js +20 -0
  94. package/sql/operators/like.d.ts +15 -0
  95. package/sql/operators/like.js +27 -0
  96. package/sql/operators/logical-operator.d.ts +15 -0
  97. package/sql/operators/logical-operator.js +86 -0
  98. package/sql/operators/lt.d.ts +13 -0
  99. package/sql/operators/lt.js +20 -0
  100. package/sql/operators/lte.d.ts +13 -0
  101. package/sql/operators/lte.js +20 -0
  102. package/sql/operators/ne.d.ts +13 -0
  103. package/sql/operators/ne.js +20 -0
  104. package/sql/operators/not-between.d.ts +15 -0
  105. package/sql/operators/not-between.js +13 -0
  106. package/sql/operators/not-exists.d.ts +14 -0
  107. package/sql/operators/not-exists.js +13 -0
  108. package/sql/operators/not-i-like.d.ts +13 -0
  109. package/sql/operators/not-i-like.js +13 -0
  110. package/sql/operators/not-in.d.ts +13 -0
  111. package/sql/operators/not-in.js +13 -0
  112. package/sql/operators/not-like.d.ts +13 -0
  113. package/sql/operators/not-like.js +13 -0
  114. package/sql/operators/not.d.ts +18 -0
  115. package/sql/operators/not.js +20 -0
  116. package/sql/operators/operator.d.ts +12 -0
  117. package/sql/operators/operator.js +11 -0
  118. package/sql/operators/or.d.ts +12 -0
  119. package/sql/operators/or.js +12 -0
  120. package/sql/query.d.ts +31 -0
  121. package/{query → sql}/query.js +13 -7
  122. package/sql/returning-query.d.ts +23 -0
  123. package/{query → sql}/returning-query.js +13 -3
  124. package/{query/select-query.d.ts → sql/select.d.ts} +20 -12
  125. package/{query/select-query.js → sql/select.js} +21 -17
  126. package/{query/union-query.d.ts → sql/union.d.ts} +10 -2
  127. package/{query/union-query.js → sql/union.js} +10 -6
  128. package/sql/update.d.ts +38 -0
  129. package/{query/update-query.js → sql/update.js} +34 -25
  130. package/type-guards.d.ts +21 -0
  131. package/{typeguards.js → type-guards.js} +10 -10
  132. package/classes.ns.d.ts +0 -38
  133. package/classes.ns.js +0 -38
  134. package/op.initializers.d.ts +0 -89
  135. package/op.initializers.js +0 -131
  136. package/query/insert-query.d.ts +0 -23
  137. package/query/query.d.ts +0 -25
  138. package/query/returning-query.d.ts +0 -14
  139. package/query/update-query.d.ts +0 -29
  140. package/sql-objects/base-field.d.ts +0 -7
  141. package/sql-objects/base-field.js +0 -7
  142. package/sql-objects/coalesce-statement.d.ts +0 -22
  143. package/sql-objects/count-statement.d.ts +0 -20
  144. package/sql-objects/expression.d.ts +0 -7
  145. package/sql-objects/expression.js +0 -6
  146. package/sql-objects/field-expression.d.ts +0 -14
  147. package/sql-objects/field-expression.js +0 -50
  148. package/sql-objects/group-column.d.ts +0 -8
  149. package/sql-objects/join-statement.d.ts +0 -17
  150. package/sql-objects/max-statement.d.ts +0 -22
  151. package/sql-objects/operator.d.ts +0 -5
  152. package/sql-objects/operator.js +0 -3
  153. package/sql-objects/operators/comp-operator.d.ts +0 -16
  154. package/sql-objects/operators/logical-operator.d.ts +0 -16
  155. package/sql-objects/operators/logical-operator.js +0 -81
  156. package/sql-objects/operators/op-and.d.ts +0 -5
  157. package/sql-objects/operators/op-and.js +0 -5
  158. package/sql-objects/operators/op-between.d.ts +0 -11
  159. package/sql-objects/operators/op-eq.d.ts +0 -8
  160. package/sql-objects/operators/op-eq.js +0 -9
  161. package/sql-objects/operators/op-exists.d.ts +0 -11
  162. package/sql-objects/operators/op-exists.js +0 -27
  163. package/sql-objects/operators/op-gt.d.ts +0 -8
  164. package/sql-objects/operators/op-gt.js +0 -9
  165. package/sql-objects/operators/op-gte.d.ts +0 -8
  166. package/sql-objects/operators/op-gte.js +0 -9
  167. package/sql-objects/operators/op-ilike.d.ts +0 -6
  168. package/sql-objects/operators/op-ilike.js +0 -6
  169. package/sql-objects/operators/op-in.d.ts +0 -9
  170. package/sql-objects/operators/op-in.js +0 -15
  171. package/sql-objects/operators/op-is-not.d.ts +0 -8
  172. package/sql-objects/operators/op-is-not.js +0 -9
  173. package/sql-objects/operators/op-is.d.ts +0 -8
  174. package/sql-objects/operators/op-is.js +0 -9
  175. package/sql-objects/operators/op-like.d.ts +0 -10
  176. package/sql-objects/operators/op-like.js +0 -16
  177. package/sql-objects/operators/op-lt.d.ts +0 -8
  178. package/sql-objects/operators/op-lt.js +0 -9
  179. package/sql-objects/operators/op-lte.d.ts +0 -8
  180. package/sql-objects/operators/op-lte.js +0 -9
  181. package/sql-objects/operators/op-ne.d.ts +0 -8
  182. package/sql-objects/operators/op-ne.js +0 -9
  183. package/sql-objects/operators/op-not-between.d.ts +0 -6
  184. package/sql-objects/operators/op-not-between.js +0 -6
  185. package/sql-objects/operators/op-not-exists.d.ts +0 -6
  186. package/sql-objects/operators/op-not-exists.js +0 -6
  187. package/sql-objects/operators/op-not-ilike.d.ts +0 -6
  188. package/sql-objects/operators/op-not-ilike.js +0 -6
  189. package/sql-objects/operators/op-not-in.d.ts +0 -6
  190. package/sql-objects/operators/op-not-in.js +0 -6
  191. package/sql-objects/operators/op-not-like.d.ts +0 -6
  192. package/sql-objects/operators/op-not-like.js +0 -6
  193. package/sql-objects/operators/op-not.d.ts +0 -11
  194. package/sql-objects/operators/op-not.js +0 -17
  195. package/sql-objects/operators/op-or.d.ts +0 -5
  196. package/sql-objects/operators/op-or.js +0 -5
  197. package/sql-objects/order-column.d.ts +0 -9
  198. package/sql-objects/order-column.js +0 -39
  199. package/sql-objects/param-expression.d.ts +0 -23
  200. package/sql-objects/raw-statement.d.ts +0 -9
  201. package/sql-objects/raw-statement.js +0 -15
  202. package/sql-objects/returning-column.d.ts +0 -9
  203. package/sql-objects/returning-column.js +0 -27
  204. package/sql-objects/sequence-getter-statement.d.ts +0 -24
  205. package/sql-objects/table-name.d.ts +0 -22
  206. package/sql-objects/table-name.js +0 -55
  207. package/sql-objects/upper-statement.d.ts +0 -22
  208. package/sqlobject.initializers.d.ts +0 -61
  209. package/sqlobject.initializers.js +0 -115
  210. package/typeguards.d.ts +0 -37
@@ -1,20 +1,7 @@
1
- import { SerializationType } from '../enums.js';
1
+ import { SerializationType } from '../../enums.js';
2
2
  import { BaseField } from './base-field.js';
3
3
  const GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/;
4
- export class GroupColumn extends BaseField {
5
- constructor(value) {
6
- super();
7
- const m = value.match(GROUP_COLUMN_PATTERN);
8
- if (!m)
9
- throw new TypeError(`"${value}" does not match group column format`);
10
- this._field = m[2];
11
- if (m[1]) {
12
- const a = m[1].split(/\./g);
13
- a.pop();
14
- this._table = a.pop();
15
- this._schema = a.pop();
16
- }
17
- }
4
+ class GroupColumnClass extends BaseField {
18
5
  get _type() {
19
6
  return SerializationType.GROUP_COLUMN;
20
7
  }
@@ -30,3 +17,20 @@ export class GroupColumn extends BaseField {
30
17
  (o.isReservedWord ? '"' + this._field + '"' : this._field));
31
18
  }
32
19
  }
20
+ export const GroupColumn = function (value) {
21
+ if (!(this instanceof GroupColumn))
22
+ return new GroupColumn(value);
23
+ BaseField.call(this);
24
+ const m = value.match(GROUP_COLUMN_PATTERN);
25
+ if (!m)
26
+ throw new TypeError(`"${value}" does not match group column format`);
27
+ this._field = m[2];
28
+ if (m[1]) {
29
+ const a = m[1].split(/\./g);
30
+ a.pop();
31
+ this._table = a.pop();
32
+ this._schema = a.pop();
33
+ }
34
+ };
35
+ GroupColumn.prototype = GroupColumnClass.prototype;
36
+ GroupColumn.prototype.constructor = GroupColumn;
@@ -0,0 +1,26 @@
1
+ export * from './base-field.js';
2
+ export * from './case.js';
3
+ export * from './coalesce.js';
4
+ export * from './count.js';
5
+ export * from './field.js';
6
+ export * from './group-column.js';
7
+ export * from './join.js';
8
+ export * from './join-cross.js';
9
+ export * from './join-full-outer.js';
10
+ export * from './join-inner.js';
11
+ export * from './join-left.js';
12
+ export * from './join-left-outer.js';
13
+ export * from './join-outer.js';
14
+ export * from './join-right.js';
15
+ export * from './join-right-outer.js';
16
+ export * from './lower.js';
17
+ export * from './max.js';
18
+ export * from './min.js';
19
+ export * from './order-column.js';
20
+ export * from './param.js';
21
+ export * from './raw.js';
22
+ export * from './returning-column.js';
23
+ export * from './sequence.js';
24
+ export * from './string-agg.js';
25
+ export * from './table-name.js';
26
+ export * from './upper.js';
@@ -0,0 +1,26 @@
1
+ export * from './base-field.js';
2
+ export * from './case.js';
3
+ export * from './coalesce.js';
4
+ export * from './count.js';
5
+ export * from './field.js';
6
+ export * from './group-column.js';
7
+ export * from './join.js';
8
+ export * from './join-cross.js';
9
+ export * from './join-full-outer.js';
10
+ export * from './join-inner.js';
11
+ export * from './join-left.js';
12
+ export * from './join-left-outer.js';
13
+ export * from './join-outer.js';
14
+ export * from './join-right.js';
15
+ export * from './join-right-outer.js';
16
+ export * from './lower.js';
17
+ export * from './max.js';
18
+ export * from './min.js';
19
+ export * from './order-column.js';
20
+ export * from './param.js';
21
+ export * from './raw.js';
22
+ export * from './returning-column.js';
23
+ export * from './sequence.js';
24
+ export * from './string-agg.js';
25
+ export * from './table-name.js';
26
+ export * from './upper.js';
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class CrossJoinClass extends Join {
6
+ }
7
+ interface CrossJoinCtor {
8
+ new (table: string | TableName | Select | Raw): CrossJoin;
9
+ (table: string | TableName | Select | Raw): CrossJoin;
10
+ prototype: CrossJoin;
11
+ }
12
+ export declare const CrossJoin: CrossJoinCtor;
13
+ export interface CrossJoin extends CrossJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class CrossJoinClass extends Join {
4
+ }
5
+ export const CrossJoin = function (table) {
6
+ if (!(this instanceof CrossJoin))
7
+ return new CrossJoin(table);
8
+ Join.call(this, JoinType.CROSS, table);
9
+ };
10
+ CrossJoin.prototype = CrossJoinClass.prototype;
11
+ CrossJoin.prototype.constructor = CrossJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class FullOuterJoinClass extends Join {
6
+ }
7
+ interface FullOuterJoinCtor {
8
+ new (table: string | TableName | Select | Raw): FullOuterJoin;
9
+ (table: string | TableName | Select | Raw): FullOuterJoin;
10
+ prototype: FullOuterJoin;
11
+ }
12
+ export declare const FullOuterJoin: FullOuterJoinCtor;
13
+ export interface FullOuterJoin extends FullOuterJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class FullOuterJoinClass extends Join {
4
+ }
5
+ export const FullOuterJoin = function (table) {
6
+ if (!(this instanceof FullOuterJoin))
7
+ return new FullOuterJoin(table);
8
+ Join.call(this, JoinType.FULL_OUTER, table);
9
+ };
10
+ FullOuterJoin.prototype = FullOuterJoinClass.prototype;
11
+ FullOuterJoin.prototype.constructor = FullOuterJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class InnerJoinClass extends Join {
6
+ }
7
+ interface InnerJoinCtor {
8
+ new (table: string | TableName | Select | Raw): InnerJoin;
9
+ (table: string | TableName | Select | Raw): InnerJoin;
10
+ prototype: InnerJoin;
11
+ }
12
+ export declare const InnerJoin: InnerJoinCtor;
13
+ export interface InnerJoin extends InnerJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class InnerJoinClass extends Join {
4
+ }
5
+ export const InnerJoin = function (table) {
6
+ if (!(this instanceof InnerJoin))
7
+ return new InnerJoin(table);
8
+ Join.call(this, JoinType.INNER, table);
9
+ };
10
+ InnerJoin.prototype = InnerJoinClass.prototype;
11
+ InnerJoin.prototype.constructor = InnerJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class LeftOuterJoinClass extends Join {
6
+ }
7
+ interface LeftOuterJoinCtor {
8
+ new (table: string | TableName | Select | Raw): LeftOuterJoin;
9
+ (table: string | TableName | Select | Raw): LeftOuterJoin;
10
+ prototype: LeftOuterJoin;
11
+ }
12
+ export declare const LeftOuterJoin: LeftOuterJoinCtor;
13
+ export interface LeftOuterJoin extends LeftOuterJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class LeftOuterJoinClass extends Join {
4
+ }
5
+ export const LeftOuterJoin = function (table) {
6
+ if (!(this instanceof LeftOuterJoin))
7
+ return new LeftOuterJoin(table);
8
+ Join.call(this, JoinType.LEFT_OUTER, table);
9
+ };
10
+ LeftOuterJoin.prototype = LeftOuterJoinClass.prototype;
11
+ LeftOuterJoin.prototype.constructor = LeftOuterJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class LeftJoinClass extends Join {
6
+ }
7
+ interface LeftJoinCtor {
8
+ new (table: string | TableName | Select | Raw): LeftJoin;
9
+ (table: string | TableName | Select | Raw): LeftJoin;
10
+ prototype: LeftJoin;
11
+ }
12
+ export declare const LeftJoin: LeftJoinCtor;
13
+ export interface LeftJoin extends LeftJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class LeftJoinClass extends Join {
4
+ }
5
+ export const LeftJoin = function (table) {
6
+ if (!(this instanceof LeftJoin))
7
+ return new LeftJoin(table);
8
+ Join.call(this, JoinType.LEFT, table);
9
+ };
10
+ LeftJoin.prototype = LeftJoinClass.prototype;
11
+ LeftJoin.prototype.constructor = LeftJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class OuterJoinClass extends Join {
6
+ }
7
+ interface OuterJoinCtor {
8
+ new (table: string | TableName | Select | Raw): OuterJoin;
9
+ (table: string | TableName | Select | Raw): OuterJoin;
10
+ prototype: OuterJoin;
11
+ }
12
+ export declare const OuterJoin: OuterJoinCtor;
13
+ export interface OuterJoin extends OuterJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class OuterJoinClass extends Join {
4
+ }
5
+ export const OuterJoin = function (table) {
6
+ if (!(this instanceof OuterJoin))
7
+ return new OuterJoin(table);
8
+ Join.call(this, JoinType.OUTER, table);
9
+ };
10
+ OuterJoin.prototype = OuterJoinClass.prototype;
11
+ OuterJoin.prototype.constructor = OuterJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class RightOuterJoinClass extends Join {
6
+ }
7
+ interface RightOuterJoinCtor {
8
+ new (table: string | TableName | Select | Raw): RightOuterJoin;
9
+ (table: string | TableName | Select | Raw): RightOuterJoin;
10
+ prototype: RightOuterJoin;
11
+ }
12
+ export declare const RightOuterJoin: RightOuterJoinCtor;
13
+ export interface RightOuterJoin extends RightOuterJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class RightOuterJoinClass extends Join {
4
+ }
5
+ export const RightOuterJoin = function (table) {
6
+ if (!(this instanceof RightOuterJoin))
7
+ return new RightOuterJoin(table);
8
+ Join.call(this, JoinType.RIGHT_OUTER, table);
9
+ };
10
+ RightOuterJoin.prototype = RightOuterJoinClass.prototype;
11
+ RightOuterJoin.prototype.constructor = RightOuterJoin;
@@ -0,0 +1,15 @@
1
+ import type { Select } from '../select.js';
2
+ import { Join } from './join.js';
3
+ import type { Raw } from './raw.js';
4
+ import { TableName } from './table-name.js';
5
+ declare class RightJoinClass extends Join {
6
+ }
7
+ interface RightJoinCtor {
8
+ new (table: string | TableName | Select | Raw): RightJoin;
9
+ (table: string | TableName | Select | Raw): RightJoin;
10
+ prototype: RightJoin;
11
+ }
12
+ export declare const RightJoin: RightJoinCtor;
13
+ export interface RightJoin extends RightJoinClass {
14
+ }
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { JoinType } from '../../enums.js';
2
+ import { Join } from './join.js';
3
+ class RightJoinClass extends Join {
4
+ }
5
+ export const RightJoin = function (table) {
6
+ if (!(this instanceof RightJoin))
7
+ return new RightJoin(table);
8
+ Join.call(this, JoinType.RIGHT, table);
9
+ };
10
+ RightJoin.prototype = RightJoinClass.prototype;
11
+ RightJoin.prototype.constructor = RightJoin;
@@ -0,0 +1,25 @@
1
+ import { JoinType, SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import type { SerializeContext } from '../../serialize-context.js';
4
+ import type { LogicalOperator } from '../operators/logical-operator.js';
5
+ import type { Select } from '../select.js';
6
+ import type { Raw } from './raw.js';
7
+ import { TableName } from './table-name.js';
8
+ declare class JoinClass extends Serializable {
9
+ _joinType: JoinType;
10
+ _table: TableName | Select | Raw;
11
+ _conditions: LogicalOperator;
12
+ get _type(): SerializationType;
13
+ on(...conditions: Serializable[]): this;
14
+ _serialize(ctx: SerializeContext): string;
15
+ protected __serializeConditions(ctx: any, join: JoinClass): any;
16
+ }
17
+ interface JoinCtor {
18
+ new (joinType: JoinType, table: string | TableName | Select | Raw): Join;
19
+ (joinType: JoinType, table: string | TableName | Select | Raw): Join;
20
+ prototype: Join;
21
+ }
22
+ export declare const Join: JoinCtor;
23
+ export interface Join extends JoinClass {
24
+ }
25
+ export {};
@@ -1,24 +1,12 @@
1
- import { JoinType, SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- import { isRawStatement, isSelectQuery, isTableName } from '../typeguards.js';
4
- import { OpAnd } from './operators/op-and.js';
1
+ import { JoinType, SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { isRaw, isSelect, isTableName } from '../../type-guards.js';
4
+ import { And } from '../operators/and.js';
5
5
  import { TableName } from './table-name.js';
6
- export class JoinStatement extends Serializable {
6
+ class JoinClass extends Serializable {
7
7
  _joinType;
8
8
  _table;
9
- _conditions = new OpAnd();
10
- constructor(joinType, table) {
11
- super();
12
- // noinspection SuspiciousTypeOfGuard
13
- if (!(isSelectQuery(table) ||
14
- isRawStatement(table) ||
15
- isTableName(table) ||
16
- typeof table === 'string')) {
17
- throw new TypeError('Table name, select query or raw object required for Join');
18
- }
19
- this._joinType = joinType;
20
- this._table = typeof table === 'string' ? new TableName(table) : table;
21
- }
9
+ _conditions = new And();
22
10
  get _type() {
23
11
  return SerializationType.JOIN;
24
12
  }
@@ -61,7 +49,7 @@ export class JoinStatement extends Serializable {
61
49
  break;
62
50
  }
63
51
  const lf = o.table.length > 40;
64
- if (isSelectQuery(this._table)) {
52
+ if (isSelect(this._table)) {
65
53
  const alias = this._table._alias;
66
54
  if (!alias)
67
55
  throw new Error('Alias required for sub-select in Join');
@@ -88,3 +76,20 @@ export class JoinStatement extends Serializable {
88
76
  return '';
89
77
  }
90
78
  }
79
+ export const Join = function (joinType, table) {
80
+ if (!(this instanceof Join))
81
+ return new Join(joinType, table);
82
+ Serializable.call(this);
83
+ // noinspection SuspiciousTypeOfGuard
84
+ if (!(isSelect(table) ||
85
+ isRaw(table) ||
86
+ isTableName(table) ||
87
+ typeof table === 'string')) {
88
+ throw new TypeError('Table name, select query or raw object required for Join');
89
+ }
90
+ this._joinType = joinType;
91
+ this._table = typeof table === 'string' ? TableName(table) : table;
92
+ this._conditions = new And();
93
+ };
94
+ Join.prototype = JoinClass.prototype;
95
+ Join.prototype.constructor = Join;
@@ -0,0 +1,30 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ declare class LowerClass extends Serializable {
5
+ _expression: any;
6
+ _alias?: string;
7
+ get _type(): SerializationType;
8
+ /**
9
+ * Sets alias to case expression.
10
+ */
11
+ as(alias: string): this;
12
+ /**
13
+ * Performs serialization
14
+ *
15
+ * @param {Object} ctx
16
+ * @return {string}
17
+ * @override
18
+ */
19
+ _serialize(ctx: SerializeContext): string;
20
+ protected __defaultSerialize(ctx: SerializeContext, o: any): string;
21
+ }
22
+ interface LowerCtor {
23
+ new (expression: any): Lower;
24
+ (expression: any): Lower;
25
+ prototype: Lower;
26
+ }
27
+ export declare const Lower: LowerCtor;
28
+ export interface Lower extends LowerClass {
29
+ }
30
+ export {};
@@ -1,12 +1,8 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- export class LowerStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ class LowerClass extends Serializable {
4
4
  _expression;
5
5
  _alias;
6
- constructor(expression) {
7
- super();
8
- this._expression = expression;
9
- }
10
6
  get _type() {
11
7
  return SerializationType.LOWER_STATEMENT;
12
8
  }
@@ -34,3 +30,11 @@ export class LowerStatement extends Serializable {
34
30
  return 'lower(' + o + ')' + (this._alias ? ' ' + this._alias : '');
35
31
  }
36
32
  }
33
+ export const Lower = function (expression) {
34
+ if (!(this instanceof Lower))
35
+ return new Lower(expression);
36
+ Serializable.call(this);
37
+ this._expression = expression;
38
+ };
39
+ Lower.prototype = LowerClass.prototype;
40
+ Lower.prototype.constructor = Lower;
@@ -1,10 +1,9 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- import { SerializeContext } from '../serialize-context.js';
4
- export declare class MinStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ declare class MaxClass extends Serializable {
5
5
  _expression: any;
6
6
  _alias?: string;
7
- constructor(expression: any);
8
7
  get _type(): SerializationType;
9
8
  /**
10
9
  * Sets alias to case expression.
@@ -20,3 +19,12 @@ export declare class MinStatement extends Serializable {
20
19
  _serialize(ctx: SerializeContext): string;
21
20
  protected __defaultSerialize(ctx: SerializeContext, o: any): string;
22
21
  }
22
+ interface MaxCtor {
23
+ new (expression: any): Max;
24
+ (expression: any): Max;
25
+ prototype: Max;
26
+ }
27
+ export declare const Max: MaxCtor;
28
+ export interface Max extends MaxClass {
29
+ }
30
+ export {};
@@ -1,12 +1,8 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- export class MaxStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ class MaxClass extends Serializable {
4
4
  _expression;
5
5
  _alias;
6
- constructor(expression) {
7
- super();
8
- this._expression = expression;
9
- }
10
6
  get _type() {
11
7
  return SerializationType.MAX_STATEMENT;
12
8
  }
@@ -34,3 +30,11 @@ export class MaxStatement extends Serializable {
34
30
  return 'max(' + o + ')' + (this._alias ? ' ' + this._alias : '');
35
31
  }
36
32
  }
33
+ export const Max = function (expression) {
34
+ if (!(this instanceof Max))
35
+ return new Max(expression);
36
+ Serializable.call(this);
37
+ this._expression = expression;
38
+ };
39
+ Max.prototype = MaxClass.prototype;
40
+ Max.prototype.constructor = Max;
@@ -1,7 +1,7 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- import { SerializeContext } from '../serialize-context.js';
4
- export declare class LowerStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ declare class MinClass extends Serializable {
5
5
  _expression: any;
6
6
  _alias?: string;
7
7
  constructor(expression: any);
@@ -20,3 +20,12 @@ export declare class LowerStatement extends Serializable {
20
20
  _serialize(ctx: SerializeContext): string;
21
21
  protected __defaultSerialize(ctx: SerializeContext, o: any): string;
22
22
  }
23
+ interface MinCtor {
24
+ new (expression: any): Min;
25
+ (expression: any): Min;
26
+ prototype: Min;
27
+ }
28
+ export declare const Min: MinCtor;
29
+ export interface Min extends MinClass {
30
+ }
31
+ export {};
@@ -1,6 +1,6 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- export class MinStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ class MinClass extends Serializable {
4
4
  _expression;
5
5
  _alias;
6
6
  constructor(expression) {
@@ -34,3 +34,10 @@ export class MinStatement extends Serializable {
34
34
  return 'min(' + o + ')' + (this._alias ? ' ' + this._alias : '');
35
35
  }
36
36
  }
37
+ export const Min = function (expression) {
38
+ if (!(this instanceof Min))
39
+ return new Min(expression);
40
+ this._expression = expression;
41
+ };
42
+ Min.prototype = MinClass.prototype;
43
+ Min.prototype.constructor = Min;
@@ -0,0 +1,17 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { SerializeContext } from '../../serialize-context.js';
3
+ import { BaseField } from './base-field.js';
4
+ declare class OrderColumnClass extends BaseField {
5
+ _descending?: boolean;
6
+ get _type(): SerializationType;
7
+ _serialize(ctx: SerializeContext): string;
8
+ }
9
+ interface OrderColumnCtor {
10
+ new (value: string): OrderColumn;
11
+ (value: string): OrderColumn;
12
+ prototype: OrderColumn;
13
+ }
14
+ export declare const OrderColumn: OrderColumnCtor;
15
+ export interface OrderColumn extends OrderColumnClass {
16
+ }
17
+ export {};
@@ -0,0 +1,43 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { BaseField } from './base-field.js';
4
+ const ORDER_COLUMN_PATTERN = /^([-+])?((?:[a-zA-Z_][\w$]*\.){0,2})([a-zA-Z_][\w$]*|\*) *(asc|dsc|desc|ascending|descending)?$/i;
5
+ class OrderColumnClass extends BaseField {
6
+ get _type() {
7
+ return SerializationType.ORDER_COLUMN;
8
+ }
9
+ _serialize(ctx) {
10
+ const o = {
11
+ schema: this._schema,
12
+ table: this._table,
13
+ field: this._field,
14
+ descending: !!this._descending,
15
+ isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
16
+ };
17
+ return ctx.serialize(this._type, o, () => (o.schema ? o.schema + '.' : '') +
18
+ (o.table ? o.table + '.' : '') +
19
+ (o.isReservedWord ? '"' + o.field + '"' : o.field) +
20
+ (o.descending ? ' desc' : ''));
21
+ }
22
+ }
23
+ export const OrderColumn = function (value) {
24
+ if (!(this instanceof OrderColumn))
25
+ return new OrderColumn(value);
26
+ Serializable.call(this);
27
+ const m = value.match(ORDER_COLUMN_PATTERN);
28
+ if (!m)
29
+ throw new TypeError(`"${value}" does not match order column format`);
30
+ this._field = m[3];
31
+ if (m[2]) {
32
+ const a = m[2].split(/\./g);
33
+ a.pop();
34
+ this._table = a.pop();
35
+ this._schema = a.pop();
36
+ }
37
+ this._descending = !!(m[1] === '-' ||
38
+ (!m[1] &&
39
+ m[4] &&
40
+ ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
41
+ };
42
+ OrderColumn.prototype = OrderColumnClass.prototype;
43
+ OrderColumn.prototype.constructor = OrderColumn;