Skip to main content

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 two NumericOperand values (a numeric column, another numeric function, a plain number literal, or an Arg<number>) and returns a composable SqlFn.

    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 durcno package.

  • 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 rows
    const updated = await db
    .update(Users)
    .set({ email: "new@example.com" })
    .where(eq(Users.id, 1n))
    .returning("*");

    // Return all columns from deleted rows
    const deleted = await db.delete(Users).where(eq(Users.id, 1n)).returning("*");

    Type inference correctly provides all table columns when using the wildcard.

  • 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 VirtualTable base class, a Cte class, a WithStatement builder, and shared query-builder helpers. A fix was also applied to InCondition to pass the parent query context when rendering subquery values in IN (...) expressions.

Patch Changes​

  • a77adf0 - Thanks to @almahdi404 !

    fix(migrations): improve internal table dependency tracking

    Fixed a bug in the orderTables function 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.