pqb 0.9.1 → 0.9.2
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.
- package/CHANGELOG.md +6 -0
- package/dist/index.esm.js +229 -227
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +229 -227
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/code.ts +2 -1
- package/src/columnSchema/columnType.ts +10 -2
- package/src/columnSchema/dateTime.test.ts +10 -2
- package/src/columnSchema/dateTime.ts +16 -14
package/dist/index.js
CHANGED
|
@@ -4,170 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var pg = require('pg');
|
|
6
6
|
|
|
7
|
-
var __defProp$r = Object.defineProperty;
|
|
8
|
-
var __defProps$k = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDescs$k = Object.getOwnPropertyDescriptors;
|
|
10
|
-
var __getOwnPropSymbols$s = Object.getOwnPropertySymbols;
|
|
11
|
-
var __hasOwnProp$s = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum$s = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp$r = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues$r = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp$s.call(b, prop))
|
|
17
|
-
__defNormalProp$r(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols$s)
|
|
19
|
-
for (var prop of __getOwnPropSymbols$s(b)) {
|
|
20
|
-
if (__propIsEnum$s.call(b, prop))
|
|
21
|
-
__defNormalProp$r(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps$k = (a, b) => __defProps$k(a, __getOwnPropDescs$k(b));
|
|
26
|
-
const addColumnData = (q, key, value) => {
|
|
27
|
-
const cloned = Object.create(q);
|
|
28
|
-
cloned.data = __spreadProps$k(__spreadValues$r({}, q.data), { [key]: value });
|
|
29
|
-
return cloned;
|
|
30
|
-
};
|
|
31
|
-
const pushColumnData = (q, key, value) => {
|
|
32
|
-
const arr = q.data[key];
|
|
33
|
-
return addColumnData(
|
|
34
|
-
q,
|
|
35
|
-
key,
|
|
36
|
-
arr ? [...arr, value] : [value]
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
const instantiateColumn = (klass, params) => {
|
|
40
|
-
const column = new klass();
|
|
41
|
-
Object.assign(column.data, params);
|
|
42
|
-
return column;
|
|
43
|
-
};
|
|
44
|
-
class ColumnType {
|
|
45
|
-
constructor() {
|
|
46
|
-
this.data = {};
|
|
47
|
-
this.isPrimaryKey = false;
|
|
48
|
-
this.isHidden = false;
|
|
49
|
-
this.hasDefault = false;
|
|
50
|
-
this.chain = [];
|
|
51
|
-
}
|
|
52
|
-
primaryKey() {
|
|
53
|
-
const cloned = Object.create(this);
|
|
54
|
-
return Object.assign(cloned, { isPrimaryKey: true });
|
|
55
|
-
}
|
|
56
|
-
foreignKey(fnOrTable, column, options = {}) {
|
|
57
|
-
const item = typeof fnOrTable === "string" ? __spreadValues$r({ table: fnOrTable, columns: [column] }, options) : __spreadValues$r({ fn: fnOrTable, columns: [column] }, options);
|
|
58
|
-
return pushColumnData(this, "foreignKeys", item);
|
|
59
|
-
}
|
|
60
|
-
hidden() {
|
|
61
|
-
return Object.assign(Object.create(this), { isHidden: true });
|
|
62
|
-
}
|
|
63
|
-
nullable() {
|
|
64
|
-
return addColumnData(
|
|
65
|
-
this,
|
|
66
|
-
"isNullable",
|
|
67
|
-
true
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
encode(fn) {
|
|
71
|
-
return Object.assign(Object.create(this), {
|
|
72
|
-
encodeFn: fn
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
parse(fn) {
|
|
76
|
-
return Object.assign(Object.create(this), {
|
|
77
|
-
parseFn: fn,
|
|
78
|
-
parseItem: fn
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
as(column) {
|
|
82
|
-
return addColumnData(this, "as", column);
|
|
83
|
-
}
|
|
84
|
-
toSQL() {
|
|
85
|
-
return this.dataType;
|
|
86
|
-
}
|
|
87
|
-
default(value) {
|
|
88
|
-
return addColumnData(this, "default", value);
|
|
89
|
-
}
|
|
90
|
-
index(options = {}) {
|
|
91
|
-
return pushColumnData(this, "indexes", options);
|
|
92
|
-
}
|
|
93
|
-
unique(options = {}) {
|
|
94
|
-
return pushColumnData(this, "indexes", __spreadProps$k(__spreadValues$r({}, options), { unique: true }));
|
|
95
|
-
}
|
|
96
|
-
comment(comment) {
|
|
97
|
-
return addColumnData(this, "comment", comment);
|
|
98
|
-
}
|
|
99
|
-
validationDefault(value) {
|
|
100
|
-
return addColumnData(this, "validationDefault", value);
|
|
101
|
-
}
|
|
102
|
-
compression(compression) {
|
|
103
|
-
return addColumnData(this, "compression", compression);
|
|
104
|
-
}
|
|
105
|
-
collate(collate) {
|
|
106
|
-
return addColumnData(this, "collate", collate);
|
|
107
|
-
}
|
|
108
|
-
modifyQuery(cb) {
|
|
109
|
-
return addColumnData(this, "modifyQuery", cb);
|
|
110
|
-
}
|
|
111
|
-
transform(fn) {
|
|
112
|
-
const cloned = Object.create(this);
|
|
113
|
-
cloned.chain = [...this.chain, ["transform", fn]];
|
|
114
|
-
return cloned;
|
|
115
|
-
}
|
|
116
|
-
to(fn, type) {
|
|
117
|
-
const cloned = Object.create(this);
|
|
118
|
-
cloned.chain = [...this.chain, ["to", fn, type], ...cloned.chain];
|
|
119
|
-
return cloned;
|
|
120
|
-
}
|
|
121
|
-
refine(check) {
|
|
122
|
-
const cloned = Object.create(this);
|
|
123
|
-
cloned.chain = [...this.chain, ["refine", check]];
|
|
124
|
-
return cloned;
|
|
125
|
-
}
|
|
126
|
-
superRefine(check) {
|
|
127
|
-
const cloned = Object.create(this);
|
|
128
|
-
cloned.chain = [...this.chain, ["superRefine", check]];
|
|
129
|
-
return cloned;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const singleQuoteRegex = /'/g;
|
|
134
|
-
const doubleQuoteRegex = /"/g;
|
|
135
|
-
const quoteValue$1 = (value) => {
|
|
136
|
-
const type = typeof value;
|
|
137
|
-
if (type === "number")
|
|
138
|
-
return String(value);
|
|
139
|
-
else if (type === "string")
|
|
140
|
-
return `"${value.replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
|
|
141
|
-
else if (type === "boolean")
|
|
142
|
-
return value ? "true" : "false";
|
|
143
|
-
else if (value instanceof Date)
|
|
144
|
-
return `"${value.toISOString()}"`;
|
|
145
|
-
else if (Array.isArray(value))
|
|
146
|
-
return quoteArray(value);
|
|
147
|
-
else if (type === null || type === void 0)
|
|
148
|
-
return "NULL";
|
|
149
|
-
else
|
|
150
|
-
return `"${JSON.stringify(value).replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
|
|
151
|
-
};
|
|
152
|
-
const quoteArray = (array) => `'{${array.map(quoteValue$1).join(",")}}'`;
|
|
153
|
-
const quote = (value) => {
|
|
154
|
-
const type = typeof value;
|
|
155
|
-
if (type === "number")
|
|
156
|
-
return `${value}`;
|
|
157
|
-
else if (type === "string")
|
|
158
|
-
return `'${value.replace(singleQuoteRegex, "''")}'`;
|
|
159
|
-
else if (type === "boolean")
|
|
160
|
-
return value ? "true" : "false";
|
|
161
|
-
else if (value instanceof Date)
|
|
162
|
-
return `'${value.toISOString()}'`;
|
|
163
|
-
else if (Array.isArray(value))
|
|
164
|
-
return quoteArray(value);
|
|
165
|
-
else if (value === null || value === void 0)
|
|
166
|
-
return "NULL";
|
|
167
|
-
else
|
|
168
|
-
return `'${JSON.stringify(value).replace(singleQuoteRegex, "''")}'`;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
7
|
const defaultsKey = Symbol("defaults");
|
|
172
8
|
const queryTypeWithLimitOne = {
|
|
173
9
|
one: true,
|
|
@@ -175,6 +11,29 @@ const queryTypeWithLimitOne = {
|
|
|
175
11
|
};
|
|
176
12
|
const isQueryReturnsAll = (q) => !q.query.returnType || q.query.returnType === "all";
|
|
177
13
|
|
|
14
|
+
const q = (sql) => `"${sql}"`;
|
|
15
|
+
const qc = (column, quotedAs) => quotedAs ? `${quotedAs}.${q(column)}` : column;
|
|
16
|
+
const quoteFullColumn = (fullColumn, quotedAs) => {
|
|
17
|
+
const index = fullColumn.indexOf(".");
|
|
18
|
+
if (index !== -1) {
|
|
19
|
+
return `${q(fullColumn.slice(0, index))}.${q(fullColumn.slice(index + 1))}`;
|
|
20
|
+
} else if (quotedAs) {
|
|
21
|
+
return `${quotedAs}.${q(fullColumn)}`;
|
|
22
|
+
} else {
|
|
23
|
+
return q(fullColumn);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const expressionToSql = (expr, values, quotedAs) => {
|
|
27
|
+
return typeof expr === "object" && isRaw(expr) ? getRaw(expr, values) : quoteFullColumn(expr, quotedAs);
|
|
28
|
+
};
|
|
29
|
+
const quoteSchemaAndTable = (schema, table) => {
|
|
30
|
+
return schema ? `${q(schema)}.${q(table)}` : q(table);
|
|
31
|
+
};
|
|
32
|
+
const addValue = (values, value) => {
|
|
33
|
+
values.push(value);
|
|
34
|
+
return `$${values.length}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
178
37
|
const pushDistinctSql = (ctx, distinct, quotedAs) => {
|
|
179
38
|
ctx.sql.push("DISTINCT");
|
|
180
39
|
if (distinct.length) {
|
|
@@ -527,29 +386,29 @@ const pushIn = (ands, prefix, quotedAs, values, arg) => {
|
|
|
527
386
|
);
|
|
528
387
|
};
|
|
529
388
|
|
|
530
|
-
var __defProp$
|
|
531
|
-
var __defProps$
|
|
532
|
-
var __getOwnPropDescs$
|
|
533
|
-
var __getOwnPropSymbols$
|
|
534
|
-
var __hasOwnProp$
|
|
535
|
-
var __propIsEnum$
|
|
536
|
-
var __defNormalProp$
|
|
537
|
-
var __spreadValues$
|
|
389
|
+
var __defProp$r = Object.defineProperty;
|
|
390
|
+
var __defProps$k = Object.defineProperties;
|
|
391
|
+
var __getOwnPropDescs$k = Object.getOwnPropertyDescriptors;
|
|
392
|
+
var __getOwnPropSymbols$s = Object.getOwnPropertySymbols;
|
|
393
|
+
var __hasOwnProp$s = Object.prototype.hasOwnProperty;
|
|
394
|
+
var __propIsEnum$s = Object.prototype.propertyIsEnumerable;
|
|
395
|
+
var __defNormalProp$r = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
396
|
+
var __spreadValues$r = (a, b) => {
|
|
538
397
|
for (var prop in b || (b = {}))
|
|
539
|
-
if (__hasOwnProp$
|
|
540
|
-
__defNormalProp$
|
|
541
|
-
if (__getOwnPropSymbols$
|
|
542
|
-
for (var prop of __getOwnPropSymbols$
|
|
543
|
-
if (__propIsEnum$
|
|
544
|
-
__defNormalProp$
|
|
398
|
+
if (__hasOwnProp$s.call(b, prop))
|
|
399
|
+
__defNormalProp$r(a, prop, b[prop]);
|
|
400
|
+
if (__getOwnPropSymbols$s)
|
|
401
|
+
for (var prop of __getOwnPropSymbols$s(b)) {
|
|
402
|
+
if (__propIsEnum$s.call(b, prop))
|
|
403
|
+
__defNormalProp$r(a, prop, b[prop]);
|
|
545
404
|
}
|
|
546
405
|
return a;
|
|
547
406
|
};
|
|
548
|
-
var __spreadProps$
|
|
407
|
+
var __spreadProps$k = (a, b) => __defProps$k(a, __getOwnPropDescs$k(b));
|
|
549
408
|
const aggregateToSql = (ctx, table, item, quotedAs) => {
|
|
550
409
|
var _a;
|
|
551
410
|
const sql = [`${item.function}(`];
|
|
552
|
-
ctx = __spreadProps$
|
|
411
|
+
ctx = __spreadProps$k(__spreadValues$r({}, ctx), { sql });
|
|
553
412
|
const options = item.options || EMPTY_OBJECT;
|
|
554
413
|
if (options.distinct && !options.withinGroup)
|
|
555
414
|
sql.push("DISTINCT ");
|
|
@@ -646,6 +505,44 @@ class UnhandledTypeError extends PormInternalError {
|
|
|
646
505
|
}
|
|
647
506
|
}
|
|
648
507
|
|
|
508
|
+
const singleQuoteRegex = /'/g;
|
|
509
|
+
const doubleQuoteRegex = /"/g;
|
|
510
|
+
const quoteValue$1 = (value) => {
|
|
511
|
+
const type = typeof value;
|
|
512
|
+
if (type === "number")
|
|
513
|
+
return String(value);
|
|
514
|
+
else if (type === "string")
|
|
515
|
+
return `"${value.replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
|
|
516
|
+
else if (type === "boolean")
|
|
517
|
+
return value ? "true" : "false";
|
|
518
|
+
else if (value instanceof Date)
|
|
519
|
+
return `"${value.toISOString()}"`;
|
|
520
|
+
else if (Array.isArray(value))
|
|
521
|
+
return quoteArray(value);
|
|
522
|
+
else if (type === null || type === void 0)
|
|
523
|
+
return "NULL";
|
|
524
|
+
else
|
|
525
|
+
return `"${JSON.stringify(value).replace(doubleQuoteRegex, '\\"').replace(singleQuoteRegex, "''")}"`;
|
|
526
|
+
};
|
|
527
|
+
const quoteArray = (array) => `'{${array.map(quoteValue$1).join(",")}}'`;
|
|
528
|
+
const quote = (value) => {
|
|
529
|
+
const type = typeof value;
|
|
530
|
+
if (type === "number")
|
|
531
|
+
return `${value}`;
|
|
532
|
+
else if (type === "string")
|
|
533
|
+
return `'${value.replace(singleQuoteRegex, "''")}'`;
|
|
534
|
+
else if (type === "boolean")
|
|
535
|
+
return value ? "true" : "false";
|
|
536
|
+
else if (value instanceof Date)
|
|
537
|
+
return `'${value.toISOString()}'`;
|
|
538
|
+
else if (Array.isArray(value))
|
|
539
|
+
return quoteArray(value);
|
|
540
|
+
else if (value === null || value === void 0)
|
|
541
|
+
return "NULL";
|
|
542
|
+
else
|
|
543
|
+
return `'${JSON.stringify(value).replace(singleQuoteRegex, "''")}'`;
|
|
544
|
+
};
|
|
545
|
+
|
|
649
546
|
const relationQueryKey = Symbol("relationQuery");
|
|
650
547
|
const isRequiredRelationKey = Symbol("isRequiredRelation");
|
|
651
548
|
|
|
@@ -1367,19 +1264,19 @@ const cloneQueryArrays = (q) => {
|
|
|
1367
1264
|
}
|
|
1368
1265
|
};
|
|
1369
1266
|
|
|
1370
|
-
var __defProp$
|
|
1371
|
-
var __getOwnPropSymbols$
|
|
1372
|
-
var __hasOwnProp$
|
|
1373
|
-
var __propIsEnum$
|
|
1374
|
-
var __defNormalProp$
|
|
1375
|
-
var __spreadValues$
|
|
1267
|
+
var __defProp$q = Object.defineProperty;
|
|
1268
|
+
var __getOwnPropSymbols$r = Object.getOwnPropertySymbols;
|
|
1269
|
+
var __hasOwnProp$r = Object.prototype.hasOwnProperty;
|
|
1270
|
+
var __propIsEnum$r = Object.prototype.propertyIsEnumerable;
|
|
1271
|
+
var __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1272
|
+
var __spreadValues$q = (a, b) => {
|
|
1376
1273
|
for (var prop in b || (b = {}))
|
|
1377
|
-
if (__hasOwnProp$
|
|
1378
|
-
__defNormalProp$
|
|
1379
|
-
if (__getOwnPropSymbols$
|
|
1380
|
-
for (var prop of __getOwnPropSymbols$
|
|
1381
|
-
if (__propIsEnum$
|
|
1382
|
-
__defNormalProp$
|
|
1274
|
+
if (__hasOwnProp$r.call(b, prop))
|
|
1275
|
+
__defNormalProp$q(a, prop, b[prop]);
|
|
1276
|
+
if (__getOwnPropSymbols$r)
|
|
1277
|
+
for (var prop of __getOwnPropSymbols$r(b)) {
|
|
1278
|
+
if (__propIsEnum$r.call(b, prop))
|
|
1279
|
+
__defNormalProp$q(a, prop, b[prop]);
|
|
1383
1280
|
}
|
|
1384
1281
|
return a;
|
|
1385
1282
|
};
|
|
@@ -1398,7 +1295,7 @@ const joinTruthy = (...strings) => {
|
|
|
1398
1295
|
return strings.filter((string) => string).join("");
|
|
1399
1296
|
};
|
|
1400
1297
|
const getClonedQueryData = (query) => {
|
|
1401
|
-
const cloned = __spreadValues$
|
|
1298
|
+
const cloned = __spreadValues$q({}, query);
|
|
1402
1299
|
delete cloned[toSqlCacheKey];
|
|
1403
1300
|
cloneQueryArrays(cloned);
|
|
1404
1301
|
return cloned;
|
|
@@ -1479,28 +1376,137 @@ const getQueryParsers = (q) => {
|
|
|
1479
1376
|
return q.query.parsers || q.columnsParsers;
|
|
1480
1377
|
};
|
|
1481
1378
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1379
|
+
var __defProp$p = Object.defineProperty;
|
|
1380
|
+
var __defProps$j = Object.defineProperties;
|
|
1381
|
+
var __getOwnPropDescs$j = Object.getOwnPropertyDescriptors;
|
|
1382
|
+
var __getOwnPropSymbols$q = Object.getOwnPropertySymbols;
|
|
1383
|
+
var __hasOwnProp$q = Object.prototype.hasOwnProperty;
|
|
1384
|
+
var __propIsEnum$q = Object.prototype.propertyIsEnumerable;
|
|
1385
|
+
var __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1386
|
+
var __spreadValues$p = (a, b) => {
|
|
1387
|
+
for (var prop in b || (b = {}))
|
|
1388
|
+
if (__hasOwnProp$q.call(b, prop))
|
|
1389
|
+
__defNormalProp$p(a, prop, b[prop]);
|
|
1390
|
+
if (__getOwnPropSymbols$q)
|
|
1391
|
+
for (var prop of __getOwnPropSymbols$q(b)) {
|
|
1392
|
+
if (__propIsEnum$q.call(b, prop))
|
|
1393
|
+
__defNormalProp$p(a, prop, b[prop]);
|
|
1394
|
+
}
|
|
1395
|
+
return a;
|
|
1493
1396
|
};
|
|
1494
|
-
|
|
1495
|
-
|
|
1397
|
+
var __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
1398
|
+
const addColumnData = (q, key, value) => {
|
|
1399
|
+
const cloned = Object.create(q);
|
|
1400
|
+
cloned.data = __spreadProps$j(__spreadValues$p({}, q.data), { [key]: value });
|
|
1401
|
+
return cloned;
|
|
1496
1402
|
};
|
|
1497
|
-
const
|
|
1498
|
-
|
|
1403
|
+
const pushColumnData = (q, key, value) => {
|
|
1404
|
+
const arr = q.data[key];
|
|
1405
|
+
return addColumnData(
|
|
1406
|
+
q,
|
|
1407
|
+
key,
|
|
1408
|
+
arr ? [...arr, value] : [value]
|
|
1409
|
+
);
|
|
1499
1410
|
};
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
|
|
1411
|
+
const instantiateColumn = (klass, params) => {
|
|
1412
|
+
const column = new klass();
|
|
1413
|
+
let data;
|
|
1414
|
+
if (params.default !== null && params.default !== void 0) {
|
|
1415
|
+
data = __spreadProps$j(__spreadValues$p({}, params), { default: raw(params.default) });
|
|
1416
|
+
} else {
|
|
1417
|
+
data = params;
|
|
1418
|
+
}
|
|
1419
|
+
Object.assign(column.data, data);
|
|
1420
|
+
return column;
|
|
1503
1421
|
};
|
|
1422
|
+
class ColumnType {
|
|
1423
|
+
constructor() {
|
|
1424
|
+
this.data = {};
|
|
1425
|
+
this.isPrimaryKey = false;
|
|
1426
|
+
this.isHidden = false;
|
|
1427
|
+
this.hasDefault = false;
|
|
1428
|
+
this.chain = [];
|
|
1429
|
+
}
|
|
1430
|
+
primaryKey() {
|
|
1431
|
+
const cloned = Object.create(this);
|
|
1432
|
+
return Object.assign(cloned, { isPrimaryKey: true });
|
|
1433
|
+
}
|
|
1434
|
+
foreignKey(fnOrTable, column, options = {}) {
|
|
1435
|
+
const item = typeof fnOrTable === "string" ? __spreadValues$p({ table: fnOrTable, columns: [column] }, options) : __spreadValues$p({ fn: fnOrTable, columns: [column] }, options);
|
|
1436
|
+
return pushColumnData(this, "foreignKeys", item);
|
|
1437
|
+
}
|
|
1438
|
+
hidden() {
|
|
1439
|
+
return Object.assign(Object.create(this), { isHidden: true });
|
|
1440
|
+
}
|
|
1441
|
+
nullable() {
|
|
1442
|
+
return addColumnData(
|
|
1443
|
+
this,
|
|
1444
|
+
"isNullable",
|
|
1445
|
+
true
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
encode(fn) {
|
|
1449
|
+
return Object.assign(Object.create(this), {
|
|
1450
|
+
encodeFn: fn
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
parse(fn) {
|
|
1454
|
+
return Object.assign(Object.create(this), {
|
|
1455
|
+
parseFn: fn,
|
|
1456
|
+
parseItem: fn
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
as(column) {
|
|
1460
|
+
return addColumnData(this, "as", column);
|
|
1461
|
+
}
|
|
1462
|
+
toSQL() {
|
|
1463
|
+
return this.dataType;
|
|
1464
|
+
}
|
|
1465
|
+
default(value) {
|
|
1466
|
+
return addColumnData(this, "default", value);
|
|
1467
|
+
}
|
|
1468
|
+
index(options = {}) {
|
|
1469
|
+
return pushColumnData(this, "indexes", options);
|
|
1470
|
+
}
|
|
1471
|
+
unique(options = {}) {
|
|
1472
|
+
return pushColumnData(this, "indexes", __spreadProps$j(__spreadValues$p({}, options), { unique: true }));
|
|
1473
|
+
}
|
|
1474
|
+
comment(comment) {
|
|
1475
|
+
return addColumnData(this, "comment", comment);
|
|
1476
|
+
}
|
|
1477
|
+
validationDefault(value) {
|
|
1478
|
+
return addColumnData(this, "validationDefault", value);
|
|
1479
|
+
}
|
|
1480
|
+
compression(compression) {
|
|
1481
|
+
return addColumnData(this, "compression", compression);
|
|
1482
|
+
}
|
|
1483
|
+
collate(collate) {
|
|
1484
|
+
return addColumnData(this, "collate", collate);
|
|
1485
|
+
}
|
|
1486
|
+
modifyQuery(cb) {
|
|
1487
|
+
return addColumnData(this, "modifyQuery", cb);
|
|
1488
|
+
}
|
|
1489
|
+
transform(fn) {
|
|
1490
|
+
const cloned = Object.create(this);
|
|
1491
|
+
cloned.chain = [...this.chain, ["transform", fn]];
|
|
1492
|
+
return cloned;
|
|
1493
|
+
}
|
|
1494
|
+
to(fn, type) {
|
|
1495
|
+
const cloned = Object.create(this);
|
|
1496
|
+
cloned.chain = [...this.chain, ["to", fn, type], ...cloned.chain];
|
|
1497
|
+
return cloned;
|
|
1498
|
+
}
|
|
1499
|
+
refine(check) {
|
|
1500
|
+
const cloned = Object.create(this);
|
|
1501
|
+
cloned.chain = [...this.chain, ["refine", check]];
|
|
1502
|
+
return cloned;
|
|
1503
|
+
}
|
|
1504
|
+
superRefine(check) {
|
|
1505
|
+
const cloned = Object.create(this);
|
|
1506
|
+
cloned.chain = [...this.chain, ["superRefine", check]];
|
|
1507
|
+
return cloned;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1504
1510
|
|
|
1505
1511
|
var __defProp$o = Object.defineProperty;
|
|
1506
1512
|
var __defProps$i = Object.defineProperties;
|
|
@@ -1852,18 +1858,21 @@ class DateTimeWithTimeZoneBaseClass extends DateTimeBaseClass {
|
|
|
1852
1858
|
);
|
|
1853
1859
|
}
|
|
1854
1860
|
}
|
|
1861
|
+
const timestampToCode = (self, t) => {
|
|
1862
|
+
const { dateTimePrecision: p } = self.data;
|
|
1863
|
+
return columnCode(
|
|
1864
|
+
self,
|
|
1865
|
+
t,
|
|
1866
|
+
`${t}.${self instanceof TimestampColumn ? "timestamp" : "timestampWithTimeZone"}(${p && p !== 6 ? p : ""})${dateDataToCode(self.data)}`
|
|
1867
|
+
);
|
|
1868
|
+
};
|
|
1855
1869
|
class TimestampColumn extends DateTimeBaseClass {
|
|
1856
1870
|
constructor() {
|
|
1857
1871
|
super(...arguments);
|
|
1858
1872
|
this.dataType = "timestamp";
|
|
1859
1873
|
}
|
|
1860
1874
|
toCode(t) {
|
|
1861
|
-
|
|
1862
|
-
return columnCode(
|
|
1863
|
-
this,
|
|
1864
|
-
t,
|
|
1865
|
-
`${t}.timestamp(${dateTimePrecision || ""})${dateDataToCode(this.data)}`
|
|
1866
|
-
);
|
|
1875
|
+
return timestampToCode(this, t);
|
|
1867
1876
|
}
|
|
1868
1877
|
}
|
|
1869
1878
|
class TimestampWithTimeZoneColumn extends DateTimeWithTimeZoneBaseClass {
|
|
@@ -1873,14 +1882,7 @@ class TimestampWithTimeZoneColumn extends DateTimeWithTimeZoneBaseClass {
|
|
|
1873
1882
|
this.baseDataType = "timestamp";
|
|
1874
1883
|
}
|
|
1875
1884
|
toCode(t) {
|
|
1876
|
-
|
|
1877
|
-
return columnCode(
|
|
1878
|
-
this,
|
|
1879
|
-
t,
|
|
1880
|
-
`${t}.timestampWithTimeZone(${dateTimePrecision || ""})${dateDataToCode(
|
|
1881
|
-
this.data
|
|
1882
|
-
)}`
|
|
1883
|
-
);
|
|
1885
|
+
return timestampToCode(this, t);
|
|
1884
1886
|
}
|
|
1885
1887
|
}
|
|
1886
1888
|
class TimeColumn extends DateTimeBaseClass {
|
|
@@ -2071,6 +2073,8 @@ const indexToCode = (index, t) => {
|
|
|
2071
2073
|
const options = [];
|
|
2072
2074
|
for (const key of optionsKeys) {
|
|
2073
2075
|
const value = index.options[key];
|
|
2076
|
+
if (value === null || value === void 0)
|
|
2077
|
+
continue;
|
|
2074
2078
|
options.push(
|
|
2075
2079
|
`${key}: ${typeof value === "object" ? singleQuoteArray(value) : typeof value === "string" ? singleQuote(value) : value},`
|
|
2076
2080
|
);
|
|
@@ -2182,8 +2186,6 @@ const columnIndexesToCode = (indexes) => {
|
|
|
2182
2186
|
arr.push(`order: ${singleQuote(index.order)},`);
|
|
2183
2187
|
if (index.name)
|
|
2184
2188
|
arr.push(`name: ${singleQuote(index.name)},`);
|
|
2185
|
-
if (index.unique)
|
|
2186
|
-
arr.push(`unique: true,`);
|
|
2187
2189
|
if (index.using)
|
|
2188
2190
|
arr.push(`using: ${singleQuote(index.using)},`);
|
|
2189
2191
|
if (index.include)
|