pqb 0.51.2 → 0.51.4
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/dist/index.d.ts +7 -4
- package/dist/index.js +33 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -878,12 +878,6 @@ const columnCode = (type, ctx, key, code) => {
|
|
|
878
878
|
}
|
|
879
879
|
if (data.explicitSelect) addCode(code, ".select(false)");
|
|
880
880
|
if (data.isNullable) addCode(code, ".nullable()");
|
|
881
|
-
if (data.encode && data.encode !== data.defaultEncode)
|
|
882
|
-
addCode(code, `.encode(${data.encode.toString()})`);
|
|
883
|
-
if (data.parse && data.parse !== data.defaultParse)
|
|
884
|
-
addCode(code, `.parse(${data.parse.toString()})`);
|
|
885
|
-
if (type.data.parseNull)
|
|
886
|
-
addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
|
|
887
881
|
if (data.as) addCode(code, `.as(${data.as.toCode(ctx, key)})`);
|
|
888
882
|
if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
|
|
889
883
|
addCode(
|
|
@@ -941,7 +935,7 @@ const addColumnParserToQuery = (q, key, column) => {
|
|
|
941
935
|
}
|
|
942
936
|
};
|
|
943
937
|
const setColumnDefaultParse = (column, parse) => {
|
|
944
|
-
column.data.parse =
|
|
938
|
+
column.data.parse = parse;
|
|
945
939
|
column._parse = (input) => input === null ? null : parse(input);
|
|
946
940
|
};
|
|
947
941
|
const setColumnParse = (column, fn, outputSchema) => {
|
|
@@ -1641,7 +1635,7 @@ class DateBaseColumn extends ColumnType {
|
|
|
1641
1635
|
this.operators = Operators.date;
|
|
1642
1636
|
this.asNumber = schema.dateAsNumber;
|
|
1643
1637
|
this.asDate = schema.dateAsDate;
|
|
1644
|
-
this.data.encode =
|
|
1638
|
+
this.data.encode = dateTimeEncode;
|
|
1645
1639
|
}
|
|
1646
1640
|
}
|
|
1647
1641
|
class DateColumn extends DateBaseColumn {
|
|
@@ -1785,13 +1779,13 @@ class BooleanColumn extends ColumnType {
|
|
|
1785
1779
|
}
|
|
1786
1780
|
const parseItem = (input) => input[0] === "t";
|
|
1787
1781
|
|
|
1788
|
-
const encode = (x) => x === null ? x : JSON.stringify(x);
|
|
1782
|
+
const encode$1 = (x) => x === null ? x : JSON.stringify(x);
|
|
1789
1783
|
class JSONColumn extends ColumnType {
|
|
1790
1784
|
constructor(schema, inputType) {
|
|
1791
1785
|
super(schema, inputType);
|
|
1792
1786
|
this.dataType = "jsonb";
|
|
1793
1787
|
this.operators = Operators.json;
|
|
1794
|
-
this.data.encode =
|
|
1788
|
+
this.data.encode = encode$1;
|
|
1795
1789
|
this.data.parseItem = JSON.parse;
|
|
1796
1790
|
}
|
|
1797
1791
|
toCode(ctx, key) {
|
|
@@ -2404,7 +2398,7 @@ class ArrayColumn extends ColumnType {
|
|
|
2404
2398
|
this.dataType = "array";
|
|
2405
2399
|
this.operators = Operators.array;
|
|
2406
2400
|
item.data.isNullable = true;
|
|
2407
|
-
setColumnDefaultParse(this, (input) => parse.call(this, input));
|
|
2401
|
+
setColumnDefaultParse(this, (input) => parse$1.call(this, input));
|
|
2408
2402
|
this.data.item = item instanceof ArrayColumn ? item.data.item : item;
|
|
2409
2403
|
this.data.name = item.data.name;
|
|
2410
2404
|
this.data.arrayDims = item instanceof ArrayColumn ? item.data.arrayDims + 1 : 1;
|
|
@@ -2429,7 +2423,7 @@ class ArrayColumn extends ColumnType {
|
|
|
2429
2423
|
return columnCode(this, ctx, key, code);
|
|
2430
2424
|
}
|
|
2431
2425
|
}
|
|
2432
|
-
const parse = function(source) {
|
|
2426
|
+
const parse$1 = function(source) {
|
|
2433
2427
|
if (typeof source !== "string") return source;
|
|
2434
2428
|
const entries = [];
|
|
2435
2429
|
parsePostgresArray(source, entries, this.data.item.data.parseItem);
|
|
@@ -2692,14 +2686,10 @@ const defaultSchemaConfig = {
|
|
|
2692
2686
|
return this;
|
|
2693
2687
|
},
|
|
2694
2688
|
dateAsNumber() {
|
|
2695
|
-
|
|
2696
|
-
c.data.defaultParse = Date.parse;
|
|
2697
|
-
return c;
|
|
2689
|
+
return this.parse(Date.parse);
|
|
2698
2690
|
},
|
|
2699
2691
|
dateAsDate() {
|
|
2700
|
-
|
|
2701
|
-
c.data.defaultParse = parseDateToDate;
|
|
2702
|
-
return c;
|
|
2692
|
+
return this.parse(parseDateToDate);
|
|
2703
2693
|
},
|
|
2704
2694
|
enum(dataType, type) {
|
|
2705
2695
|
return new EnumColumn(defaultSchemaConfig, dataType, type, void 0);
|
|
@@ -4230,9 +4220,6 @@ const setParserForSelectedString = (query, arg, as, columnAs, columnAlias) => {
|
|
|
4230
4220
|
return arg;
|
|
4231
4221
|
};
|
|
4232
4222
|
const selectColumn = (query, q, key, columnAs, columnAlias) => {
|
|
4233
|
-
if (columnAlias === "pluck") {
|
|
4234
|
-
throw new Error("?");
|
|
4235
|
-
}
|
|
4236
4223
|
if (columnAs && q.parsers) {
|
|
4237
4224
|
const parser = q.parsers[key];
|
|
4238
4225
|
if (parser) setObjectValueImmutable(q, "parsers", columnAs, parser);
|
|
@@ -4269,7 +4256,9 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
4269
4256
|
result = {};
|
|
4270
4257
|
for (const key in shape) {
|
|
4271
4258
|
const column = shape[key];
|
|
4272
|
-
|
|
4259
|
+
if (!column.data.explicitSelect) {
|
|
4260
|
+
result[key] = column.data.name ? setColumnData(column, "name", void 0) : column;
|
|
4261
|
+
}
|
|
4273
4262
|
}
|
|
4274
4263
|
} else {
|
|
4275
4264
|
result = shape;
|
|
@@ -4329,10 +4318,12 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
|
|
|
4329
4318
|
}
|
|
4330
4319
|
} else if (arg === "*") {
|
|
4331
4320
|
for (const key2 in shape) {
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4321
|
+
if (!shape[key2].data.explicitSelect) {
|
|
4322
|
+
result[key2] = mapSubSelectColumn(
|
|
4323
|
+
shape[key2],
|
|
4324
|
+
isSubQuery
|
|
4325
|
+
);
|
|
4326
|
+
}
|
|
4336
4327
|
}
|
|
4337
4328
|
} else {
|
|
4338
4329
|
result[key || arg] = mapSubSelectColumn(
|
|
@@ -4861,7 +4852,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4861
4852
|
if (hookSelect) {
|
|
4862
4853
|
selected ?? (selected = {});
|
|
4863
4854
|
selectedAs ?? (selectedAs = {});
|
|
4864
|
-
for (const key in query.
|
|
4855
|
+
for (const key in query.selectAllShape) {
|
|
4865
4856
|
selected[key] = quotedAs;
|
|
4866
4857
|
selectedAs[key] = key;
|
|
4867
4858
|
}
|
|
@@ -5010,7 +5001,7 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
|
5010
5001
|
}
|
|
5011
5002
|
const selectAllSql = (query, quotedAs, jsonList) => {
|
|
5012
5003
|
if (jsonList) {
|
|
5013
|
-
Object.assign(jsonList, query.
|
|
5004
|
+
Object.assign(jsonList, query.selectAllShape);
|
|
5014
5005
|
}
|
|
5015
5006
|
return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
|
|
5016
5007
|
};
|
|
@@ -7183,11 +7174,7 @@ class DomainColumn extends CustomTypeColumn {
|
|
|
7183
7174
|
}
|
|
7184
7175
|
|
|
7185
7176
|
const defaultSrid = 4326;
|
|
7186
|
-
const
|
|
7187
|
-
srid = defaultSrid,
|
|
7188
|
-
lon,
|
|
7189
|
-
lat
|
|
7190
|
-
}) => {
|
|
7177
|
+
const encode = ({ srid = defaultSrid, lon, lat }) => {
|
|
7191
7178
|
const arr = new Uint8Array(25);
|
|
7192
7179
|
const view = new DataView(arr.buffer);
|
|
7193
7180
|
view.setInt8(0, 1);
|
|
@@ -7203,8 +7190,8 @@ class PostgisGeographyPointColumn extends ColumnType {
|
|
|
7203
7190
|
super(schema, schema.geographyPointSchema());
|
|
7204
7191
|
this.dataType = "geography(Point)";
|
|
7205
7192
|
this.operators = Operators.any;
|
|
7206
|
-
setColumnDefaultParse(this,
|
|
7207
|
-
this.data.encode =
|
|
7193
|
+
setColumnDefaultParse(this, parse);
|
|
7194
|
+
this.data.encode = encode;
|
|
7208
7195
|
}
|
|
7209
7196
|
static isDefaultPoint(typmod) {
|
|
7210
7197
|
return typmodType(typmod) === "Point" && typmodSrid(typmod) === defaultSrid;
|
|
@@ -7213,8 +7200,9 @@ class PostgisGeographyPointColumn extends ColumnType {
|
|
|
7213
7200
|
return columnCode(this, ctx, key, `geography.point()`);
|
|
7214
7201
|
}
|
|
7215
7202
|
}
|
|
7216
|
-
|
|
7217
|
-
|
|
7203
|
+
// It is used by test-factory
|
|
7204
|
+
PostgisGeographyPointColumn.encode = encode;
|
|
7205
|
+
const parse = (input) => {
|
|
7218
7206
|
const bytes = new Uint8Array(20);
|
|
7219
7207
|
for (let i = 0; i < 40; i += 2) {
|
|
7220
7208
|
bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
|
|
@@ -11810,7 +11798,7 @@ class ExpressionMethods {
|
|
|
11810
11798
|
column(name) {
|
|
11811
11799
|
const column = this.shape[name];
|
|
11812
11800
|
return new ColumnRefExpression(
|
|
11813
|
-
column,
|
|
11801
|
+
column || UnknownColumn.instance,
|
|
11814
11802
|
name
|
|
11815
11803
|
);
|
|
11816
11804
|
}
|
|
@@ -11852,12 +11840,12 @@ class ExpressionMethods {
|
|
|
11852
11840
|
if (table === as) {
|
|
11853
11841
|
column = shape[col];
|
|
11854
11842
|
} else {
|
|
11855
|
-
column = q.q.joinedShapes[table][col];
|
|
11843
|
+
column = q.q.joinedShapes?.[table][col];
|
|
11856
11844
|
}
|
|
11857
11845
|
} else {
|
|
11858
11846
|
column = shape[arg];
|
|
11859
11847
|
}
|
|
11860
|
-
return new RefExpression(column, q, arg);
|
|
11848
|
+
return new RefExpression(column || UnknownColumn.instance, q, arg);
|
|
11861
11849
|
}
|
|
11862
11850
|
val(value) {
|
|
11863
11851
|
return new ValExpression(value);
|
|
@@ -12737,7 +12725,7 @@ const parseIndexOrExclude = (item) => {
|
|
|
12737
12725
|
|
|
12738
12726
|
const anyShape = {};
|
|
12739
12727
|
class Db extends QueryMethods {
|
|
12740
|
-
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData =
|
|
12728
|
+
constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = {}) {
|
|
12741
12729
|
super();
|
|
12742
12730
|
this.adapter = adapter;
|
|
12743
12731
|
this.queryBuilder = queryBuilder;
|
|
@@ -12831,26 +12819,21 @@ class Db extends QueryMethods {
|
|
|
12831
12819
|
);
|
|
12832
12820
|
this.columns = columns;
|
|
12833
12821
|
if (options.computed) applyComputedColumns(this, options.computed);
|
|
12834
|
-
const selectableShape = this.q.selectableShape = {};
|
|
12835
12822
|
if (prepareSelectAll) {
|
|
12823
|
+
const selectAllShape = this.q.selectAllShape = {};
|
|
12836
12824
|
const list = [];
|
|
12837
12825
|
for (const key in shape) {
|
|
12838
12826
|
const column = shape[key];
|
|
12839
|
-
if (!column.data.explicitSelect
|
|
12827
|
+
if (!column.data.explicitSelect) {
|
|
12840
12828
|
list.push(
|
|
12841
12829
|
column.data.name ? `"${column.data.name}" "${key}"` : `"${key}"`
|
|
12842
12830
|
);
|
|
12843
|
-
|
|
12831
|
+
selectAllShape[key] = column;
|
|
12844
12832
|
}
|
|
12845
12833
|
}
|
|
12846
12834
|
this.q.selectAllColumns = list;
|
|
12847
12835
|
} else {
|
|
12848
|
-
|
|
12849
|
-
const column = shape[key];
|
|
12850
|
-
if (column instanceof VirtualColumn) {
|
|
12851
|
-
selectableShape[key] = column;
|
|
12852
|
-
}
|
|
12853
|
-
}
|
|
12836
|
+
this.q.selectAllShape = shape;
|
|
12854
12837
|
}
|
|
12855
12838
|
if (modifyQuery) {
|
|
12856
12839
|
for (const cb of modifyQuery) {
|