@mrnafisia/type-query 1.0.49 → 1.0.51

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 (44) hide show
  1. package/README.md +2 -2
  2. package/dist/U.d.ts +2 -2
  3. package/dist/U.js +28 -28
  4. package/dist/context.d.ts +987 -987
  5. package/dist/context.js +84 -84
  6. package/dist/dictionary.d.ts +12 -12
  7. package/dist/dictionary.js +179 -179
  8. package/dist/entity.d.ts +3585 -3585
  9. package/dist/entity.js +1053 -1053
  10. package/dist/error.d.ts +4 -4
  11. package/dist/error.js +7 -7
  12. package/dist/index.d.ts +18 -18
  13. package/dist/index.js +56 -56
  14. package/dist/model.d.ts +1005 -1005
  15. package/dist/model.js +282 -282
  16. package/dist/parser.d.ts +11 -11
  17. package/dist/parser.d.ts.map +1 -1
  18. package/dist/parser.js +123 -120
  19. package/dist/parser.js.map +1 -1
  20. package/dist/pool.d.ts +5 -5
  21. package/dist/pool.js +122 -122
  22. package/dist/schema.d.ts +25 -25
  23. package/dist/schema.js +405 -405
  24. package/dist/testUtil.d.ts +4 -4
  25. package/dist/testUtil.js +343 -343
  26. package/dist/types/context.d.ts +51 -51
  27. package/dist/types/context.js +2 -2
  28. package/dist/types/entity.d.ts +70 -70
  29. package/dist/types/entity.js +2 -2
  30. package/dist/types/json.d.ts +8 -8
  31. package/dist/types/json.js +2 -2
  32. package/dist/types/model.d.ts +23 -23
  33. package/dist/types/model.js +2 -2
  34. package/dist/types/pool.d.ts +18 -18
  35. package/dist/types/pool.js +2 -2
  36. package/dist/types/postgres.d.ts +9 -9
  37. package/dist/types/postgres.js +2 -2
  38. package/dist/types/table.d.ts +233 -233
  39. package/dist/types/table.js +2 -2
  40. package/dist/types/testUtil.d.ts +26 -26
  41. package/dist/types/testUtil.js +2 -2
  42. package/dist/utils.d.ts +67 -67
  43. package/dist/utils.js +220 -220
  44. package/package.json +40 -40
package/dist/utils.d.ts CHANGED
@@ -1,68 +1,68 @@
1
- import Decimal from 'decimal.js';
2
- import { JSON as Json } from './types/json';
3
- import type { Table } from './types/table';
4
- import type { ColumnTypeByTable, PostgresType } from './types/postgres';
5
- import type { ExpressionTypes, ValueExpression, Expression, QueryExpression, Query } from './types/entity';
6
- import type { ArithmeticOperator, NullOperator, BooleanOperator, CompareOperator, ListOperator, LikeOperator, JsonOperator } from './types/context';
7
- declare function val(v: null | undefined): ValueExpression<null>;
8
- declare function val(v: boolean | undefined): ValueExpression<boolean>;
9
- declare function val(v: number | undefined): ValueExpression<number>;
10
- declare function val(v: bigint | undefined): ValueExpression<bigint>;
11
- declare function val(v: Decimal | undefined): ValueExpression<Decimal>;
12
- declare function val(v: string | undefined): ValueExpression<string>;
13
- declare function val(v: Date | undefined): ValueExpression<Date>;
14
- declare function val(v: Json | undefined): ValueExpression<Json>;
15
- declare function col<T extends Table, C extends keyof T['columns'] & string>(table: T, column: C, full?: boolean, alias?: string): ValueExpression<ColumnTypeByTable<T, C>>;
16
- declare function fun<T extends ExpressionTypes>(name: string | undefined, args: readonly Expression<any>[] | undefined, cast?: string): ValueExpression<T>;
17
- declare function swt<T extends ExpressionTypes>(cases: readonly ({
18
- when: Expression<boolean>;
19
- then: Expression<T>;
20
- } | undefined)[] | undefined, otherwise?: Expression<T>): ValueExpression<T>;
21
- declare function raw<T extends ExpressionTypes>(v: string): ValueExpression<T>;
22
- declare function subQry<T extends ExpressionTypes>(v: Query<any, any>): QueryExpression<T>;
23
- declare function notOp(v: Expression<boolean>): ValueExpression<boolean>;
24
- declare function artOp(v1: Expression<number>, op: ArithmeticOperator, v2: Expression<number>): ValueExpression<number>;
25
- declare function artOp(v1: Expression<bigint>, op: ArithmeticOperator, v2: Expression<bigint>): ValueExpression<bigint>;
26
- declare function artOp(v1: Expression<Decimal>, op: ArithmeticOperator, v2: Expression<Decimal>): ValueExpression<Decimal>;
27
- declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<number>[] | undefined): ValueExpression<number>;
28
- declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<bigint>[] | undefined): ValueExpression<bigint>;
29
- declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<Decimal>[] | undefined): ValueExpression<Decimal>;
30
- declare function conOp(v1: Expression<string>, v2: Expression<string>): ValueExpression<string>;
31
- declare function conOp(v1: Expression<Json>, v2: Expression<Json>): ValueExpression<Json>;
32
- declare function conAllOp(v: readonly Expression<string>[] | undefined): ValueExpression<string>;
33
- declare function conAllOp(v: readonly Expression<Json>[] | undefined): ValueExpression<Json>;
34
- declare function jMinusOp(v1: Expression<Json>, v2: Expression<string>): ValueExpression<Json>;
35
- declare function jArrMinusOp(v1: Expression<Json>, v2: readonly Expression<string>[] | undefined): ValueExpression<Json>;
36
- declare function andOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
37
- declare function andAllOp(v: readonly Expression<boolean>[] | undefined): ValueExpression<boolean>;
38
- declare function orOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
39
- declare function orAllOp(v: readonly Expression<boolean>[] | undefined): ValueExpression<boolean>;
40
- declare function nullOp(v: Expression<null>, op: NullOperator): ValueExpression<boolean>;
41
- declare function boolOp(v: Expression<boolean>, op: BooleanOperator): ValueExpression<boolean>;
42
- declare function cmpOp(v1: Expression<number>, op: CompareOperator, v2: Expression<number>): ValueExpression<boolean>;
43
- declare function cmpOp(v1: Expression<bigint>, op: CompareOperator, v2: Expression<bigint>): ValueExpression<boolean>;
44
- declare function cmpOp(v1: Expression<Decimal>, op: CompareOperator, v2: Expression<Decimal>): ValueExpression<boolean>;
45
- declare function cmpOp(v1: Expression<string>, op: CompareOperator, v2: Expression<string>): ValueExpression<boolean>;
46
- declare function cmpOp(v1: Expression<Date>, op: CompareOperator, v2: Expression<Date>): ValueExpression<boolean>;
47
- declare function listOp(v1: Expression<number>, op: ListOperator, v2: readonly Expression<number>[] | undefined): ValueExpression<boolean>;
48
- declare function listOp(v1: Expression<bigint>, op: ListOperator, v2: readonly Expression<bigint>[] | undefined): ValueExpression<boolean>;
49
- declare function listOp(v1: Expression<Decimal>, op: ListOperator, v2: readonly Expression<Decimal>[] | undefined): ValueExpression<boolean>;
50
- declare function listOp(v1: Expression<string>, op: ListOperator, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
51
- declare function listOp(v1: Expression<Date>, op: ListOperator, v2: readonly Expression<Date>[] | undefined): ValueExpression<boolean>;
52
- declare function btOp(v1: Expression<number>, v2: Expression<number>, v3: Expression<number>): ValueExpression<boolean>;
53
- declare function btOp(v1: Expression<bigint>, v2: Expression<bigint>, v3: Expression<bigint>): ValueExpression<boolean>;
54
- declare function btOp(v1: Expression<Decimal>, v2: Expression<Decimal>, v3: Expression<Decimal>): ValueExpression<boolean>;
55
- declare function btOp(v1: Expression<string>, v2: Expression<string>, v3: Expression<string>): ValueExpression<boolean>;
56
- declare function btOp(v1: Expression<Date>, v2: Expression<Date>, v3: Expression<Date>): ValueExpression<boolean>;
57
- declare function likeOp(v1: Expression<string>, op: Extract<LikeOperator, 'like'>, v2: Expression<string>): ValueExpression<boolean>;
58
- declare function likeOp(v1: Expression<string>, op: Extract<LikeOperator, 'like all' | 'like some'>, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
59
- declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '@>' | '<@'>, v2: Expression<Json>): ValueExpression<boolean>;
60
- declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '?'>, v2: Expression<string>): ValueExpression<boolean>;
61
- declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '?&' | '?|'>, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
62
- declare function existsOp(v: QueryExpression<any>): ValueExpression<boolean>;
63
- declare const stringify: <T extends ExpressionTypes>(v: T, inline?: boolean) => T extends number ? number : T extends bigint ? bigint : string;
64
- declare const cast: (v: unknown, [type, nullable]: [type: PostgresType, nullable: boolean]) => ExpressionTypes;
65
- export { val, col, fun, swt, raw, subQry };
66
- export { notOp, artOp, artAllOp, conOp, conAllOp, jMinusOp, jArrMinusOp, andOp, andAllOp, orOp, orAllOp, nullOp, boolOp, cmpOp, listOp, btOp, likeOp, jsonOp, existsOp };
67
- export { stringify, cast };
1
+ import Decimal from 'decimal.js';
2
+ import { JSON as Json } from './types/json';
3
+ import type { Table } from './types/table';
4
+ import type { ColumnTypeByTable, PostgresType } from './types/postgres';
5
+ import type { ExpressionTypes, ValueExpression, Expression, QueryExpression, Query } from './types/entity';
6
+ import type { ArithmeticOperator, NullOperator, BooleanOperator, CompareOperator, ListOperator, LikeOperator, JsonOperator } from './types/context';
7
+ declare function val(v: null | undefined): ValueExpression<null>;
8
+ declare function val(v: boolean | undefined): ValueExpression<boolean>;
9
+ declare function val(v: number | undefined): ValueExpression<number>;
10
+ declare function val(v: bigint | undefined): ValueExpression<bigint>;
11
+ declare function val(v: Decimal | undefined): ValueExpression<Decimal>;
12
+ declare function val(v: string | undefined): ValueExpression<string>;
13
+ declare function val(v: Date | undefined): ValueExpression<Date>;
14
+ declare function val(v: Json | undefined): ValueExpression<Json>;
15
+ declare function col<T extends Table, C extends keyof T['columns'] & string>(table: T, column: C, full?: boolean, alias?: string): ValueExpression<ColumnTypeByTable<T, C>>;
16
+ declare function fun<T extends ExpressionTypes>(name: string | undefined, args: readonly Expression<any>[] | undefined, cast?: string): ValueExpression<T>;
17
+ declare function swt<T extends ExpressionTypes>(cases: readonly ({
18
+ when: Expression<boolean>;
19
+ then: Expression<T>;
20
+ } | undefined)[] | undefined, otherwise?: Expression<T>): ValueExpression<T>;
21
+ declare function raw<T extends ExpressionTypes>(v: string): ValueExpression<T>;
22
+ declare function subQry<T extends ExpressionTypes>(v: Query<any, any>): QueryExpression<T>;
23
+ declare function notOp(v: Expression<boolean>): ValueExpression<boolean>;
24
+ declare function artOp(v1: Expression<number>, op: ArithmeticOperator, v2: Expression<number>): ValueExpression<number>;
25
+ declare function artOp(v1: Expression<bigint>, op: ArithmeticOperator, v2: Expression<bigint>): ValueExpression<bigint>;
26
+ declare function artOp(v1: Expression<Decimal>, op: ArithmeticOperator, v2: Expression<Decimal>): ValueExpression<Decimal>;
27
+ declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<number>[] | undefined): ValueExpression<number>;
28
+ declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<bigint>[] | undefined): ValueExpression<bigint>;
29
+ declare function artAllOp(op: ArithmeticOperator, v: readonly Expression<Decimal>[] | undefined): ValueExpression<Decimal>;
30
+ declare function conOp(v1: Expression<string>, v2: Expression<string>): ValueExpression<string>;
31
+ declare function conOp(v1: Expression<Json>, v2: Expression<Json>): ValueExpression<Json>;
32
+ declare function conAllOp(v: readonly Expression<string>[] | undefined): ValueExpression<string>;
33
+ declare function conAllOp(v: readonly Expression<Json>[] | undefined): ValueExpression<Json>;
34
+ declare function jMinusOp(v1: Expression<Json>, v2: Expression<string>): ValueExpression<Json>;
35
+ declare function jArrMinusOp(v1: Expression<Json>, v2: readonly Expression<string>[] | undefined): ValueExpression<Json>;
36
+ declare function andOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
37
+ declare function andAllOp(v: readonly Expression<boolean>[] | undefined): ValueExpression<boolean>;
38
+ declare function orOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
39
+ declare function orAllOp(v: readonly Expression<boolean>[] | undefined): ValueExpression<boolean>;
40
+ declare function nullOp(v: Expression<null>, op: NullOperator): ValueExpression<boolean>;
41
+ declare function boolOp(v: Expression<boolean>, op: BooleanOperator): ValueExpression<boolean>;
42
+ declare function cmpOp(v1: Expression<number>, op: CompareOperator, v2: Expression<number>): ValueExpression<boolean>;
43
+ declare function cmpOp(v1: Expression<bigint>, op: CompareOperator, v2: Expression<bigint>): ValueExpression<boolean>;
44
+ declare function cmpOp(v1: Expression<Decimal>, op: CompareOperator, v2: Expression<Decimal>): ValueExpression<boolean>;
45
+ declare function cmpOp(v1: Expression<string>, op: CompareOperator, v2: Expression<string>): ValueExpression<boolean>;
46
+ declare function cmpOp(v1: Expression<Date>, op: CompareOperator, v2: Expression<Date>): ValueExpression<boolean>;
47
+ declare function listOp(v1: Expression<number>, op: ListOperator, v2: readonly Expression<number>[] | undefined): ValueExpression<boolean>;
48
+ declare function listOp(v1: Expression<bigint>, op: ListOperator, v2: readonly Expression<bigint>[] | undefined): ValueExpression<boolean>;
49
+ declare function listOp(v1: Expression<Decimal>, op: ListOperator, v2: readonly Expression<Decimal>[] | undefined): ValueExpression<boolean>;
50
+ declare function listOp(v1: Expression<string>, op: ListOperator, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
51
+ declare function listOp(v1: Expression<Date>, op: ListOperator, v2: readonly Expression<Date>[] | undefined): ValueExpression<boolean>;
52
+ declare function btOp(v1: Expression<number>, v2: Expression<number>, v3: Expression<number>): ValueExpression<boolean>;
53
+ declare function btOp(v1: Expression<bigint>, v2: Expression<bigint>, v3: Expression<bigint>): ValueExpression<boolean>;
54
+ declare function btOp(v1: Expression<Decimal>, v2: Expression<Decimal>, v3: Expression<Decimal>): ValueExpression<boolean>;
55
+ declare function btOp(v1: Expression<string>, v2: Expression<string>, v3: Expression<string>): ValueExpression<boolean>;
56
+ declare function btOp(v1: Expression<Date>, v2: Expression<Date>, v3: Expression<Date>): ValueExpression<boolean>;
57
+ declare function likeOp(v1: Expression<string>, op: Extract<LikeOperator, 'like'>, v2: Expression<string>): ValueExpression<boolean>;
58
+ declare function likeOp(v1: Expression<string>, op: Extract<LikeOperator, 'like all' | 'like some'>, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
59
+ declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '@>' | '<@'>, v2: Expression<Json>): ValueExpression<boolean>;
60
+ declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '?'>, v2: Expression<string>): ValueExpression<boolean>;
61
+ declare function jsonOp(v1: Expression<Json>, op: Extract<JsonOperator, '?&' | '?|'>, v2: readonly Expression<string>[] | undefined): ValueExpression<boolean>;
62
+ declare function existsOp(v: QueryExpression<any>): ValueExpression<boolean>;
63
+ declare const stringify: <T extends ExpressionTypes>(v: T, inline?: boolean) => T extends number ? number : T extends bigint ? bigint : string;
64
+ declare const cast: (v: unknown, [type, nullable]: [type: PostgresType, nullable: boolean]) => ExpressionTypes;
65
+ export { val, col, fun, swt, raw, subQry };
66
+ export { notOp, artOp, artAllOp, conOp, conAllOp, jMinusOp, jArrMinusOp, andOp, andAllOp, orOp, orAllOp, nullOp, boolOp, cmpOp, listOp, btOp, likeOp, jsonOp, existsOp };
67
+ export { stringify, cast };
68
68
  //# sourceMappingURL=utils.d.ts.map
package/dist/utils.js CHANGED
@@ -1,221 +1,221 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cast = exports.stringify = exports.existsOp = exports.jsonOp = exports.likeOp = exports.btOp = exports.listOp = exports.cmpOp = exports.boolOp = exports.nullOp = exports.orAllOp = exports.orOp = exports.andAllOp = exports.andOp = exports.jArrMinusOp = exports.jMinusOp = exports.conAllOp = exports.conOp = exports.artAllOp = exports.artOp = exports.notOp = exports.subQry = exports.raw = exports.swt = exports.fun = exports.col = exports.val = void 0;
7
- var decimal_js_1 = __importDefault(require("decimal.js"));
8
- var entity_1 = require("./entity");
9
- function val(v) {
10
- return ['val', v];
11
- }
12
- exports.val = val;
13
- function col(table, column, full, alias) {
14
- if (full === void 0) { full = false; }
15
- return ['col', (0, entity_1.resolveColumn)(table, column, full, alias)];
16
- }
17
- exports.col = col;
18
- function fun(name, args, cast) {
19
- if (cast === void 0) { cast = ''; }
20
- return ['fun', name, args, cast];
21
- }
22
- exports.fun = fun;
23
- function swt(cases, otherwise) {
24
- return ['swt', cases, otherwise];
25
- }
26
- exports.swt = swt;
27
- function raw(v) {
28
- return ['raw', v];
29
- }
30
- exports.raw = raw;
31
- function subQry(v) {
32
- return ['qry', v];
33
- }
34
- exports.subQry = subQry;
35
- function notOp(v) {
36
- return ['not', v];
37
- }
38
- exports.notOp = notOp;
39
- function artOp(v1, op, v2) {
40
- switch (op) {
41
- case '+':
42
- return ['+', [v1, v2]];
43
- case '-':
44
- return ['-', [v1, v2]];
45
- case '*':
46
- return ['*', [v1, v2]];
47
- case '/':
48
- return ['/', [v1, v2]];
49
- case '**':
50
- return ['**', [v1, v2]];
51
- }
52
- }
53
- exports.artOp = artOp;
54
- function artAllOp(op, v) {
55
- switch (op) {
56
- case '+':
57
- return ['+', v];
58
- case '-':
59
- return ['-', v];
60
- case '*':
61
- return ['*', v];
62
- case '/':
63
- return ['/', v];
64
- case '**':
65
- return ['**', v];
66
- }
67
- }
68
- exports.artAllOp = artAllOp;
69
- function conOp(v1, v2) {
70
- return ['||', [v1, v2]];
71
- }
72
- exports.conOp = conOp;
73
- function conAllOp(v) {
74
- return ['||', v];
75
- }
76
- exports.conAllOp = conAllOp;
77
- function jMinusOp(v1, v2) {
78
- return ['j-', v1, v2];
79
- }
80
- exports.jMinusOp = jMinusOp;
81
- function jArrMinusOp(v1, v2) {
82
- return ['j-a', v1, v2];
83
- }
84
- exports.jArrMinusOp = jArrMinusOp;
85
- function andOp(v1, v2) {
86
- return ['and', [v1, v2]];
87
- }
88
- exports.andOp = andOp;
89
- function andAllOp(v) {
90
- return ['and', v];
91
- }
92
- exports.andAllOp = andAllOp;
93
- function orOp(v1, v2) {
94
- return ['or', [v1, v2]];
95
- }
96
- exports.orOp = orOp;
97
- function orAllOp(v) {
98
- return ['or', v];
99
- }
100
- exports.orAllOp = orAllOp;
101
- function nullOp(v, op) {
102
- switch (op) {
103
- case '= null':
104
- return ['=n', v];
105
- case '!= null':
106
- return ['!=n', v];
107
- }
108
- }
109
- exports.nullOp = nullOp;
110
- function boolOp(v, op) {
111
- switch (op) {
112
- case '= true':
113
- return ['=t', v];
114
- case '= false':
115
- return ['=f', v];
116
- }
117
- }
118
- exports.boolOp = boolOp;
119
- function cmpOp(v1, op, v2) {
120
- switch (op) {
121
- case '=':
122
- return ['=', v1, v2];
123
- case '!=':
124
- return ['!=', v1, v2];
125
- case '>':
126
- return ['>', v1, v2];
127
- case '>=':
128
- return ['>=', v1, v2];
129
- case '<':
130
- return ['<', v1, v2];
131
- case '<=':
132
- return ['<=', v1, v2];
133
- }
134
- }
135
- exports.cmpOp = cmpOp;
136
- function listOp(v1, op, v2) {
137
- switch (op) {
138
- case 'in':
139
- return ['in', v1, v2];
140
- case 'not in':
141
- return ['nin', v1, v2];
142
- }
143
- }
144
- exports.listOp = listOp;
145
- function btOp(v1, v2, v3) {
146
- return ['bt', v1, v2, v3];
147
- }
148
- exports.btOp = btOp;
149
- function likeOp(v1, op, v2) {
150
- switch (op) {
151
- case 'like':
152
- return ['lk', v1, v2];
153
- case 'like all':
154
- return ['lka', v1, v2];
155
- case 'like some':
156
- return ['lks', v1, v2];
157
- }
158
- }
159
- exports.likeOp = likeOp;
160
- function jsonOp(v1, op, v2) {
161
- switch (op) {
162
- case '@>':
163
- return ['@>', v1, v2];
164
- case '<@':
165
- return ['<@', v1, v2];
166
- case '?':
167
- return ['?', v1, v2];
168
- case '?&':
169
- return ['?&', v1, v2];
170
- case '?|':
171
- return ['?|', v1, v2];
172
- }
173
- }
174
- exports.jsonOp = jsonOp;
175
- function existsOp(v) {
176
- return ['exists', v];
177
- }
178
- exports.existsOp = existsOp;
179
- var stringify = function (v, inline) {
180
- if (inline === void 0) { inline = false; }
181
- var result;
182
- if (v === null) {
183
- result = 'NULL';
184
- }
185
- else if (typeof v === 'boolean') {
186
- result = v ? 'TRUE' : 'FALSE';
187
- }
188
- else if (typeof v === 'number' || typeof v === 'bigint') {
189
- result = v;
190
- }
191
- else if (v instanceof decimal_js_1.default) {
192
- result = v.toString();
193
- }
194
- else if (v instanceof Date) {
195
- result = inline ? "'".concat(v.toISOString(), "'") : v.toISOString();
196
- }
197
- else if (typeof v === 'object') {
198
- result = inline ? "'".concat(JSON.stringify(v), "'::JSONB") : JSON.stringify(v);
199
- }
200
- else {
201
- result = inline ? "'".concat(v, "'") : "".concat(v);
202
- }
203
- return result;
204
- };
205
- exports.stringify = stringify;
206
- var cast = function (v, _a) {
207
- var type = _a[0], nullable = _a[1];
208
- if (nullable && v === null) {
209
- return null;
210
- }
211
- switch (type) {
212
- case 'bigint':
213
- return BigInt(v);
214
- case 'numeric':
215
- return new decimal_js_1.default(v);
216
- default:
217
- return v;
218
- }
219
- };
220
- exports.cast = cast;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cast = exports.stringify = exports.existsOp = exports.jsonOp = exports.likeOp = exports.btOp = exports.listOp = exports.cmpOp = exports.boolOp = exports.nullOp = exports.orAllOp = exports.orOp = exports.andAllOp = exports.andOp = exports.jArrMinusOp = exports.jMinusOp = exports.conAllOp = exports.conOp = exports.artAllOp = exports.artOp = exports.notOp = exports.subQry = exports.raw = exports.swt = exports.fun = exports.col = exports.val = void 0;
7
+ var decimal_js_1 = __importDefault(require("decimal.js"));
8
+ var entity_1 = require("./entity");
9
+ function val(v) {
10
+ return ['val', v];
11
+ }
12
+ exports.val = val;
13
+ function col(table, column, full, alias) {
14
+ if (full === void 0) { full = false; }
15
+ return ['col', (0, entity_1.resolveColumn)(table, column, full, alias)];
16
+ }
17
+ exports.col = col;
18
+ function fun(name, args, cast) {
19
+ if (cast === void 0) { cast = ''; }
20
+ return ['fun', name, args, cast];
21
+ }
22
+ exports.fun = fun;
23
+ function swt(cases, otherwise) {
24
+ return ['swt', cases, otherwise];
25
+ }
26
+ exports.swt = swt;
27
+ function raw(v) {
28
+ return ['raw', v];
29
+ }
30
+ exports.raw = raw;
31
+ function subQry(v) {
32
+ return ['qry', v];
33
+ }
34
+ exports.subQry = subQry;
35
+ function notOp(v) {
36
+ return ['not', v];
37
+ }
38
+ exports.notOp = notOp;
39
+ function artOp(v1, op, v2) {
40
+ switch (op) {
41
+ case '+':
42
+ return ['+', [v1, v2]];
43
+ case '-':
44
+ return ['-', [v1, v2]];
45
+ case '*':
46
+ return ['*', [v1, v2]];
47
+ case '/':
48
+ return ['/', [v1, v2]];
49
+ case '**':
50
+ return ['**', [v1, v2]];
51
+ }
52
+ }
53
+ exports.artOp = artOp;
54
+ function artAllOp(op, v) {
55
+ switch (op) {
56
+ case '+':
57
+ return ['+', v];
58
+ case '-':
59
+ return ['-', v];
60
+ case '*':
61
+ return ['*', v];
62
+ case '/':
63
+ return ['/', v];
64
+ case '**':
65
+ return ['**', v];
66
+ }
67
+ }
68
+ exports.artAllOp = artAllOp;
69
+ function conOp(v1, v2) {
70
+ return ['||', [v1, v2]];
71
+ }
72
+ exports.conOp = conOp;
73
+ function conAllOp(v) {
74
+ return ['||', v];
75
+ }
76
+ exports.conAllOp = conAllOp;
77
+ function jMinusOp(v1, v2) {
78
+ return ['j-', v1, v2];
79
+ }
80
+ exports.jMinusOp = jMinusOp;
81
+ function jArrMinusOp(v1, v2) {
82
+ return ['j-a', v1, v2];
83
+ }
84
+ exports.jArrMinusOp = jArrMinusOp;
85
+ function andOp(v1, v2) {
86
+ return ['and', [v1, v2]];
87
+ }
88
+ exports.andOp = andOp;
89
+ function andAllOp(v) {
90
+ return ['and', v];
91
+ }
92
+ exports.andAllOp = andAllOp;
93
+ function orOp(v1, v2) {
94
+ return ['or', [v1, v2]];
95
+ }
96
+ exports.orOp = orOp;
97
+ function orAllOp(v) {
98
+ return ['or', v];
99
+ }
100
+ exports.orAllOp = orAllOp;
101
+ function nullOp(v, op) {
102
+ switch (op) {
103
+ case '= null':
104
+ return ['=n', v];
105
+ case '!= null':
106
+ return ['!=n', v];
107
+ }
108
+ }
109
+ exports.nullOp = nullOp;
110
+ function boolOp(v, op) {
111
+ switch (op) {
112
+ case '= true':
113
+ return ['=t', v];
114
+ case '= false':
115
+ return ['=f', v];
116
+ }
117
+ }
118
+ exports.boolOp = boolOp;
119
+ function cmpOp(v1, op, v2) {
120
+ switch (op) {
121
+ case '=':
122
+ return ['=', v1, v2];
123
+ case '!=':
124
+ return ['!=', v1, v2];
125
+ case '>':
126
+ return ['>', v1, v2];
127
+ case '>=':
128
+ return ['>=', v1, v2];
129
+ case '<':
130
+ return ['<', v1, v2];
131
+ case '<=':
132
+ return ['<=', v1, v2];
133
+ }
134
+ }
135
+ exports.cmpOp = cmpOp;
136
+ function listOp(v1, op, v2) {
137
+ switch (op) {
138
+ case 'in':
139
+ return ['in', v1, v2];
140
+ case 'not in':
141
+ return ['nin', v1, v2];
142
+ }
143
+ }
144
+ exports.listOp = listOp;
145
+ function btOp(v1, v2, v3) {
146
+ return ['bt', v1, v2, v3];
147
+ }
148
+ exports.btOp = btOp;
149
+ function likeOp(v1, op, v2) {
150
+ switch (op) {
151
+ case 'like':
152
+ return ['lk', v1, v2];
153
+ case 'like all':
154
+ return ['lka', v1, v2];
155
+ case 'like some':
156
+ return ['lks', v1, v2];
157
+ }
158
+ }
159
+ exports.likeOp = likeOp;
160
+ function jsonOp(v1, op, v2) {
161
+ switch (op) {
162
+ case '@>':
163
+ return ['@>', v1, v2];
164
+ case '<@':
165
+ return ['<@', v1, v2];
166
+ case '?':
167
+ return ['?', v1, v2];
168
+ case '?&':
169
+ return ['?&', v1, v2];
170
+ case '?|':
171
+ return ['?|', v1, v2];
172
+ }
173
+ }
174
+ exports.jsonOp = jsonOp;
175
+ function existsOp(v) {
176
+ return ['exists', v];
177
+ }
178
+ exports.existsOp = existsOp;
179
+ var stringify = function (v, inline) {
180
+ if (inline === void 0) { inline = false; }
181
+ var result;
182
+ if (v === null) {
183
+ result = 'NULL';
184
+ }
185
+ else if (typeof v === 'boolean') {
186
+ result = v ? 'TRUE' : 'FALSE';
187
+ }
188
+ else if (typeof v === 'number' || typeof v === 'bigint') {
189
+ result = v;
190
+ }
191
+ else if (v instanceof decimal_js_1.default) {
192
+ result = v.toString();
193
+ }
194
+ else if (v instanceof Date) {
195
+ result = inline ? "'".concat(v.toISOString(), "'") : v.toISOString();
196
+ }
197
+ else if (typeof v === 'object') {
198
+ result = inline ? "'".concat(JSON.stringify(v), "'::JSONB") : JSON.stringify(v);
199
+ }
200
+ else {
201
+ result = inline ? "'".concat(v, "'") : "".concat(v);
202
+ }
203
+ return result;
204
+ };
205
+ exports.stringify = stringify;
206
+ var cast = function (v, _a) {
207
+ var type = _a[0], nullable = _a[1];
208
+ if (nullable && v === null) {
209
+ return null;
210
+ }
211
+ switch (type) {
212
+ case 'bigint':
213
+ return BigInt(v);
214
+ case 'numeric':
215
+ return new decimal_js_1.default(v);
216
+ default:
217
+ return v;
218
+ }
219
+ };
220
+ exports.cast = cast;
221
221
  //# sourceMappingURL=utils.js.map