@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
package/index.d.ts CHANGED
@@ -1,20 +1,10 @@
1
- export * as classes from './classes.ns.js';
2
1
  export * from './enums.js';
3
2
  export * from './extensions.js';
4
3
  export * from './helpers.js';
5
- export * from './op.initializers.js';
6
- export { op } from './op.initializers.js';
7
- export * from './query/delete-query.js';
8
- export * from './query/insert-query.js';
9
- export * from './query/query.js';
10
- export * from './query/select-query.js';
11
- export * from './query/update-query.js';
4
+ export * from './op.ns.js';
12
5
  export * from './serializable.js';
13
6
  export * from './serialize-context.js';
14
- export * from './sql-objects/join-statement.js';
15
- export * from './sql-objects/operator.js';
16
- export * from './sql-objects/operators/comp-operator.js';
17
- export * from './sql-objects/operators/logical-operator.js';
18
- export * from './sqlobject.initializers.js';
19
- export * from './typeguards.js';
7
+ export * as sql from './sql/index.js';
8
+ export * from './sql/index.js';
9
+ export * from './type-guards.js';
20
10
  export * from './types.js';
package/index.js CHANGED
@@ -1,20 +1,10 @@
1
- export * as classes from './classes.ns.js';
2
1
  export * from './enums.js';
3
2
  export * from './extensions.js';
4
3
  export * from './helpers.js';
5
- export * from './op.initializers.js';
6
- export { op } from './op.initializers.js';
7
- export * from './query/delete-query.js';
8
- export * from './query/insert-query.js';
9
- export * from './query/query.js';
10
- export * from './query/select-query.js';
11
- export * from './query/update-query.js';
4
+ export * from './op.ns.js';
12
5
  export * from './serializable.js';
13
6
  export * from './serialize-context.js';
14
- export * from './sql-objects/join-statement.js';
15
- export * from './sql-objects/operator.js';
16
- export * from './sql-objects/operators/comp-operator.js';
17
- export * from './sql-objects/operators/logical-operator.js';
18
- export * from './sqlobject.initializers.js';
19
- export * from './typeguards.js';
7
+ export * as sql from './sql/index.js';
8
+ export * from './sql/index.js';
9
+ export * from './type-guards.js';
20
10
  export * from './types.js';
package/op.ns.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { And } from './sql/operators/and.js';
2
+ import { Between } from './sql/operators/between.js';
3
+ import { Eq } from './sql/operators/eq.js';
4
+ import { Exists } from './sql/operators/exists.js';
5
+ import { Gt } from './sql/operators/gt.js';
6
+ import { Gte } from './sql/operators/gte.js';
7
+ import { ILike } from './sql/operators/i-like.js';
8
+ import { In } from './sql/operators/in.js';
9
+ import { Is } from './sql/operators/is.js';
10
+ import { IsNot } from './sql/operators/is-not.js';
11
+ import { Like } from './sql/operators/like.js';
12
+ import { Lt } from './sql/operators/lt.js';
13
+ import { Lte } from './sql/operators/lte.js';
14
+ import { Ne } from './sql/operators/ne.js';
15
+ import { Not } from './sql/operators/not.js';
16
+ import { NotBetween } from './sql/operators/not-between.js';
17
+ import { NotExists } from './sql/operators/not-exists.js';
18
+ import { NotILike } from './sql/operators/not-i-like.js';
19
+ import { NotIn } from './sql/operators/not-in.js';
20
+ import { NotLike } from './sql/operators/not-like.js';
21
+ import { Or } from './sql/operators/or.js';
22
+ export interface OperatorsMap {
23
+ and: typeof And;
24
+ or: typeof Or;
25
+ eq: typeof Eq;
26
+ '=': typeof Eq;
27
+ ne: typeof Ne;
28
+ '!=': typeof Ne;
29
+ gt: typeof Gt;
30
+ '>': typeof Gt;
31
+ gte: typeof Gte;
32
+ '>=': typeof Gte;
33
+ lt: typeof Lt;
34
+ '<': typeof Lt;
35
+ lte: typeof Lte;
36
+ '<=': typeof Lte;
37
+ between: typeof Between;
38
+ btw: typeof Between;
39
+ notBetween: typeof NotBetween;
40
+ nbtw: typeof NotBetween;
41
+ '!between': typeof NotBetween;
42
+ '!btw': typeof NotBetween;
43
+ in: typeof In;
44
+ notIn: typeof NotIn;
45
+ nin: typeof NotIn;
46
+ '!in': typeof NotIn;
47
+ like: typeof Like;
48
+ not: typeof Not;
49
+ notLike: typeof NotLike;
50
+ nlike: typeof NotLike;
51
+ '!like': typeof NotLike;
52
+ ilike: typeof ILike;
53
+ notILike: typeof NotILike;
54
+ nilike: typeof NotILike;
55
+ '!ilike': typeof NotILike;
56
+ is: typeof Is;
57
+ isNot: typeof IsNot;
58
+ '!is': typeof IsNot;
59
+ exists: typeof Exists;
60
+ notExists: typeof NotExists;
61
+ '!exists': typeof NotExists;
62
+ }
63
+ declare const Operators: OperatorsMap;
64
+ export { Operators };
package/op.ns.js ADDED
@@ -0,0 +1,65 @@
1
+ import { LogicalOperator } from './sql/index.js';
2
+ import { And } from './sql/operators/and.js';
3
+ import { Between } from './sql/operators/between.js';
4
+ import { Eq } from './sql/operators/eq.js';
5
+ import { Exists } from './sql/operators/exists.js';
6
+ import { Gt } from './sql/operators/gt.js';
7
+ import { Gte } from './sql/operators/gte.js';
8
+ import { ILike } from './sql/operators/i-like.js';
9
+ import { In } from './sql/operators/in.js';
10
+ import { Is } from './sql/operators/is.js';
11
+ import { IsNot } from './sql/operators/is-not.js';
12
+ import { Like } from './sql/operators/like.js';
13
+ import { Lt } from './sql/operators/lt.js';
14
+ import { Lte } from './sql/operators/lte.js';
15
+ import { Ne } from './sql/operators/ne.js';
16
+ import { Not } from './sql/operators/not.js';
17
+ import { NotBetween } from './sql/operators/not-between.js';
18
+ import { NotExists } from './sql/operators/not-exists.js';
19
+ import { NotILike } from './sql/operators/not-i-like.js';
20
+ import { NotIn } from './sql/operators/not-in.js';
21
+ import { NotLike } from './sql/operators/not-like.js';
22
+ import { Or } from './sql/operators/or.js';
23
+ const Operators = {
24
+ and: And,
25
+ or: Or,
26
+ eq: Eq,
27
+ '=': Eq,
28
+ ne: Ne,
29
+ '!=': Ne,
30
+ gt: Gt,
31
+ '>': Gt,
32
+ gte: Gte,
33
+ '>=': Gte,
34
+ lt: Lt,
35
+ '<': Lt,
36
+ lte: Lte,
37
+ '<=': Lte,
38
+ between: Between,
39
+ btw: Between,
40
+ notBetween: NotBetween,
41
+ nbtw: NotBetween,
42
+ '!between': NotBetween,
43
+ '!btw': NotBetween,
44
+ in: In,
45
+ notIn: NotIn,
46
+ nin: NotIn,
47
+ '!in': NotIn,
48
+ like: Like,
49
+ not: Not,
50
+ notLike: NotLike,
51
+ nlike: NotLike,
52
+ '!like': NotLike,
53
+ ilike: ILike,
54
+ notILike: NotILike,
55
+ nilike: NotILike,
56
+ '!ilike': NotILike,
57
+ is: Is,
58
+ isNot: IsNot,
59
+ '!is': IsNot,
60
+ exists: Exists,
61
+ notExists: NotExists,
62
+ '!exists': NotExists,
63
+ };
64
+ LogicalOperator.Operators = Operators;
65
+ export { Operators };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/builder",
3
3
  "description": "Extensible multi-dialect SQL query builder written with TypeScript",
4
- "version": "4.26.1",
4
+ "version": "5.0.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
package/serializable.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  import type { SerializationType } from './enums.js';
2
2
  import type { SerializeContext } from './serialize-context.js';
3
- export declare abstract class Serializable {
4
- abstract _type: SerializationType;
3
+ export interface Serializable {
4
+ _type: SerializationType;
5
5
  /**
6
6
  * Performs serialization
7
7
  */
8
- abstract _serialize(ctx: SerializeContext): string;
8
+ _serialize(ctx: SerializeContext): string;
9
9
  }
10
+ interface SerializableCtor {
11
+ new (): Serializable;
12
+ (): Serializable;
13
+ prototype: Serializable;
14
+ }
15
+ export declare const Serializable: SerializableCtor;
16
+ export {};
package/serializable.js CHANGED
@@ -1,2 +1,7 @@
1
- export class Serializable {
2
- }
1
+ export const Serializable = function () {
2
+ if (!this)
3
+ return new Serializable();
4
+ if (this.constructor === Serializable) {
5
+ throw new TypeError('Serializable is abstract and cannot be instantiated');
6
+ }
7
+ };
@@ -1,5 +1,5 @@
1
- import type { Query } from './query/query.js';
2
- import { DefaultSerializeFunction, GenerateOptions, ParamOptions } from './types.js';
1
+ import { Query } from './sql/index.js';
2
+ import type { DefaultSerializeFunction, GenerateOptions, ParamOptions } from './types.js';
3
3
  export declare class SerializeContext implements GenerateOptions {
4
4
  readonly rootQuery: Query;
5
5
  readonly reservedWords: string[];
@@ -1,7 +1,7 @@
1
1
  import { SerializationType } from './enums.js';
2
2
  import { SerializerRegistry } from './extensions.js';
3
3
  import { Serializable } from './serializable.js';
4
- import { isLogicalOperator, isQuery, isSerializable } from './typeguards.js';
4
+ import { isLogicalOperator, isQuery, isSerializable } from './type-guards.js';
5
5
  export class SerializeContext {
6
6
  rootQuery;
7
7
  reservedWords = [
@@ -1,13 +1,12 @@
1
1
  import { SerializationType } from '../enums.js';
2
2
  import { SerializeContext } from '../serialize-context.js';
3
- import { LogicalOperator } from '../sql-objects/operators/logical-operator.js';
4
- import { RawStatement } from '../sql-objects/raw-statement.js';
5
- import { TableName } from '../sql-objects/table-name.js';
3
+ import { Raw } from './elements/raw.js';
4
+ import { TableName } from './elements/table-name.js';
5
+ import { LogicalOperator } from './operators/logical-operator.js';
6
6
  import { Query } from './query.js';
7
- export declare class DeleteQuery extends Query {
8
- _table: TableName | RawStatement;
7
+ declare class DeleteClass extends Query {
8
+ _table: TableName | Raw;
9
9
  _where?: LogicalOperator;
10
- constructor(tableName: string | TableName | RawStatement);
11
10
  get _type(): SerializationType;
12
11
  /**
13
12
  * Defines "where" part of query
@@ -23,3 +22,12 @@ export declare class DeleteQuery extends Query {
23
22
  */
24
23
  _serializeWhere(ctx: SerializeContext): string;
25
24
  }
25
+ interface DeleteCtor {
26
+ new (tableName: string | TableName | Raw): Delete;
27
+ (tableName: string | TableName | Raw): Delete;
28
+ prototype: Delete;
29
+ }
30
+ export declare const Delete: DeleteCtor;
31
+ export interface Delete extends DeleteClass {
32
+ }
33
+ export {};
@@ -1,26 +1,11 @@
1
1
  import { SerializationType } from '../enums.js';
2
- import { OpAnd } from '../sql-objects/operators/op-and.js';
3
- import { TableName } from '../sql-objects/table-name.js';
4
- import { isRawStatement } from '../typeguards.js';
2
+ import { isRaw } from '../type-guards.js';
3
+ import { TableName } from './elements/table-name.js';
4
+ import { And } from './operators/and.js';
5
5
  import { Query } from './query.js';
6
- export class DeleteQuery extends Query {
6
+ class DeleteClass extends Query {
7
7
  _table;
8
8
  _where;
9
- constructor(tableName) {
10
- super();
11
- if (!(tableName &&
12
- (tableName instanceof TableName ||
13
- typeof tableName === 'string' ||
14
- isRawStatement(tableName)))) {
15
- throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
16
- }
17
- this._table =
18
- tableName instanceof TableName
19
- ? tableName
20
- : typeof tableName === 'string'
21
- ? new TableName(tableName)
22
- : tableName;
23
- }
24
9
  get _type() {
25
10
  return SerializationType.DELETE_QUERY;
26
11
  }
@@ -28,7 +13,7 @@ export class DeleteQuery extends Query {
28
13
  * Defines "where" part of query
29
14
  */
30
15
  where(...operator) {
31
- this._where = this._where || new OpAnd();
16
+ this._where = this._where || new And();
32
17
  this._where.add(...operator);
33
18
  return this;
34
19
  }
@@ -57,3 +42,22 @@ export class DeleteQuery extends Query {
57
42
  s ? 'where ' + s : '');
58
43
  }
59
44
  }
45
+ export const Delete = function (tableName) {
46
+ if (!(this instanceof Delete))
47
+ return new Delete(tableName);
48
+ Query.call(this);
49
+ if (!(tableName &&
50
+ (tableName instanceof TableName ||
51
+ typeof tableName === 'string' ||
52
+ isRaw(tableName)))) {
53
+ throw new TypeError('String or Raw instance required as first argument (tableName) for Delete');
54
+ }
55
+ this._table =
56
+ tableName instanceof TableName
57
+ ? tableName
58
+ : typeof tableName === 'string'
59
+ ? TableName(tableName)
60
+ : tableName;
61
+ };
62
+ Delete.prototype = DeleteClass.prototype;
63
+ Delete.prototype.constructor = Delete;
@@ -0,0 +1,18 @@
1
+ import { DataType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ export interface BaseField extends Serializable {
4
+ _dataType?: DataType;
5
+ _isArray?: boolean;
6
+ _isDataSet?: boolean;
7
+ _field: string;
8
+ _schema?: string;
9
+ _table?: string;
10
+ _descending?: boolean;
11
+ }
12
+ interface BaseFieldCtor {
13
+ new (): BaseField;
14
+ (): BaseField;
15
+ prototype: BaseField;
16
+ }
17
+ export declare const BaseField: BaseFieldCtor;
18
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Serializable } from '../../serializable.js';
2
+ export const BaseField = function () {
3
+ if (!(this instanceof BaseField))
4
+ return new BaseField();
5
+ if (this.constructor === BaseField) {
6
+ throw new TypeError('BaseField is abstract and cannot be instantiated');
7
+ }
8
+ Serializable.call(this);
9
+ this._field = '';
10
+ };
11
+ BaseField.prototype = Object.create(Serializable.prototype);
12
+ BaseField.prototype.constructor = BaseField;
@@ -1,10 +1,10 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- import { SerializeContext } from '../serialize-context.js';
4
- import { Operator } from './operator.js';
5
- import { LogicalOperator } from './operators/logical-operator.js';
6
- import { RawStatement } from './raw-statement.js';
7
- export declare class CaseStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ import { LogicalOperator } from '../operators/logical-operator.js';
5
+ import { Operator } from '../operators/operator.js';
6
+ import { Raw } from './raw.js';
7
+ declare class CaseClass extends Serializable {
8
8
  _expressions: {
9
9
  condition: Serializable;
10
10
  value: any;
@@ -12,12 +12,11 @@ export declare class CaseStatement extends Serializable {
12
12
  _elseValue: any;
13
13
  _condition?: LogicalOperator;
14
14
  _alias?: string;
15
- constructor();
16
15
  get _type(): SerializationType;
17
16
  /**
18
17
  * Defines "when" part of Case expression.
19
18
  */
20
- when(...condition: (Operator | RawStatement)[]): this;
19
+ when(...condition: (Operator | Raw)[]): this;
21
20
  /**
22
21
  * Defines "then" part of Case expression.
23
22
  */
@@ -40,3 +39,12 @@ export declare class CaseStatement extends Serializable {
40
39
  _serialize(ctx: SerializeContext): string;
41
40
  protected __defaultSerialize(ctx: SerializeContext, o: any): string;
42
41
  }
42
+ interface CaseCtor {
43
+ new (): Case;
44
+ (): Case;
45
+ prototype: Case;
46
+ }
47
+ export declare const Case: CaseCtor;
48
+ export interface Case extends CaseClass {
49
+ }
50
+ export {};
@@ -1,15 +1,11 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- import { OpAnd } from './operators/op-and.js';
4
- export class CaseStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { And } from '../operators/and.js';
4
+ class CaseClass extends Serializable {
5
5
  _expressions;
6
6
  _elseValue;
7
7
  _condition;
8
8
  _alias;
9
- constructor() {
10
- super();
11
- this._expressions = [];
12
- }
13
9
  get _type() {
14
10
  return SerializationType.CASE_STATEMENT;
15
11
  }
@@ -18,7 +14,7 @@ export class CaseStatement extends Serializable {
18
14
  */
19
15
  when(...condition) {
20
16
  if (condition.length)
21
- this._condition = new OpAnd(...condition);
17
+ this._condition = new And(...condition);
22
18
  else
23
19
  this._condition = undefined;
24
20
  return this;
@@ -85,3 +81,11 @@ export class CaseStatement extends Serializable {
85
81
  return out;
86
82
  }
87
83
  }
84
+ export const Case = function () {
85
+ if (!(this instanceof Case))
86
+ return new Case();
87
+ Serializable.call(this);
88
+ this._expressions = [];
89
+ };
90
+ Case.prototype = CaseClass.prototype;
91
+ Case.prototype.constructor = Case;
@@ -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 CoalesceClass extends Serializable {
5
+ _expressions: 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 CoalesceCtor {
23
+ new (...expressions: any[]): Coalesce;
24
+ (...expressions: any[]): Coalesce;
25
+ prototype: Coalesce;
26
+ }
27
+ export declare const Coalesce: CoalesceCtor;
28
+ export interface Coalesce extends CoalesceClass {
29
+ }
30
+ export {};
@@ -1,12 +1,8 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- export class CoalesceStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ class CoalesceClass extends Serializable {
4
4
  _expressions;
5
5
  _alias;
6
- constructor(...expressions) {
7
- super();
8
- this._expressions = expressions;
9
- }
10
6
  get _type() {
11
7
  return SerializationType.COALESCE_STATEMENT;
12
8
  }
@@ -42,3 +38,11 @@ export class CoalesceStatement extends Serializable {
42
38
  (this._alias ? ' ' + this._alias : ''));
43
39
  }
44
40
  }
41
+ export const Coalesce = function (...expressions) {
42
+ if (!(this instanceof Coalesce))
43
+ return new Coalesce(...expressions);
44
+ Serializable.call(this);
45
+ this._expressions = expressions;
46
+ };
47
+ Coalesce.prototype = CoalesceClass.prototype;
48
+ Coalesce.prototype.constructor = Coalesce;
@@ -0,0 +1,29 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ import { SerializeContext } from '../../serialize-context.js';
4
+ declare class CountClass extends Serializable {
5
+ _alias?: string;
6
+ get _type(): SerializationType;
7
+ /**
8
+ * Sets alias to case expression.
9
+ */
10
+ as(alias: string): this;
11
+ /**
12
+ * Performs serialization
13
+ *
14
+ * @param {Object} ctx
15
+ * @return {string}
16
+ * @override
17
+ */
18
+ _serialize(ctx: SerializeContext): string;
19
+ protected __defaultSerialize(ctx: SerializeContext, o: any): string;
20
+ }
21
+ interface CountCtor {
22
+ new (): Count;
23
+ (): Count;
24
+ prototype: Count;
25
+ }
26
+ export declare const Count: CountCtor;
27
+ export interface Count extends CountClass {
28
+ }
29
+ export {};
@@ -1,6 +1,6 @@
1
- import { SerializationType } from '../enums.js';
2
- import { Serializable } from '../serializable.js';
3
- export class CountStatement extends Serializable {
1
+ import { SerializationType } from '../../enums.js';
2
+ import { Serializable } from '../../serializable.js';
3
+ class CountClass extends Serializable {
4
4
  _alias;
5
5
  get _type() {
6
6
  return SerializationType.COUNT_STATEMENT;
@@ -31,3 +31,10 @@ export class CountStatement extends Serializable {
31
31
  return 'count(*)';
32
32
  }
33
33
  }
34
+ export const Count = function () {
35
+ if (!(this instanceof Count))
36
+ return new Count();
37
+ Serializable.call(this);
38
+ };
39
+ Count.prototype = CountClass.prototype;
40
+ Count.prototype.constructor = Count;
@@ -0,0 +1,27 @@
1
+ import { DataType, SerializationType } from '../../enums.js';
2
+ import { SerializeContext } from '../../serialize-context.js';
3
+ import { BaseField } from './base-field.js';
4
+ declare class FieldClass extends BaseField {
5
+ _alias?: string;
6
+ get _type(): SerializationType;
7
+ _serialize(ctx: SerializeContext): string;
8
+ }
9
+ interface FieldCtor {
10
+ new (expression: string, dataType?: DataType, isArray?: boolean): Field;
11
+ new (args: {
12
+ expression: string;
13
+ dataType?: DataType;
14
+ isArray?: boolean;
15
+ }): Field;
16
+ (expression: string, dataType?: DataType, isArray?: boolean): Field;
17
+ (args: {
18
+ expression: string;
19
+ dataType?: DataType;
20
+ isArray?: boolean;
21
+ }): Field;
22
+ prototype: Field;
23
+ }
24
+ export declare const Field: FieldCtor;
25
+ export interface Field extends FieldClass {
26
+ }
27
+ export {};
@@ -0,0 +1,54 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { BaseField } from './base-field.js';
3
+ const TABLE_COLUMN_PATTERN = /^ *((?:[a-zA-Z_][\w$_]*\.){0,2}) *([0-9a-zA-Z_][\w$_]*|\*) *(?:as)? *([a-zA-Z_][\w$_]*)?$/;
4
+ class FieldClass extends BaseField {
5
+ _alias;
6
+ get _type() {
7
+ return SerializationType.FIELD_NAME;
8
+ }
9
+ _serialize(ctx) {
10
+ const o = {
11
+ schema: this._schema,
12
+ table: this._table,
13
+ field: this._field,
14
+ alias: this._alias,
15
+ isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
16
+ };
17
+ return ctx.serialize(this._type, o, () => {
18
+ const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
19
+ (this._table ? this._table + '.' : '');
20
+ return (prefix +
21
+ (!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
22
+ (this._alias ? ' as ' + this._alias : ''));
23
+ });
24
+ }
25
+ }
26
+ export const Field = function (arg0, arg1, arg2) {
27
+ if (!(this instanceof Field))
28
+ return new Field(arg0, arg1, arg2);
29
+ BaseField.call(this);
30
+ let expression;
31
+ if (typeof arg0 === 'object') {
32
+ expression = arg0.expression;
33
+ this._dataType = arg0.dataType;
34
+ this._isArray = arg0.isArray;
35
+ }
36
+ else {
37
+ expression = arg0;
38
+ this._dataType = arg1;
39
+ this._isArray = arg2;
40
+ }
41
+ const m = expression?.match(TABLE_COLUMN_PATTERN);
42
+ if (!m)
43
+ throw new TypeError(`"${expression}" does not match table column format`);
44
+ this._field = m[2]?.trim();
45
+ if (m[1]) {
46
+ const a = m[1].split(/\./g);
47
+ a.pop();
48
+ this._table = a.pop()?.trim();
49
+ this._schema = a.pop()?.trim();
50
+ }
51
+ this._alias = this._field !== '*' ? m[3]?.trim() : '';
52
+ };
53
+ Field.prototype = FieldClass.prototype;
54
+ Field.prototype.constructor = Field;
@@ -0,0 +1,16 @@
1
+ import { SerializationType } from '../../enums.js';
2
+ import { SerializeContext } from '../../serialize-context.js';
3
+ import { BaseField } from './base-field.js';
4
+ declare class GroupColumnClass extends BaseField {
5
+ get _type(): SerializationType;
6
+ _serialize(ctx: SerializeContext): string;
7
+ }
8
+ interface GroupColumnCtor {
9
+ new (value: string): GroupColumn;
10
+ (value: string): GroupColumn;
11
+ prototype: GroupColumn;
12
+ }
13
+ export declare const GroupColumn: GroupColumnCtor;
14
+ export interface GroupColumn extends GroupColumnClass {
15
+ }
16
+ export {};