durcno@1.0.0-alpha.17
Minor Changes
-
7187405 - Thanks to @almahdi404 !
feat(functions): add arithmetic operators (add, sub, mul, div)
Adds four arithmetic operator functions —
add,sub,mul,div— for building numeric expressions in queries. Each function accepts twoNumericOperandvalues (a numeric column, another numeric function, a plain number literal, or anArg<number>) and returns a composableSqlFn.The functions wrap their operands in parentheses, making it safe to nest them into complex expressions.
const result = await db.from(Products).select({total: mul(Products.price, Products.quantity),discounted: sub(mul(Products.price, Products.quantity), 10),});All four functions are exported from the top-level
durcnopackage. -
5246ebc - Thanks to @almahdi404 !
feat(query-builder): support wildcard RETURNING * syntax in update/delete
Added support for
RETURNING *wildcard syntax in UPDATE and DELETE queries, allowing users to return all columns from modified rows without explicitly specifying each column.Key Changes
- UpdateQuery: Added overload for
returning("*")method that returns all columns with full type safety - DeleteQuery: Added overload for
returning("*")method that returns all columns with full type safety - SQL Generation: Proper handling of
RETURNING *clause in generated SQL queries
Usage Example
// Return all columns from updated rowsconst updated = await db.update(Users).set({ email: "new@example.com" }).where(eq(Users.id, 1n)).returning("*");// Return all columns from deleted rowsconst deleted = await db.delete(Users).where(eq(Users.id, 1n)).returning("*");Type inference correctly provides all table columns when using the wildcard.
- UpdateQuery: Added overload for
-
5b245cb - Thanks to @almahdi404 !
feat(qb): add CTE support via db.with()
Adds first-class Common Table Expression (CTE) support through a new
db.with()API with two overloads.Define a CTE by name, binding it to a subquery:
const activeCte = db.with("activeUsers").as(db.from(Users).select({ id: true, name: true }).where(eq(Users.active, true)),);Use CTEs in SELECT, INSERT, UPDATE, and DELETE statements via
db.with(...ctes):const rows = await db.with(activeCte).from((ctes) => ctes.activeUsers).select();Multiple CTEs can be declared together and referenced in any statement. CTE columns are fully type-inferred from the bound subquery.
Internally, this introduces a
VirtualTablebase class, aCteclass, aWithStatementbuilder, and shared query-builder helpers. A fix was also applied toInConditionto pass the parent query context when rendering subquery values inIN (...)expressions.
Patch Changes
-
a77adf0 - Thanks to @almahdi404 !
fix(migrations): improve internal table dependency tracking
Fixed a bug in the
orderTablesfunction where self-referencing tables (tables that have foreign keys to themselves) were being included in the dependency list.The fix adds an additional filter condition to exclude tables from their own dependency list, preventing circular reference issues during migration generation.