pqb 0.38.4 → 0.38.6
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 +18 -11
- package/dist/index.js +58 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1095,9 +1095,9 @@ class NumberAsStringBaseColumn extends ColumnType {
|
|
|
1095
1095
|
this.operators = Operators.number;
|
|
1096
1096
|
}
|
|
1097
1097
|
}
|
|
1098
|
-
class DecimalColumn extends
|
|
1098
|
+
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
1099
1099
|
constructor(schema, numericPrecision, numericScale) {
|
|
1100
|
-
super(schema
|
|
1100
|
+
super(schema);
|
|
1101
1101
|
this.operators = Operators.number;
|
|
1102
1102
|
this.dataType = "numeric";
|
|
1103
1103
|
this.data.numericPrecision = numericPrecision;
|
|
@@ -3276,18 +3276,7 @@ class Transaction {
|
|
|
3276
3276
|
const result = await this.q.adapter.transaction(sql, callback);
|
|
3277
3277
|
if (log)
|
|
3278
3278
|
log.afterQuery(commitSql$1, logData);
|
|
3279
|
-
|
|
3280
|
-
if (afterCommit) {
|
|
3281
|
-
const promises = [];
|
|
3282
|
-
for (let i = 0, len = afterCommit.length; i < len; i += 2) {
|
|
3283
|
-
const q = afterCommit[i];
|
|
3284
|
-
const result2 = afterCommit[i + 1];
|
|
3285
|
-
for (const fn2 of afterCommit[i + 2]) {
|
|
3286
|
-
promises.push(fn2(result2, q));
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
await Promise.all(promises);
|
|
3290
|
-
}
|
|
3279
|
+
await runAfterCommit(trx.afterCommit);
|
|
3291
3280
|
return result;
|
|
3292
3281
|
} catch (err) {
|
|
3293
3282
|
if (log)
|
|
@@ -3319,6 +3308,11 @@ class Transaction {
|
|
|
3319
3308
|
await adapter.query(sql);
|
|
3320
3309
|
if (log)
|
|
3321
3310
|
log.afterQuery(sql, logData);
|
|
3311
|
+
if (transactionId === trx.testTransactionCount) {
|
|
3312
|
+
await runAfterCommit(
|
|
3313
|
+
trx.afterCommit
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
3322
3316
|
return result;
|
|
3323
3317
|
} finally {
|
|
3324
3318
|
trx.transactionId = transactionId - 1;
|
|
@@ -3326,6 +3320,19 @@ class Transaction {
|
|
|
3326
3320
|
}
|
|
3327
3321
|
}
|
|
3328
3322
|
}
|
|
3323
|
+
const runAfterCommit = async (afterCommit) => {
|
|
3324
|
+
if (afterCommit) {
|
|
3325
|
+
const promises = [];
|
|
3326
|
+
for (let i = 0, len = afterCommit.length; i < len; i += 3) {
|
|
3327
|
+
const result = afterCommit[i];
|
|
3328
|
+
const q = afterCommit[i + 1];
|
|
3329
|
+
for (const fn of afterCommit[i + 2]) {
|
|
3330
|
+
promises.push(fn(result, q));
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
await Promise.all(promises);
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3329
3336
|
|
|
3330
3337
|
const applyBatchTransforms = (query, batches) => {
|
|
3331
3338
|
if (query.transform) {
|
|
@@ -4562,25 +4569,29 @@ class SelectItemExpression extends Expression {
|
|
|
4562
4569
|
}
|
|
4563
4570
|
}
|
|
4564
4571
|
|
|
4565
|
-
const
|
|
4572
|
+
const _getSelectableColumn = (q, arg) => {
|
|
4566
4573
|
var _a, _b;
|
|
4574
|
+
let type = q.q.shape[arg];
|
|
4575
|
+
if (!type) {
|
|
4576
|
+
const index = arg.indexOf(".");
|
|
4577
|
+
if (index !== -1) {
|
|
4578
|
+
const table = arg.slice(0, index);
|
|
4579
|
+
const column = arg.slice(index + 1);
|
|
4580
|
+
if (table === (q.q.as || q.table)) {
|
|
4581
|
+
type = q.shape[column];
|
|
4582
|
+
} else {
|
|
4583
|
+
type = (_b = (_a = q.q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
return type;
|
|
4588
|
+
};
|
|
4589
|
+
const _get = (query, returnType, arg) => {
|
|
4567
4590
|
const q = query.q;
|
|
4568
4591
|
q.returnType = returnType;
|
|
4569
4592
|
let type;
|
|
4570
4593
|
if (typeof arg === "string") {
|
|
4571
|
-
type =
|
|
4572
|
-
if (!type) {
|
|
4573
|
-
const index = arg.indexOf(".");
|
|
4574
|
-
if (index !== -1) {
|
|
4575
|
-
const table = arg.slice(0, index);
|
|
4576
|
-
const column = arg.slice(index + 1);
|
|
4577
|
-
if (table === (q.as || query.table)) {
|
|
4578
|
-
type = q.shape[column];
|
|
4579
|
-
} else {
|
|
4580
|
-
type = (_b = (_a = q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
|
|
4581
|
-
}
|
|
4582
|
-
}
|
|
4583
|
-
}
|
|
4594
|
+
type = _getSelectableColumn(query, arg);
|
|
4584
4595
|
q.getColumn = type;
|
|
4585
4596
|
const selected = setParserForSelectedString(
|
|
4586
4597
|
query,
|
|
@@ -6543,6 +6554,13 @@ const nullableInt = new IntegerColumn(defaultSchemaConfig);
|
|
|
6543
6554
|
nullableInt.parseItem = nullableInt.parseFn = (input) => input === null ? null : parseInt(input);
|
|
6544
6555
|
const nullableFloat = new RealColumn(defaultSchemaConfig);
|
|
6545
6556
|
nullableFloat.parseItem = nullableFloat.parseFn = (input) => input === null ? null : parseFloat(input);
|
|
6557
|
+
const stringAsNumber = new NumberAsStringBaseColumn(
|
|
6558
|
+
defaultSchemaConfig
|
|
6559
|
+
);
|
|
6560
|
+
const numericResultColumn = (q, arg) => {
|
|
6561
|
+
const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
|
|
6562
|
+
return type instanceof NumberBaseColumn ? nullableFloat : stringAsNumber;
|
|
6563
|
+
};
|
|
6546
6564
|
class AggregateMethods {
|
|
6547
6565
|
/**
|
|
6548
6566
|
* Use `exists()` to check if there is at least one record-matching condition.
|
|
@@ -6613,7 +6631,7 @@ class AggregateMethods {
|
|
|
6613
6631
|
min(arg, options) {
|
|
6614
6632
|
return makeFnExpression(
|
|
6615
6633
|
this,
|
|
6616
|
-
|
|
6634
|
+
numericResultColumn(this, arg),
|
|
6617
6635
|
"min",
|
|
6618
6636
|
[arg],
|
|
6619
6637
|
options
|
|
@@ -6643,7 +6661,7 @@ class AggregateMethods {
|
|
|
6643
6661
|
max(arg, options) {
|
|
6644
6662
|
return makeFnExpression(
|
|
6645
6663
|
this,
|
|
6646
|
-
|
|
6664
|
+
numericResultColumn(this, arg),
|
|
6647
6665
|
"max",
|
|
6648
6666
|
[arg],
|
|
6649
6667
|
options
|
|
@@ -6672,7 +6690,7 @@ class AggregateMethods {
|
|
|
6672
6690
|
sum(arg, options) {
|
|
6673
6691
|
return makeFnExpression(
|
|
6674
6692
|
this,
|
|
6675
|
-
|
|
6693
|
+
numericResultColumn(this, arg),
|
|
6676
6694
|
"sum",
|
|
6677
6695
|
[arg],
|
|
6678
6696
|
options
|
|
@@ -6698,7 +6716,7 @@ class AggregateMethods {
|
|
|
6698
6716
|
avg(arg, options) {
|
|
6699
6717
|
return makeFnExpression(
|
|
6700
6718
|
this,
|
|
6701
|
-
|
|
6719
|
+
numericResultColumn(this, arg),
|
|
6702
6720
|
"avg",
|
|
6703
6721
|
[arg],
|
|
6704
6722
|
options
|
|
@@ -6727,7 +6745,7 @@ class AggregateMethods {
|
|
|
6727
6745
|
bitAnd(arg, options) {
|
|
6728
6746
|
return makeFnExpression(
|
|
6729
6747
|
this,
|
|
6730
|
-
|
|
6748
|
+
numericResultColumn(this, arg),
|
|
6731
6749
|
"bit_and",
|
|
6732
6750
|
[arg],
|
|
6733
6751
|
options
|
|
@@ -6753,7 +6771,7 @@ class AggregateMethods {
|
|
|
6753
6771
|
bitOr(arg, options) {
|
|
6754
6772
|
return makeFnExpression(
|
|
6755
6773
|
this,
|
|
6756
|
-
|
|
6774
|
+
numericResultColumn(this, arg),
|
|
6757
6775
|
"bit_or",
|
|
6758
6776
|
[arg],
|
|
6759
6777
|
options
|
|
@@ -12702,6 +12720,7 @@ const testTransaction = {
|
|
|
12702
12720
|
adapter.query = t.query.bind(t);
|
|
12703
12721
|
adapter.arrays = t.arrays.bind(t);
|
|
12704
12722
|
adapter.transaction = t.transaction.bind(t);
|
|
12723
|
+
trx.testTransactionCount = trx.testTransactionCount ? trx.testTransactionCount + 1 : 1;
|
|
12705
12724
|
}
|
|
12706
12725
|
data.reject = rej;
|
|
12707
12726
|
});
|
|
@@ -12710,6 +12729,10 @@ const testTransaction = {
|
|
|
12710
12729
|
throw err;
|
|
12711
12730
|
}
|
|
12712
12731
|
}).finally(() => {
|
|
12732
|
+
const trx = db.internal.transactionStorage.getStore();
|
|
12733
|
+
if (trx == null ? void 0 : trx.testTransactionCount) {
|
|
12734
|
+
trx.testTransactionCount--;
|
|
12735
|
+
}
|
|
12713
12736
|
db.internal.transactionStorage.getStore = getStore;
|
|
12714
12737
|
});
|
|
12715
12738
|
});
|
|
@@ -12787,5 +12810,5 @@ function copyTableData(query, arg) {
|
|
|
12787
12810
|
return q;
|
|
12788
12811
|
}
|
|
12789
12812
|
|
|
12790
|
-
export { Adapter, 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, _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, 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, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12813
|
+
export { Adapter, 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, _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, 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, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12791
12814
|
//# sourceMappingURL=index.mjs.map
|