pqb 0.40.5 → 0.40.7
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 +26 -4
- package/dist/index.js +119 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -809,7 +809,7 @@ const columnCode = (type, ctx, key, code, data = type.data, skip) => {
|
|
|
809
809
|
addCode(code, ".nullable()");
|
|
810
810
|
if (type.encodeFn && type.encodeFn !== (skip == null ? void 0 : skip.encodeFn))
|
|
811
811
|
addCode(code, `.encode(${type.encodeFn.toString()})`);
|
|
812
|
-
if (type.parseFn && !("hideFromCode" in type.parseFn))
|
|
812
|
+
if (type.parseFn && type.parseFn !== (skip == null ? void 0 : skip.parseFn) && !("hideFromCode" in type.parseFn))
|
|
813
813
|
addCode(code, `.parse(${type.parseFn.toString()})`);
|
|
814
814
|
if (data.as)
|
|
815
815
|
addCode(code, `.as(${data.as.toCode(ctx, key)})`);
|
|
@@ -1262,7 +1262,7 @@ class CircleColumn extends ColumnType {
|
|
|
1262
1262
|
}
|
|
1263
1263
|
class MoneyColumn extends ColumnType {
|
|
1264
1264
|
constructor(schema) {
|
|
1265
|
-
super(schema, schema.
|
|
1265
|
+
super(schema, schema.number());
|
|
1266
1266
|
this.dataType = "money";
|
|
1267
1267
|
this.operators = Operators.number;
|
|
1268
1268
|
this.parseFn = Object.assign(
|
|
@@ -1472,6 +1472,7 @@ class CitextColumn extends TextBaseColumn {
|
|
|
1472
1472
|
constructor(schema) {
|
|
1473
1473
|
super(schema, schema.stringSchema());
|
|
1474
1474
|
this.dataType = "citext";
|
|
1475
|
+
this.data.extension = "citext";
|
|
1475
1476
|
}
|
|
1476
1477
|
toCode(ctx, key) {
|
|
1477
1478
|
return textColumnToCode(this, ctx, key);
|
|
@@ -3177,7 +3178,8 @@ const defaultSchemaConfig = {
|
|
|
3177
3178
|
citext: () => new CitextColumn(defaultSchemaConfig),
|
|
3178
3179
|
date: () => new DateColumn(defaultSchemaConfig),
|
|
3179
3180
|
timestampNoTZ: (precision) => new TimestampColumn(defaultSchemaConfig, precision),
|
|
3180
|
-
timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision)
|
|
3181
|
+
timestamp: (precision) => new TimestampTZColumn(defaultSchemaConfig, precision),
|
|
3182
|
+
geographyPointSchema: noop
|
|
3181
3183
|
};
|
|
3182
3184
|
|
|
3183
3185
|
const escape = (value, migration, nested) => {
|
|
@@ -3191,7 +3193,7 @@ const escape = (value, migration, nested) => {
|
|
|
3191
3193
|
else if (value instanceof Date)
|
|
3192
3194
|
return `'${value.toISOString()}'`;
|
|
3193
3195
|
else if (Array.isArray(value))
|
|
3194
|
-
return migration && nested && !value.length ? "" : (migration ? "{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? "}" : "]");
|
|
3196
|
+
return migration && nested && !value.length ? "" : (migration ? nested ? "{" : "'{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? nested ? "}" : "}'" : "]");
|
|
3195
3197
|
else if (value === null || value === void 0)
|
|
3196
3198
|
return "NULL";
|
|
3197
3199
|
else
|
|
@@ -6142,7 +6144,7 @@ const joinSubQuery = (q, sub) => {
|
|
|
6142
6144
|
};
|
|
6143
6145
|
|
|
6144
6146
|
class CustomTypeColumn extends ColumnType {
|
|
6145
|
-
constructor(schema, dataType) {
|
|
6147
|
+
constructor(schema, dataType, extension) {
|
|
6146
6148
|
super(
|
|
6147
6149
|
schema,
|
|
6148
6150
|
schema.unknown(),
|
|
@@ -6152,6 +6154,7 @@ class CustomTypeColumn extends ColumnType {
|
|
|
6152
6154
|
this.dataType = dataType;
|
|
6153
6155
|
this.operators = Operators.any;
|
|
6154
6156
|
this.data.isOfCustomType = true;
|
|
6157
|
+
this.data.extension = extension;
|
|
6155
6158
|
}
|
|
6156
6159
|
toCode(ctx, key) {
|
|
6157
6160
|
return columnCode(this, ctx, key, `type(${singleQuote(this.dataType)})`);
|
|
@@ -6174,6 +6177,108 @@ class DomainColumn extends CustomTypeColumn {
|
|
|
6174
6177
|
}
|
|
6175
6178
|
}
|
|
6176
6179
|
|
|
6180
|
+
const defaultSrid = 4326;
|
|
6181
|
+
class PostgisGeographyPointColumn extends ColumnType {
|
|
6182
|
+
constructor(schema) {
|
|
6183
|
+
super(schema, schema.geographyPointSchema());
|
|
6184
|
+
this.dataType = "geography(Point)";
|
|
6185
|
+
this.operators = Operators.any;
|
|
6186
|
+
}
|
|
6187
|
+
static isDefaultPoint(typmod) {
|
|
6188
|
+
return typmodType(typmod) === "Point" && typmodSrid(typmod) === defaultSrid;
|
|
6189
|
+
}
|
|
6190
|
+
parseFn(input) {
|
|
6191
|
+
if (!input)
|
|
6192
|
+
return null;
|
|
6193
|
+
const bytes = new Uint8Array(20);
|
|
6194
|
+
for (let i = 0; i < 40; i += 2) {
|
|
6195
|
+
bytes[i / 2] = parseInt(input.slice(10 + i, 12 + i), 16);
|
|
6196
|
+
}
|
|
6197
|
+
const view = new DataView(bytes.buffer);
|
|
6198
|
+
const srid = view.getUint32(0, true);
|
|
6199
|
+
const lon = view.getFloat64(4, true);
|
|
6200
|
+
const lat = view.getFloat64(12, true);
|
|
6201
|
+
return srid === defaultSrid ? { lon, lat } : {
|
|
6202
|
+
lon,
|
|
6203
|
+
lat,
|
|
6204
|
+
srid
|
|
6205
|
+
};
|
|
6206
|
+
}
|
|
6207
|
+
encodeFn({ srid = defaultSrid, lon, lat }) {
|
|
6208
|
+
const arr = new Uint8Array(25);
|
|
6209
|
+
const view = new DataView(arr.buffer);
|
|
6210
|
+
view.setInt8(0, 1);
|
|
6211
|
+
view.setInt8(1, 1);
|
|
6212
|
+
view.setInt8(4, 32);
|
|
6213
|
+
view.setUint32(5, srid, true);
|
|
6214
|
+
view.setFloat64(9, lon, true);
|
|
6215
|
+
view.setFloat64(17, lat, true);
|
|
6216
|
+
return uint8ArrToHex(arr);
|
|
6217
|
+
}
|
|
6218
|
+
toCode(ctx, key) {
|
|
6219
|
+
return columnCode(this, ctx, key, `geography.point()`, this.data, {
|
|
6220
|
+
encodeFn: PostgisGeographyPointColumn.prototype.encodeFn,
|
|
6221
|
+
parseFn: PostgisGeographyPointColumn.prototype.parseFn
|
|
6222
|
+
});
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
const typmodGetType = (typmod) => (typmod & 252) >> 2;
|
|
6226
|
+
const lwtypeName = (type) => [
|
|
6227
|
+
"Unknown",
|
|
6228
|
+
"Point",
|
|
6229
|
+
"LineString",
|
|
6230
|
+
"Polygon",
|
|
6231
|
+
"MultiPoint",
|
|
6232
|
+
"MultiLineString",
|
|
6233
|
+
"MultiPolygon",
|
|
6234
|
+
"GeometryCollection",
|
|
6235
|
+
"CircularString",
|
|
6236
|
+
"CompoundCurve",
|
|
6237
|
+
"CurvePolygon",
|
|
6238
|
+
"MultiCurve",
|
|
6239
|
+
"MultiSurface",
|
|
6240
|
+
"PolyhedralSurface",
|
|
6241
|
+
"Triangle",
|
|
6242
|
+
"Tin"
|
|
6243
|
+
][type] || "Invalid type";
|
|
6244
|
+
const typmodGetZ = (typmod) => (typmod & 2) >> 1;
|
|
6245
|
+
const typmodGetM = (typmod) => typmod & 1;
|
|
6246
|
+
const typmodType = (typmod) => {
|
|
6247
|
+
const type = typmodGetType(typmod);
|
|
6248
|
+
let s = "";
|
|
6249
|
+
if (typmod < 0 || type === 0) {
|
|
6250
|
+
s += "Geometry";
|
|
6251
|
+
} else {
|
|
6252
|
+
s += lwtypeName(type);
|
|
6253
|
+
}
|
|
6254
|
+
if (typmod >= 0 && typmodGetZ(typmod))
|
|
6255
|
+
s += "Z";
|
|
6256
|
+
if (typmod >= 0 && typmodGetM(typmod))
|
|
6257
|
+
s += "M";
|
|
6258
|
+
return s;
|
|
6259
|
+
};
|
|
6260
|
+
const typmodSrid = (typmod) => {
|
|
6261
|
+
return typmod < 0 ? 0 : (typmod & 268435200) - (typmod & 268435456) >> 8;
|
|
6262
|
+
};
|
|
6263
|
+
const postgisTypmodToSql = (typmod) => {
|
|
6264
|
+
const srid = typmodSrid(typmod);
|
|
6265
|
+
return typmodType(typmod) + (srid === defaultSrid ? "" : ", " + srid);
|
|
6266
|
+
};
|
|
6267
|
+
let byteToHex;
|
|
6268
|
+
function uint8ArrToHex(arr) {
|
|
6269
|
+
if (!byteToHex) {
|
|
6270
|
+
byteToHex = [];
|
|
6271
|
+
for (let n = 0; n <= 255; ++n) {
|
|
6272
|
+
const hexOctet = n.toString(16).padStart(2, "0");
|
|
6273
|
+
byteToHex.push(hexOctet);
|
|
6274
|
+
}
|
|
6275
|
+
}
|
|
6276
|
+
const hexOctets = [];
|
|
6277
|
+
for (let i = 0; i < arr.length; ++i)
|
|
6278
|
+
hexOctets.push(byteToHex[arr[i]]);
|
|
6279
|
+
return hexOctets.join("");
|
|
6280
|
+
}
|
|
6281
|
+
|
|
6177
6282
|
var __defProp$8 = Object.defineProperty;
|
|
6178
6283
|
var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
|
|
6179
6284
|
var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
|
|
@@ -6302,6 +6407,11 @@ const makeColumnTypes = (schema) => {
|
|
|
6302
6407
|
},
|
|
6303
6408
|
domain(dataType) {
|
|
6304
6409
|
return new DomainColumn(schema, dataType);
|
|
6410
|
+
},
|
|
6411
|
+
geography: {
|
|
6412
|
+
point() {
|
|
6413
|
+
return new PostgisGeographyPointColumn(schema);
|
|
6414
|
+
}
|
|
6305
6415
|
}
|
|
6306
6416
|
}, makeTimestampsHelpers(makeRegexToFindInSql));
|
|
6307
6417
|
};
|
|
@@ -6383,7 +6493,8 @@ const makeColumnsByType = (schema) => {
|
|
|
6383
6493
|
serial: t.serial,
|
|
6384
6494
|
bigserial: t.bigSerial,
|
|
6385
6495
|
// requires citext extension
|
|
6386
|
-
citext: t.citext
|
|
6496
|
+
citext: t.citext,
|
|
6497
|
+
geographyDefaultPoint: t.geography.point
|
|
6387
6498
|
};
|
|
6388
6499
|
};
|
|
6389
6500
|
|
|
@@ -12992,5 +13103,5 @@ function copyTableData(query, arg) {
|
|
|
12992
13103
|
return q;
|
|
12993
13104
|
}
|
|
12994
13105
|
|
|
12995
|
-
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
13106
|
+
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12996
13107
|
//# sourceMappingURL=index.mjs.map
|