Skip to main content

durcno@1.0.0-alpha.37

Major Changes​

  • 4a08ea4 - Thanks to @almahdi404 !

    change(columns)!: remove default on delete action for references

    Column-level .references() no longer adds an implicit ON DELETE CASCADE. A plain reference now produces no ON DELETE clause, so PostgreSQL's NO ACTION default applies.

    The object form .references({ column, onDelete }) is removed. Use the lazy getter and chain the delete action instead:

    userId: bigint({ notNull }).references(() => Users.id),
    ownerId: bigint({ notNull })
    .references(() => Users.id)
    .onDeleteCascade(),
    reviewerId: bigint({})
    .references(() => Users.id)
    .onDeleteSetNull(),

    Available actions are .onDelete(action), .onDeleteCascade(), .onDeleteSetNull(), .onDeleteSetDefault(), .onDeleteRestrict(), and .onDeleteNoAction(). The table-level fk() builder follows the same rule and emits no ON DELETE clause by default.

    Existing schemas that relied on the implicit CASCADE — on column-level references or table-level foreign keys — must add .onDeleteCascade(). Without it, the next generate run emits a migration that replaces those foreign keys with NO ACTION.

Minor Changes​

  • e47bc5d - Thanks to @almahdi404 !

    feat: accept boolean literals as filter expressions

    Boolean literals are now valid wherever a filter expression is expected and render as the PostgreSQL constants TRUE / FALSE. This works in SELECT, UPDATE, and DELETE where clauses, having, join on, upsert DO UPDATE ... WHERE, aggregate filter, caseWhen, relational where, query shortcuts, check constraints, and partial index predicates.

    await db.from(Users).select("*").where(() => true);

    const filter = and(
    input.status ? eq(Orders.status, input.status) : true,
    );

    count(Users.id).filter(false);

    and() and or() treat booleans like any other condition while continuing to ignore null and undefined entries. Boolean conditions contribute no referenced columns, so they do not affect grouped-query inference.

    Aggregate .filter() accepts a Filter | boolean union, so conditional predicates can be passed directly. .filter(true) and .filter(false) keep the aggregate's column scope unchanged, while .filter(condition) still widens it with the filter's referenced columns.

  • 5f905bb - Thanks to @almahdi404 !

    feat(qb): support aliased projections in returning

    .returning() now accepts aliased projections on INSERT, UPDATE, and DELETE, mirroring .select() projections. Values can be columns of the affected table, non-aggregate scalar SqlFns, or raw Sql expressions.

    const [row] = await db
    .insertInto(Users)
    .values({ username: "jane_doe", type: "user" })
    .returning({
    userId: Users.id,
    name: Users.username,
    loweredName: lower(Users.username),
    });
    // { userId: bigint; name: string; loweredName: string }

    Alias keys are used in the returned rows and become the CTE column names when a DML query is wrapped with db.with(...).as(...). Boolean true/false inclusion maps and "*" behave as before, and cannot be mixed with aliased expressions in the same object. Aggregate and window expressions are rejected, matching PostgreSQL. Aliased columns stay qualified against the target table in UPDATE ... FROM, so a same-named FROM column cannot make RETURNING ambiguous.