Skip to main content

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, and ON CONFLICT DO UPDATE SET clauses.

    Expressions in UPDATE​

    UPDATE .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 INSERT​

    INSERT .values() now accepts column-free scalar SQL functions alongside literals and raw sql:

    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 and excluded.*:

    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() and doUpdateSet() now automatically filter out keys with undefined values, 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 / *Value aliases), and expose inferSelect, inferInsert, and inferUpdate on table.$:

    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 in index() and uniqueIndex().

    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 users
    index([t.email]).where(eq(t.status, "active")),

    // Partial unique index for soft deletes
    uniqueIndex("users_active_email_idx", [t.email]).where(
    isNull(t.deletedAt),
    ),
    ],
    },
    );

    The .where() method accepts any filter operator (eq, isNull, and, or, etc.), raw sql, or a callback. Method chaining mirrors SQL syntax, supporting .using().where().

    Custom Index Names​

    index() and uniqueIndex() now accept an explicit index name as an optional first parameter, while preserving the existing signature that auto-generates names:

    // Explicit custom name
    index("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]);