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
Copy file name to clipboardexpand all lines: packages/d2ts/src/d2ql/README.md
+62
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,68 @@ The current implementation supports:
71
71
- JSON_EXTRACT for working with JSON data
72
72
- GROUP BY and HAVING clauses with aggregate functions:
73
73
- SUM, COUNT, AVG, MIN, MAX, MEDIAN, MODE
74
+
- Common Table Expressions (CTEs) using the WITH clause
75
+
76
+
## Common Table Expressions (CTEs)
77
+
78
+
D2QL supports SQL-like Common Table Expressions (CTEs) using the `WITH` clause. CTEs allow you to define temporary result sets that can be referenced in the main query or in other CTEs.
79
+
80
+
### Basic CTE Example
81
+
82
+
```typescript
83
+
const query:Query= {
84
+
with: [
85
+
{
86
+
select: ['@id', '@name', '@age'],
87
+
from: 'users',
88
+
where: ['@age', '>', 21],
89
+
as: 'adult_users'
90
+
}
91
+
],
92
+
select: ['@id', '@name'],
93
+
from: 'adult_users',
94
+
where: ['@name', 'like', 'A%']
95
+
};
96
+
```
97
+
98
+
### Multiple CTEs Example
99
+
100
+
You can define multiple CTEs and reference earlier CTEs in later ones:
"description": "An array of Common Table Expressions (CTEs) that can be referenced in the main query or in other CTEs. Each CTE must have an 'as' property that defines its name and cannot have a 'keyBy' property.",
0 commit comments