You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 🎉 **Implemented support for WITH clause ([docs](/drizzle-orm/src/pg-core/README.md#with-clause)). Example usage:**
3
+
4
+
```ts
5
+
const sq =db
6
+
.select()
7
+
.from(users)
8
+
.prepareWithSubquery('sq');
9
+
10
+
const result =awaitdb
11
+
.with(sq)
12
+
.select({
13
+
id: sq.id,
14
+
name: sq.name,
15
+
total: sql<number>`count(${sq.id})::int`(),
16
+
})
17
+
.from(sq)
18
+
.groupBy(sq.id, sq.name);
19
+
```
20
+
21
+
- 🐛 Fixed various bugs with selecting/joining of subqueries.
22
+
- ❗ Renamed `.subquery('alias')` to `.as('alias')`.
23
+
- ❗ ``sql`query`.as<type>()`` is now ``sql<type>`query`()``. Old syntax is still supported, but is deprecated and will be removed in one of the next releases.
> **Note**: Keep in mind, that if you need to select raw `sql` in a WITH subquery and reference that field in other queries, you must add an alias to it:
Otherwise, the field type will become `DrizzleTypeError` and you won't be able to reference it in other queries. If you ignore the type error and still try to reference the field, you will get a runtime error, because we cannot reference that field without an alias.
0 commit comments