durcno@1.0.0-alpha.29
Minor Changes
-
dbf058d - Thanks to @almahdi404 !
feat(qb): support expressions in insert and update
Add support for SQL expressions (scalar SQL functions, column assignments, raw SQL, and prepared arguments) across
INSERT,UPDATE, andON CONFLICT DO UPDATE SETclauses.Expressions in
UPDATEUPDATE .set()now supports column-to-column assignment and scalar SQL functions (arithmetic, string, conditional, etc.), fully validated for type compatibility:await db.update(Users).set({score: add(Users.score, 10),bio: Users.description,username: lower(Users.username),}).where(eq(Users.id, 1));Expressions in
INSERTINSERT .values()now accepts column-free scalar SQL functions alongside literals and rawsql:await db.insertInto(Users).values({username: lower("ALICE"),score: add(10, 5),bio: coalesce(null, "Default bio"),});Expressions in Upserts (
ON CONFLICT DO UPDATE SET)doUpdateSet()now supports scalar SQL functions and column references using existing table columns andexcluded.*:await db.insertInto(Users).values(newUser).onConflict(Users.username).doUpdateSet(({ excluded }) => ({score: add(Users.score, excluded.score),bio: concat(Users.bio, " - updated"),}));Partial Update Handling
UPDATE .set()anddoUpdateSet()now automatically filter out keys withundefinedvalues, ensuring partial updates only include columns with concrete values or SQL expressions.Model Type Inference
Also introduce table model type inference helpers (
InferSelect,InferInsert,InferUpdate, and corresponding*Model/*Valuealiases), and exposeinferSelect,inferInsert, andinferUpdateontable.$:import { type InferInsert, type InferSelect, type InferUpdate } from "durcno";type User = InferSelect<typeof Users>;type NewUser = InferInsert<typeof Users>;type UserUpdate = InferUpdate<typeof Users>; -
f40cfef - Thanks to @almahdi404 !
feat(indexes): support partial indexes and custom index names
Add support for partial indexes via
.where()on table indexes and custom index naming inindex()anduniqueIndex().Partial Indexes
Indexes now support a
.where()method that specifies a predicate expression for partial indexing. This reduces index size and write overhead while accelerating queries matching the condition:export const Users = table("public","users",{id: pk(),email: varchar({ length: 255, notNull }),status: varchar({ length: 50, notNull }),deletedAt: timestamptz({}),},{indexes: (t) => [// Partial index for active usersindex([t.email]).where(eq(t.status, "active")),// Partial unique index for soft deletesuniqueIndex("users_active_email_idx", [t.email]).where(isNull(t.deletedAt),),],},);The
.where()method accepts any filter operator (eq,isNull,and,or, etc.), rawsql, or a callback. Method chaining mirrors SQL syntax, supporting.using().where().Custom Index Names
index()anduniqueIndex()now accept an explicit index name as an optional first parameter, while preserving the existing signature that auto-generates names:// Explicit custom nameindex("idx_orders_user_id", [Orders.userId]);uniqueIndex("uidx_users_active_email", [Users.email]).where(isNull(Users.deletedAt),);// Auto-generated name (existing behavior)index([Orders.userId]);