durcno@1.0.0-alpha.23
Minor Changes
-
212f208 - Thanks to @almahdi404 !
feat(functions): add trunc and power mathematical functions
Added support for PostgreSQL
truncandpowermathematical functions in query builder expressions.trunctruncates a numeric expression to the nearest integer or optionally to a specified number of decimal places:import { trunc } from "durcno";trunc(Users.price);trunc(Users.price, 2);powerreturns a numeric expression raised to the power of an exponent:import { power } from "durcno";power(Users.price, 2); -
03680e2 - Thanks to @almahdi404 !
perf(db): optimize prepared query execution
Introduced
execStrArgsin the query executor to directly execute raw query strings and arguments. This avoids unnecessarily instantiatingQueryobjects, significantly improving the performance of prepared statements.Additionally, expanded
SqlArgTypeto includebigintandbooleantypes, allowing them to be passed directly as arguments todb.rawand prepared queries.
Patch Changes
-
6b69489 - Thanks to @almahdi404 !
fix(qb/type): fix type inference for scalar functions inside aggregate functions
Fix type inference when passing scalar functions or scalar arithmetic expressions inside aggregate functions like
sum(),avg(),min(),max(), andcount().const [result] = await db.from(schema.Users).select({totalAbs: sum(abs(schema.Users.score)),avgAbs: avg(abs(schema.Users.score)),}); -
23ccde2 - Thanks to @almahdi404 !
fix(rq): support extra foreign key constraints in relation subqueries
Update
buildRelationSubqueryin the relational query builder to resolve foreign key column references defined via table extra foreign key constraints (extra.foreignKeys) when inline column references (getReferencesCol) are absent.This resolves issues where relational queries failed to resolve relations defined through table-level foreign key definitions.
-
ac5c26e - Thanks to @almahdi404 !
perf(qb): optimize object mapping for relation and select queries
This optimization refines how rows returned by the database are transformed into TypeScript objects across
rq.ts(RelationQuery) andselect.ts(SelectQuery) to improve overall performance and reduce memory allocations.- Relation Queries: Now leverage SQL aliasing directly in the query (
AS "colName") to retrieve rows with TypeScript keys pre-mapped, eliminating the need to iterate through objects and rewrite keys in JavaScript. It also uses traditionalforloops rather thanfor...into iterate array relations, optimizing array processing. - Select Queries: The object mapping logic now short-circuits on empty arrays. Additionally, it caches
Object.keys()from the first row and re-uses it to iterate over subsequent rows instead of callingObject.entries()on every row, reducing garbage collection overhead for large result sets.
- Relation Queries: Now leverage SQL aliasing directly in the query (
-
47b86fa - Thanks to @almahdi404 !
perf(qb): inline variable access during row processing
Optimized query result mapping in
rqandselectquery builders by removing intermediate variable declarations during row iteration. This reduces unnecessary memory allocations and improves performance when mapping database rows to TypeScript objects.