@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
@@ -0,0 +1,20 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { CompOperator } from './comp-operator.js';
3
+ class LtClass extends CompOperator {
4
+ }
5
+ export const Lt = function (left, right) {
6
+ if (!(this instanceof Lt))
7
+ return new Lt(left, right);
8
+ CompOperator.call(this, left, right);
9
+ this._operatorType = OperatorType.lt;
10
+ this._symbol = '<';
11
+ if (typeof left === 'string') {
12
+ const m = left.match(/^([\w\\.$]+)(\[])?/);
13
+ if (!m)
14
+ throw new TypeError(`"${left}" is not a valid expression definition`);
15
+ this._left = m[1];
16
+ this._isArray = !!m[2];
17
+ }
18
+ };
19
+ Lt.prototype = LtClass.prototype;
20
+ Lt.prototype.constructor = Lt;
@@ -0,0 +1,13 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { CompOperator } from './comp-operator.js';
3
+ declare class LteClass extends CompOperator {
4
+ }
5
+ interface LteCtor {
6
+ new (left: string | Serializable, right?: any): Lte;
7
+ (left: string | Serializable, right?: any): Lte;
8
+ prototype: Lte;
9
+ }
10
+ export declare const Lte: LteCtor;
11
+ export interface Lte extends LteClass {
12
+ }
13
+ export {};
@@ -0,0 +1,20 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { CompOperator } from './comp-operator.js';
3
+ class LteClass extends CompOperator {
4
+ }
5
+ export const Lte = function (left, right) {
6
+ if (!(this instanceof Lte))
7
+ return new Lte(left, right);
8
+ CompOperator.call(this, left, right);
9
+ this._operatorType = OperatorType.lte;
10
+ this._symbol = '<=';
11
+ if (typeof left === 'string') {
12
+ const m = left.match(/^([\w\\.$]+)(\[])?/);
13
+ if (!m)
14
+ throw new TypeError(`"${left}" is not a valid expression definition`);
15
+ this._left = m[1];
16
+ this._isArray = !!m[2];
17
+ }
18
+ };
19
+ Lte.prototype = LteClass.prototype;
20
+ Lte.prototype.constructor = Lte;
@@ -0,0 +1,13 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { CompOperator } from './comp-operator.js';
3
+ declare class NeClass extends CompOperator {
4
+ }
5
+ interface NeCtor {
6
+ new (left: string | Serializable, right?: any): Ne;
7
+ (left: string | Serializable, right?: any): Ne;
8
+ prototype: Ne;
9
+ }
10
+ export declare const Ne: NeCtor;
11
+ export interface Ne extends NeClass {
12
+ }
13
+ export {};
@@ -0,0 +1,20 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { CompOperator } from './comp-operator.js';
3
+ class NeClass extends CompOperator {
4
+ }
5
+ export const Ne = function (left, right) {
6
+ if (!(this instanceof Ne))
7
+ return new Ne(left, right);
8
+ CompOperator.call(this, left, right);
9
+ this._operatorType = OperatorType.ne;
10
+ this._symbol = '!=';
11
+ if (typeof left === 'string') {
12
+ const m = left.match(/^([\w\\.$]+)(\[])?/);
13
+ if (!m)
14
+ throw new TypeError(`"${left}" is not a valid expression definition`);
15
+ this._left = m[1];
16
+ this._isArray = !!m[2];
17
+ }
18
+ };
19
+ Ne.prototype = NeClass.prototype;
20
+ Ne.prototype.constructor = Ne;
@@ -0,0 +1,15 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { Between } from './between.js';
3
+ declare class NotBetweenClass extends Between {
4
+ }
5
+ interface NotBetweenCtor {
6
+ new (left: string | Serializable, right: any[] | Serializable): NotBetween;
7
+ new (left: string | Serializable, right1: any, right2: any): NotBetween;
8
+ (left: string | Serializable, right: any[] | Serializable): NotBetween;
9
+ (left: string | Serializable, right1: any, right2: any): NotBetween;
10
+ prototype: NotBetween;
11
+ }
12
+ export declare const NotBetween: NotBetweenCtor;
13
+ export interface NotBetween extends NotBetweenClass {
14
+ }
15
+ export {};
@@ -0,0 +1,13 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { Between } from './between.js';
3
+ class NotBetweenClass extends Between {
4
+ }
5
+ export const NotBetween = function (left, right1, right2) {
6
+ if (!(this instanceof NotBetween))
7
+ return new NotBetween(left, right1, right2);
8
+ Between.call(this, left, right1, right2);
9
+ this._operatorType = OperatorType.notBetween;
10
+ this._symbol = 'not between';
11
+ };
12
+ NotBetween.prototype = NotBetweenClass.prototype;
13
+ NotBetween.prototype.constructor = NotBetween;
@@ -0,0 +1,14 @@
1
+ import type { Raw } from '../elements/index.js';
2
+ import type { Select } from '../select.js';
3
+ import { Exists } from './exists.js';
4
+ declare class NotExistsClass extends Exists {
5
+ }
6
+ interface NotExistsCtor {
7
+ new (query: Select | Raw): NotExists;
8
+ (query: Select | Raw): NotExists;
9
+ prototype: NotExists;
10
+ }
11
+ export declare const NotExists: NotExistsCtor;
12
+ export interface NotExists extends NotExistsClass {
13
+ }
14
+ export {};
@@ -0,0 +1,13 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { Exists } from './exists.js';
3
+ class NotExistsClass extends Exists {
4
+ }
5
+ export const NotExists = function (query) {
6
+ if (!(this instanceof NotExists))
7
+ return new NotExists(query);
8
+ Exists.call(this, query);
9
+ this._operatorType = OperatorType.notExists;
10
+ this._symbol = 'not exists';
11
+ };
12
+ NotExists.prototype = NotExistsClass.prototype;
13
+ NotExists.prototype.constructor = NotExists;
@@ -0,0 +1,13 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { ILike } from './i-like.js';
3
+ declare class NotILikeClass extends ILike {
4
+ }
5
+ interface NotILikeCtor {
6
+ new (left: string | Serializable, right?: string | Serializable): NotILike;
7
+ (left: string | Serializable, right?: string | Serializable): NotILike;
8
+ prototype: NotILike;
9
+ }
10
+ export declare const NotILike: NotILikeCtor;
11
+ export interface NotILike extends NotILikeClass {
12
+ }
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { ILike } from './i-like.js';
3
+ class NotILikeClass extends ILike {
4
+ }
5
+ export const NotILike = function (left, right) {
6
+ if (!(this instanceof NotILike))
7
+ return new NotILike(left, right);
8
+ ILike.call(this, left, right);
9
+ this._operatorType = OperatorType.notILike;
10
+ this._symbol = 'not ilike';
11
+ };
12
+ NotILike.prototype = NotILikeClass.prototype;
13
+ NotILike.prototype.constructor = NotILike;
@@ -0,0 +1,13 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { In } from './in.js';
3
+ declare class NotInClass extends In {
4
+ }
5
+ interface NotInCtor {
6
+ new (left: string | Serializable, right: any[] | Serializable): NotIn;
7
+ (left: string | Serializable, right: any[] | Serializable): NotIn;
8
+ prototype: NotIn;
9
+ }
10
+ export declare const NotIn: NotInCtor;
11
+ export interface NotIn extends NotInClass {
12
+ }
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { In } from './in.js';
3
+ class NotInClass extends In {
4
+ }
5
+ export const NotIn = function (left, right) {
6
+ if (!(this instanceof NotIn))
7
+ return new NotIn(left, right);
8
+ In.call(this, left, right);
9
+ this._operatorType = OperatorType.notIn;
10
+ this._symbol = 'not in';
11
+ };
12
+ NotIn.prototype = NotInClass.prototype;
13
+ NotIn.prototype.constructor = NotIn;
@@ -0,0 +1,13 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ import { Like } from './like.js';
3
+ declare class NotLikeClass extends Like {
4
+ }
5
+ interface NotLikeCtor {
6
+ new (left: string | Serializable, right?: string | Serializable): NotLike;
7
+ (left: string | Serializable, right?: string | Serializable): NotLike;
8
+ prototype: NotLike;
9
+ }
10
+ export declare const NotLike: NotLikeCtor;
11
+ export interface NotLike extends NotLikeClass {
12
+ }
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { Like } from './like.js';
3
+ class NotLikeClass extends Like {
4
+ }
5
+ export const NotLike = function (left, right) {
6
+ if (!(this instanceof NotLike))
7
+ return new NotLike(left, right);
8
+ Like.call(this, left, right);
9
+ this._operatorType = OperatorType.notLike;
10
+ this._symbol = 'not like';
11
+ };
12
+ NotLike.prototype = NotLikeClass.prototype;
13
+ NotLike.prototype.constructor = NotLike;
@@ -0,0 +1,18 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ import { Operator } from '../operators/operator.js';
5
+ declare class NotClass extends Operator {
6
+ _expression: Serializable;
7
+ get _type(): SerializationType;
8
+ _serialize(ctx: SerializeContext): string;
9
+ }
10
+ interface NotCtor {
11
+ new (expression: Serializable): Not;
12
+ (expression: Serializable): Not;
13
+ prototype: Not;
14
+ }
15
+ export declare const Not: NotCtor;
16
+ export interface Not extends NotClass {
17
+ }
18
+ export {};
@@ -0,0 +1,20 @@
1
+ import { OperatorType, SerializationType } from '../../enums.js';
2
+ import { Operator } from '../operators/operator.js';
3
+ class NotClass extends Operator {
4
+ get _type() {
5
+ return SerializationType.NEGATIVE_EXPRESSION;
6
+ }
7
+ _serialize(ctx) {
8
+ const expression = ctx.anyToSQL(this._expression);
9
+ return ctx.serialize(this._type, expression, () => expression ? 'not ' + expression : '');
10
+ }
11
+ }
12
+ export const Not = function (expression) {
13
+ if (!(this instanceof Not))
14
+ return new Not(expression);
15
+ Operator.call(this);
16
+ this._operatorType = OperatorType.not;
17
+ this._expression = expression;
18
+ };
19
+ Not.prototype = NotClass.prototype;
20
+ Not.prototype.constructor = Not;
@@ -0,0 +1,12 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ export interface Operator extends Serializable {
4
+ _operatorType: OperatorType;
5
+ }
6
+ interface OperatorCtor {
7
+ new (): Operator;
8
+ (): Operator;
9
+ prototype: Operator;
10
+ }
11
+ export declare const Operator: OperatorCtor;
12
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ export const Operator = function () {
3
+ if (!(this instanceof Operator))
4
+ return new Operator();
5
+ if (this.constructor === Operator) {
6
+ throw new TypeError('Operator is abstract and cannot be instantiated');
7
+ }
8
+ Serializable.call(this);
9
+ };
10
+ Operator.prototype = Object.create(Serializable.prototype);
11
+ Operator.prototype.constructor = Operator;
@@ -0,0 +1,12 @@
1
+ import { LogicalOperator } from './logical-operator.js';
2
+ declare class OrClass extends LogicalOperator {
3
+ }
4
+ interface OrCtor {
5
+ new (...items: any[]): Or;
6
+ (...items: any[]): Or;
7
+ prototype: Or;
8
+ }
9
+ export declare const Or: OrCtor;
10
+ export interface Or extends OrClass {
11
+ }
12
+ export {};
@@ -0,0 +1,12 @@
1
+ import { OperatorType } from '../../enums.js';
2
+ import { LogicalOperator } from './logical-operator.js';
3
+ class OrClass extends LogicalOperator {
4
+ }
5
+ export const Or = function (...items) {
6
+ if (!(this instanceof Or))
7
+ return new Or(...items);
8
+ LogicalOperator.call(this, ...items);
9
+ this._operatorType = OperatorType.or;
10
+ };
11
+ Or.prototype = OrClass.prototype;
12
+ Or.prototype.constructor = Or;
package/sql/query.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { EventEmitter } from 'events';
2
+ import { Serializable } from '../serializable.js';
3
+ import type { GenerateOptions, GenerateResult } from '../types.js';
4
+ declare interface QueryClass extends EventEmitter {
5
+ }
6
+ declare class QueryClass extends Serializable {
7
+ protected _comment: Query.Comment[];
8
+ protected _params?: Record<string, any>;
9
+ /**
10
+ * Generates Sql script
11
+ */
12
+ generate(options?: GenerateOptions): GenerateResult;
13
+ values(obj: any): this;
14
+ comment(args: Query.Comment): this;
15
+ comment(text: string, dialect?: string[]): this;
16
+ }
17
+ interface QueryCtor {
18
+ new (): Query;
19
+ (): Query;
20
+ prototype: Query;
21
+ }
22
+ export declare const Query: QueryCtor;
23
+ export interface Query extends QueryClass, EventEmitter {
24
+ }
25
+ export declare namespace Query {
26
+ interface Comment {
27
+ comment: string;
28
+ dialect?: string[];
29
+ }
30
+ }
31
+ export {};
@@ -3,13 +3,7 @@ import flattenText from 'putil-flattentext';
3
3
  import merge from 'putil-merge';
4
4
  import { Serializable } from '../serializable.js';
5
5
  import { SerializeContext } from '../serialize-context.js';
6
- export class Query extends Serializable {
7
- _comment = [];
8
- _params;
9
- constructor() {
10
- super();
11
- EventEmitter.call(this);
12
- }
6
+ class QueryClass extends Serializable {
13
7
  /**
14
8
  * Generates Sql script
15
9
  */
@@ -59,4 +53,16 @@ export class Query extends Serializable {
59
53
  return this;
60
54
  }
61
55
  }
56
+ export const Query = function () {
57
+ if (!(this instanceof Query))
58
+ return new Query();
59
+ if (this.constructor === Query) {
60
+ throw new TypeError('Query is abstract and cannot be instantiated');
61
+ }
62
+ Serializable.call(this);
63
+ EventEmitter.call(this);
64
+ this._comment = [];
65
+ };
66
+ Query.prototype = QueryClass.prototype;
62
67
  merge(Query.prototype, EventEmitter.prototype, { descriptor: true });
68
+ Query.prototype.constructor = Query;
@@ -0,0 +1,23 @@
1
+ import { SerializeContext } from '../serialize-context.js';
2
+ import { ReturningColumn } from './elements/returning-column.js';
3
+ import { Query } from './query.js';
4
+ declare class ReturningQueryClass extends Query {
5
+ _returningColumns?: ReturningColumn[];
6
+ /**
7
+ *
8
+ */
9
+ returning(...columns: string[]): this;
10
+ /**
11
+ *
12
+ */
13
+ protected __serializeReturning(ctx: SerializeContext): string;
14
+ }
15
+ interface ReturningQueryCtor {
16
+ new (): ReturningQuery;
17
+ (): ReturningQuery;
18
+ prototype: ReturningQuery;
19
+ }
20
+ export declare const ReturningQuery: ReturningQueryCtor;
21
+ export interface ReturningQuery extends ReturningQueryClass {
22
+ }
23
+ export {};
@@ -1,8 +1,8 @@
1
1
  import { SerializationType } from '../enums.js';
2
2
  import { printArray } from '../helpers.js';
3
- import { ReturningColumn } from '../sql-objects/returning-column.js';
3
+ import { ReturningColumn } from './elements/returning-column.js';
4
4
  import { Query } from './query.js';
5
- export class ReturningQuery extends Query {
5
+ class ReturningQueryClass extends Query {
6
6
  _returningColumns;
7
7
  /**
8
8
  *
@@ -14,7 +14,7 @@ export class ReturningQuery extends Query {
14
14
  this._returningColumns = columns.length
15
15
  ? columns.reduce((a, v) => {
16
16
  if (v)
17
- a.push(new ReturningColumn(v));
17
+ a.push(ReturningColumn(v));
18
18
  return a;
19
19
  }, [])
20
20
  : undefined;
@@ -40,3 +40,13 @@ export class ReturningQuery extends Query {
40
40
  });
41
41
  }
42
42
  }
43
+ export const ReturningQuery = function () {
44
+ if (!(this instanceof ReturningQuery))
45
+ return new ReturningQuery();
46
+ if (this.constructor === ReturningQuery) {
47
+ throw new TypeError('ReturningQuery is abstract and cannot be instantiated');
48
+ }
49
+ Query.call(this);
50
+ };
51
+ ReturningQuery.prototype = ReturningQueryClass.prototype;
52
+ ReturningQuery.prototype.constructor = ReturningQuery;
@@ -1,18 +1,18 @@
1
1
  import { SerializationType } from '../enums.js';
2
2
  import { Serializable } from '../serializable.js';
3
3
  import { SerializeContext } from '../serialize-context.js';
4
- import { GroupColumn } from '../sql-objects/group-column.js';
5
- import { JoinStatement } from '../sql-objects/join-statement.js';
6
- import { LogicalOperator } from '../sql-objects/operators/logical-operator.js';
7
- import { OrderColumn } from '../sql-objects/order-column.js';
8
- import { RawStatement } from '../sql-objects/raw-statement.js';
9
- import { TableName } from '../sql-objects/table-name.js';
4
+ import { GroupColumn } from './elements/group-column.js';
5
+ import { Join } from './elements/join.js';
6
+ import { OrderColumn } from './elements/order-column.js';
7
+ import { Raw } from './elements/raw.js';
8
+ import { TableName } from './elements/table-name.js';
9
+ import { LogicalOperator } from './operators/logical-operator.js';
10
10
  import { Query } from './query.js';
11
- import type { UnionQuery } from './union-query.js';
12
- export declare class SelectQuery extends Query {
11
+ import type { Union } from './union.js';
12
+ declare class SelectClass extends Query {
13
13
  _tables?: Serializable[];
14
14
  _columns?: Serializable[];
15
- _joins?: JoinStatement[];
15
+ _joins?: Join[];
16
16
  _where?: LogicalOperator;
17
17
  _groupBy?: (GroupColumn | Serializable)[];
18
18
  _orderBy?: (OrderColumn | Serializable)[];
@@ -20,7 +20,6 @@ export declare class SelectQuery extends Query {
20
20
  _offset?: number;
21
21
  _alias?: string;
22
22
  _distinct?: boolean;
23
- constructor(...column: (string | string[] | Serializable)[]);
24
23
  get _type(): SerializationType;
25
24
  /**
26
25
  * Adds columns to query.
@@ -29,11 +28,11 @@ export declare class SelectQuery extends Query {
29
28
  /**
30
29
  * Defines "from" part of query.
31
30
  */
32
- from(...table: (string | TableName | RawStatement | SelectQuery | UnionQuery)[]): this;
31
+ from(...table: (string | TableName | Raw | SelectClass | Union)[]): this;
33
32
  /**
34
33
  * Adds "join" statements to query
35
34
  */
36
- join(...join: JoinStatement[]): this;
35
+ join(...join: Join[]): this;
37
36
  /**
38
37
  * Defines "where" part of query
39
38
  */
@@ -90,3 +89,12 @@ export declare class SelectQuery extends Query {
90
89
  protected __serializeGroupColumns(ctx: SerializeContext): string;
91
90
  protected __serializeOrderColumns(ctx: SerializeContext): string;
92
91
  }
92
+ interface SelectCtor {
93
+ new (...column: (string | string[] | Serializable)[]): Select;
94
+ (...column: (string | string[] | Serializable)[]): Select;
95
+ prototype: Select;
96
+ }
97
+ export declare const Select: SelectCtor;
98
+ export interface Select extends SelectClass {
99
+ }
100
+ export {};
@@ -2,14 +2,14 @@ import { splitString } from 'fast-tokenizer';
2
2
  import { coerceToInt } from 'putil-varhelpers';
3
3
  import { SerializationType } from '../enums.js';
4
4
  import { printArray } from '../helpers.js';
5
- import { FieldExpression } from '../sql-objects/field-expression.js';
6
- import { GroupColumn } from '../sql-objects/group-column.js';
7
- import { OpAnd } from '../sql-objects/operators/op-and.js';
8
- import { OrderColumn } from '../sql-objects/order-column.js';
9
- import { TableName } from '../sql-objects/table-name.js';
10
- import { isJoinStatement } from '../typeguards.js';
5
+ import { isJoin } from '../type-guards.js';
6
+ import { Field } from './elements/field.js';
7
+ import { GroupColumn } from './elements/group-column.js';
8
+ import { OrderColumn } from './elements/order-column.js';
9
+ import { TableName } from './elements/table-name.js';
10
+ import { And } from './operators/and.js';
11
11
  import { Query } from './query.js';
12
- export class SelectQuery extends Query {
12
+ class SelectClass extends Query {
13
13
  _tables;
14
14
  _columns;
15
15
  _joins;
@@ -20,11 +20,6 @@ export class SelectQuery extends Query {
20
20
  _offset;
21
21
  _alias;
22
22
  _distinct;
23
- constructor(...column) {
24
- super();
25
- if (column.length)
26
- this.addColumn(...column);
27
- }
28
23
  get _type() {
29
24
  return SerializationType.SELECT_QUERY;
30
25
  }
@@ -49,7 +44,7 @@ export class SelectQuery extends Query {
49
44
  keepBrackets: true,
50
45
  });
51
46
  items.forEach(item => {
52
- this._columns.push(new FieldExpression(item));
47
+ this._columns.push(Field(item));
53
48
  });
54
49
  }
55
50
  else
@@ -82,7 +77,7 @@ export class SelectQuery extends Query {
82
77
  for (const arg of join) {
83
78
  if (!arg)
84
79
  continue;
85
- if (!isJoinStatement(arg))
80
+ if (!isJoin(arg))
86
81
  throw new TypeError('Join statement required');
87
82
  this._joins.push(arg);
88
83
  }
@@ -92,7 +87,7 @@ export class SelectQuery extends Query {
92
87
  * Defines "where" part of query
93
88
  */
94
89
  where(...condition) {
95
- this._where = this._where || new OpAnd();
90
+ this._where = this._where || new And();
96
91
  this._where.add(...condition);
97
92
  return this;
98
93
  }
@@ -217,7 +212,7 @@ export class SelectQuery extends Query {
217
212
  const s = ctx.anyToSQL(t);
218
213
  // t._serialize(ctx);
219
214
  if (s) {
220
- if (t instanceof SelectQuery) {
215
+ if (t instanceof SelectClass) {
221
216
  if (!t._alias)
222
217
  throw new TypeError('Alias required for sub-select in columns');
223
218
  arr.push(s + ' ' + t._alias);
@@ -239,7 +234,7 @@ export class SelectQuery extends Query {
239
234
  const s = t._serialize(ctx);
240
235
  /* istanbul ignore else */
241
236
  if (s) {
242
- if (t instanceof SelectQuery) {
237
+ if (t instanceof SelectClass) {
243
238
  if (!t._alias)
244
239
  throw new TypeError('Alias required for sub-select in "from"');
245
240
  arr.push({
@@ -320,3 +315,12 @@ export class SelectQuery extends Query {
320
315
  });
321
316
  }
322
317
  }
318
+ export const Select = function (...column) {
319
+ if (!(this instanceof Select))
320
+ return new Select(...column);
321
+ Query.call(this);
322
+ if (column.length)
323
+ this.addColumn(...column);
324
+ };
325
+ Select.prototype = SelectClass.prototype;
326
+ Select.prototype.constructor = Select;
@@ -2,10 +2,9 @@ import { SerializationType } from '../enums.js';
2
2
  import { SerializeContext } from '../serialize-context.js';
3
3
  import { Query } from './query.js';
4
4
  export type UnionQueryType = 'all';
5
- export declare class UnionQuery extends Query {
5
+ declare class UnionClass extends Query {
6
6
  _queries: Query[];
7
7
  _unionType?: UnionQueryType;
8
- constructor(queries: Query[], unionType?: UnionQueryType);
9
8
  get _type(): SerializationType;
10
9
  /**
11
10
  * Performs serialization
@@ -13,3 +12,12 @@ export declare class UnionQuery extends Query {
13
12
  _serialize(ctx: SerializeContext): string;
14
13
  protected __defaultSerialize(ctx: SerializeContext, o: any): string;
15
14
  }
15
+ interface UnionCtor {
16
+ new (queries: Query[], unionType?: UnionQueryType): Union;
17
+ (queries: Query[], unionType?: UnionQueryType): Union;
18
+ prototype: Union;
19
+ }
20
+ export declare const Union: UnionCtor;
21
+ export interface Union extends UnionClass {
22
+ }
23
+ export {};
@@ -1,13 +1,8 @@
1
1
  import { SerializationType } from '../enums.js';
2
2
  import { Query } from './query.js';
3
- export class UnionQuery extends Query {
3
+ class UnionClass extends Query {
4
4
  _queries;
5
5
  _unionType;
6
- constructor(queries, unionType) {
7
- super();
8
- this._queries = queries;
9
- this._unionType = unionType;
10
- }
11
6
  get _type() {
12
7
  return SerializationType.UNION_QUERY;
13
8
  }
@@ -26,3 +21,12 @@ export class UnionQuery extends Query {
26
21
  return o.queries.join(o.unionType === 'all' ? '\nUNION ALL\n' : '\nUNION\n');
27
22
  }
28
23
  }
24
+ export const Union = function (queries, unionType) {
25
+ if (!(this instanceof Union))
26
+ return new Union(queries, unionType);
27
+ Query.call(this);
28
+ this._queries = queries;
29
+ this._unionType = unionType;
30
+ };
31
+ Union.prototype = UnionClass.prototype;
32
+ Union.prototype.constructor = Union;