durcno@1.0.0-alpha.5
Minor Changes
-
c68fc6f - Thanks to @almahdi404 !
feat(query-builders): add prepare support to shortcut queries
The shortcut query methods
$count,$exists,$first,$sum,$avg,$min,$max, and$distinctnow support prepared statements viadb.prepare().Each of these query classes (
CountQuery,ExistsQuery,FirstQuery,AggregateQuery,DistinctQuery) gains a newTPrepare extends booleangeneric parameter. When in prepare mode, theWHEREclause is built usingtoQuery()(which inlines$Nparameter placeholders) instead oftoSQL().The
Baseclass threadsTPreparethroughBuildFilterExpressionin the overload signatures, soArg<T>values are accepted only when called viadb.prepare()and are rejected by the type system otherwise.// Prepared shortcut query with a typed argumentconst q = prequery({ userType: Users.type.arg() }, (args) =>db.prepare().$count(Users, eq(Users.type, args.userType)),);const count = await q.run(db, { userType: "admin" });// Non-prepare usage — Arg<T> is rejected at compile time// @ts-expect-errordb.$count(Users, eq(Users.type, Users.type.arg()));
Patch Changes
-
915c8bf - Thanks to @almahdi404 !
fix(insert): use DEFAULT for missing columns and build SQL inline
Previously, insert rows used a two-phase approach: values were collected into intermediate arrays and joined at the end. Columns missing from the input row were filled with
NULL, even when the column had no explicit value — which could silently override a column's database-levelDEFAULT.The column list is now derived directly from
table._.columns, covering all columns consistently. When a column has no value and no insert function,DEFAULTis emitted instead ofNULL, correctly delegating to the database default.SQL is now written directly to
query.sqlas each field is processed, eliminating the intermediaterowValuesandrowsValuearrays and reducing allocations per insert. -
337c0e4 - Thanks to @almahdi404 !
rename(logger): rename createDurcnoLogger to createQueryLogger
The
createDurcnoLoggerfunction has been renamed tocreateQueryLoggerfor clarity.The old name is kept as a deprecated alias so existing code continues to work without changes, but it will be removed in a future major release.
// Beforeimport { createDurcnoLogger } from "durcno/logger";logger: createDurcnoLogger();// Afterimport { createQueryLogger } from "durcno/logger";logger: createQueryLogger(); -
a88b747 - Thanks to @almahdi404 !
fix(filters/array): use column toSQL methods with explicit type cast
Array filters (
arrayContains,arrayContainedBy,arrayOverlaps,arrayHas,arrayAll) previously generated SQL using local helper functions (arrayToSql,valueToSql) that produced string literals without proper PostgreSQL type casts. This caused failures with enum array columns, where PostgreSQL requires an explicit cast (e.g.,::status_enum[]) to resolve the type.The fix delegates SQL generation to the column's own
toSQL/toSQLScalarmethods and appends an explicit cast using the column'ssqlType:// before`${col.fullName} @> ARRAY['active']`// after`${col.fullName} @> ${col.toSQL(["active"])}::status_enum[]`;The array integration tests were restructured into isolated per-type
describeblocks withreturning({ id: true })for row-level isolation.