@mrnafisia/type-query 1.0.26 → 1.0.29

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 (46) hide show
  1. package/README.md +2 -2
  2. package/dist/U.d.ts +2 -2
  3. package/dist/U.js +27 -27
  4. package/dist/context.d.ts +5 -5
  5. package/dist/context.js +85 -85
  6. package/dist/dictionary.d.ts +12 -12
  7. package/dist/dictionary.js +173 -173
  8. package/dist/entity.d.ts +3306 -3306
  9. package/dist/entity.js +960 -960
  10. package/dist/error.d.ts +4 -4
  11. package/dist/error.js +6 -6
  12. package/dist/index.d.ts +32 -32
  13. package/dist/index.js +35 -35
  14. package/dist/model.d.ts +991 -991
  15. package/dist/model.d.ts.map +1 -1
  16. package/dist/model.js +355 -293
  17. package/dist/model.js.map +1 -1
  18. package/dist/pool.d.ts +5 -5
  19. package/dist/pool.d.ts.map +1 -1
  20. package/dist/pool.js +120 -120
  21. package/dist/pool.js.map +1 -1
  22. package/dist/schema.d.ts +25 -25
  23. package/dist/schema.js +395 -395
  24. package/dist/testUtil.d.ts +4 -4
  25. package/dist/testUtil.js +330 -330
  26. package/dist/types/context.d.ts +55 -55
  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.d.ts.map +1 -1
  34. package/dist/types/model.js +2 -2
  35. package/dist/types/pool.d.ts +18 -17
  36. package/dist/types/pool.d.ts.map +1 -1
  37. package/dist/types/pool.js +2 -2
  38. package/dist/types/postgres.d.ts +9 -9
  39. package/dist/types/postgres.js +2 -2
  40. package/dist/types/table.d.ts +234 -234
  41. package/dist/types/table.js +2 -2
  42. package/dist/types/testUtil.d.ts +26 -26
  43. package/dist/types/testUtil.js +2 -2
  44. package/dist/utils.d.ts +67 -67
  45. package/dist/utils.js +216 -216
  46. package/package.json +39 -39
package/dist/utils.d.ts CHANGED
@@ -1,68 +1,68 @@
1
- import Decimal from 'decimal.js';
2
- import type Table from './types/table';
3
- import type { JSON } from './types/json';
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: Expression<any>[] | undefined, cast?: string): ValueExpression<T>;
17
- declare function swt<T extends ExpressionTypes>(cases: ({
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: Expression<number>[] | undefined): ValueExpression<number>;
28
- declare function artAllOp(op: ArithmeticOperator, v: Expression<bigint>[] | undefined): ValueExpression<bigint>;
29
- declare function artAllOp(op: ArithmeticOperator, v: 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: Expression<string>[] | undefined): ValueExpression<string>;
33
- declare function conAllOp(v: 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: Expression<string>[] | undefined): ValueExpression<JSON>;
36
- declare function andOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
37
- declare function andAllOp(v: Expression<boolean>[] | undefined): ValueExpression<boolean>;
38
- declare function orOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
39
- declare function orAllOp(v: 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: Expression<number>[] | undefined): ValueExpression<boolean>;
48
- declare function listOp(v1: Expression<bigint>, op: ListOperator, v2: Expression<bigint>[] | undefined): ValueExpression<boolean>;
49
- declare function listOp(v1: Expression<Decimal>, op: ListOperator, v2: Expression<Decimal>[] | undefined): ValueExpression<boolean>;
50
- declare function listOp(v1: Expression<string>, op: ListOperator, v2: Expression<string>[] | undefined): ValueExpression<boolean>;
51
- declare function listOp(v1: Expression<Date>, op: ListOperator, v2: 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: 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: 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: PostgresType) => 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 type Table from './types/table';
3
+ import type { JSON } from './types/json';
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: Expression<any>[] | undefined, cast?: string): ValueExpression<T>;
17
+ declare function swt<T extends ExpressionTypes>(cases: ({
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: Expression<number>[] | undefined): ValueExpression<number>;
28
+ declare function artAllOp(op: ArithmeticOperator, v: Expression<bigint>[] | undefined): ValueExpression<bigint>;
29
+ declare function artAllOp(op: ArithmeticOperator, v: 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: Expression<string>[] | undefined): ValueExpression<string>;
33
+ declare function conAllOp(v: 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: Expression<string>[] | undefined): ValueExpression<JSON>;
36
+ declare function andOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
37
+ declare function andAllOp(v: Expression<boolean>[] | undefined): ValueExpression<boolean>;
38
+ declare function orOp(v1: Expression<boolean>, v2: Expression<boolean>): ValueExpression<boolean>;
39
+ declare function orAllOp(v: 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: Expression<number>[] | undefined): ValueExpression<boolean>;
48
+ declare function listOp(v1: Expression<bigint>, op: ListOperator, v2: Expression<bigint>[] | undefined): ValueExpression<boolean>;
49
+ declare function listOp(v1: Expression<Decimal>, op: ListOperator, v2: Expression<Decimal>[] | undefined): ValueExpression<boolean>;
50
+ declare function listOp(v1: Expression<string>, op: ListOperator, v2: Expression<string>[] | undefined): ValueExpression<boolean>;
51
+ declare function listOp(v1: Expression<Date>, op: ListOperator, v2: 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: 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: 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: PostgresType) => 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,217 +1,217 @@
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 = inline ? "'".concat(v.toString(), "'") : 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, "'") : v;
202
- }
203
- return result;
204
- };
205
- exports.stringify = stringify;
206
- var cast = function (v, type) {
207
- switch (type) {
208
- case 'bigint':
209
- return BigInt(v);
210
- case 'numeric':
211
- return new decimal_js_1.default(v);
212
- default:
213
- return v;
214
- }
215
- };
216
- 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 = inline ? "'".concat(v.toString(), "'") : 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, "'") : v;
202
+ }
203
+ return result;
204
+ };
205
+ exports.stringify = stringify;
206
+ var cast = function (v, type) {
207
+ switch (type) {
208
+ case 'bigint':
209
+ return BigInt(v);
210
+ case 'numeric':
211
+ return new decimal_js_1.default(v);
212
+ default:
213
+ return v;
214
+ }
215
+ };
216
+ exports.cast = cast;
217
217
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@mrnafisia/type-query",
3
- "version": "1.0.26",
4
- "description": "mini-orm with full type support for postgres.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
10
- "scripts": {
11
- "build": "tsc",
12
- "test": "jest ./tests"
13
- },
14
- "keywords": [
15
- "orm",
16
- "query-builder",
17
- "postgres",
18
- "sql",
19
- "type-safe"
20
- ],
21
- "repository": "https://github.com/MRNafisiA/type-query.git",
22
- "author": "MRNafisiA <mnafisiasl@gmail.com>",
23
- "license": "MIT",
24
- "devDependencies": {
25
- "@types/jest": "^28.1.0",
26
- "@types/lodash": "^4.14.182",
27
- "@types/node": "^17.0.39",
28
- "@types/pg": "^8.6.5",
29
- "jest": "^28.1.0",
30
- "ts-jest": "^28.0.4",
31
- "typescript": "^4.7.2"
32
- },
33
- "dependencies": {
34
- "decimal.js": "^10.3.1",
35
- "lodash": "^4.17.21",
36
- "never-catch": "^1.0.6",
37
- "pg": "^8.7.3"
38
- }
39
- }
1
+ {
2
+ "name": "@mrnafisia/type-query",
3
+ "version": "1.0.29",
4
+ "description": "mini-orm with full type support for postgres.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "jest ./tests"
13
+ },
14
+ "keywords": [
15
+ "orm",
16
+ "query-builder",
17
+ "postgres",
18
+ "sql",
19
+ "type-safe"
20
+ ],
21
+ "repository": "https://github.com/MRNafisiA/type-query.git",
22
+ "author": "MRNafisiA <mnafisiasl@gmail.com>",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/jest": "^28.1.0",
26
+ "@types/lodash": "^4.14.182",
27
+ "@types/node": "^17.0.39",
28
+ "@types/pg": "^8.6.5",
29
+ "jest": "^28.1.0",
30
+ "ts-jest": "^28.0.4",
31
+ "typescript": "^4.7.2"
32
+ },
33
+ "dependencies": {
34
+ "decimal.js": "^10.3.1",
35
+ "lodash": "^4.17.21",
36
+ "never-catch": "^1.0.6",
37
+ "pg": "^8.7.3"
38
+ }
39
+ }