Skip to main content

durcno@1.0.0-alpha.28

Minor Changes​

  • eced7f0 - Thanks to @almahdi404 !

    feat(qb): add .with() support for .query()

    Add .query() support on WithStatement (db.with().query(table)), allowing Common Table Expressions (CTEs) to be declared and scoped to relational queries.

    const activeUsers = db.with("activeUsers").as(
    db
    .from(Users)
    .select(() => ({ id: Users.id }))
    .where(() => eq(Users.status, "active")),
    );

    const users = await db
    .with(activeUsers)
    .query(Users)
    .findMany({
    where: isIn(
    Users.id,
    db.from(activeUsers).select(() => ({ id: activeUsers.id })),
    ),
    with: {
    posts: {},
    },
    });

    // Or evaluate CTE subqueries directly inside the select option using exists() / isIn():
    const usersWithStatus = await db
    .with(activeUsers)
    .query(Users)
    .findMany({
    select: {
    id: Users.id,
    name: Users.name,
    isActive: exists(
    db
    .from(activeUsers)
    .select(() => ({ id: activeUsers.id }))
    .where(() => eq(activeUsers.id, Users.id)),
    ),
    },
    });

Patch Changes​

  • d0ebe20 - Thanks to @almahdi404 !

    fix(types): resolve cte contravariance and relation return type inference

    Widen AnyCteWithColumns generic from Record<any, any> to any. This resolves function-parameter contravariance issues on extra.indexes when passing multiple CTEs to db.with(cte1, cte2).

    const q = db.with(cte1, cte2).from(cte1).select("*");

    In relational queries (db.query()), update RelationReturnType to directly inspect the relation discriminant (TRelation["t"] extends "Many") and remove the internal AnyMany type alias, ensuring consistent O[] array inference for one-to-many relations.