durcno@1.0.0-alpha.28
Minor Changes
-
eced7f0 - Thanks to @almahdi404 !
feat(qb): add .with() support for .query()
Add
.query()support onWithStatement(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
AnyCteWithColumnsgeneric fromRecord<any, any>toany. This resolves function-parameter contravariance issues onextra.indexeswhen passing multiple CTEs todb.with(cte1, cte2).const q = db.with(cte1, cte2).from(cte1).select("*");In relational queries (
db.query()), updateRelationReturnTypeto directly inspect the relation discriminant (TRelation["t"] extends "Many") and remove the internalAnyManytype alias, ensuring consistentO[]array inference for one-to-many relations.