Commit 2ec07a3
authored
Standardize query builder syntax across Rust, TypeScript, and C# (Server/Client) (#4261)
# Description of Changes
Standardizes the query builder API across all three language SDKs (Rust,
TypeScript, C#) for consistency.
**Rust:**
- Rename `Query` struct to `RawQuery`, make `Query` a trait with `fn
into_sql(self) -> String`
- All builder types (`Table`, `FromWhere`, `LeftSemiJoin`,
`RightSemiJoin`) implement `Query<T>` trait
- Views can return `-> impl Query<T>` instead of specifying exact
builder types
- The `#[view]` macro auto-detects `impl Query<T>` and rewrites to
`RawQuery<T>`
- Add `Not` variant to `BoolExpr` with `.not()` method
**TypeScript:**
- Add `ne()` to `ColumnExpression`
- Refactor `BooleanExpr` to `BoolExpr` class with chainable `.and()`,
`.or()`, `.not()` methods
- Make builders valid queries directly (`.build()` deprecated but still
works)
- Deprecate `from()` wrapper — use `tables.person.where(...)` directly
- Merge `query` export into `tables` so table refs are also query
builders
- Add subscription callback form: `subscribe(ctx =>
ctx.from.person.where(...))`
- Unify `useTable` with query builder syntax; deprecate `filter.ts`
**C#:**
- Add `Not()` method to `BoolExpr<TRow>`
- Add `IQuery<TRow>` interface implemented by all builder types
(`Table`, `FromWhere`, `LeftSemiJoin`, `RightSemiJoin`, `Query`)
- Add `ToSql()` to all builder types so `.Build()` is no longer required
- Update `AddQuery` to accept `IQuery<TRow>` instead of `Query<TRow>`
# API and ABI breaking changes
- Rust: `Query<T>` is now a trait (was a struct). The struct is renamed
to `RawQuery<T>`. This is a breaking change for any code that used
`Query<T>` as a type directly.
- TypeScript: `BooleanExpr` is now a `BoolExpr` class (was a
discriminated union type). The `query` export is deprecated in favor of
`tables`.
- C#: `AddQuery` now accepts `Func<QueryBuilder, IQuery<TRow>>` instead
of `Func<QueryBuilder, Query<TRow>>`. Existing `.Build()` calls still
work since `Query<TRow>` implements `IQuery<TRow>`.
# Expected complexity level and risk
3 — Changes touch multiple language SDKs and codegen, but each
individual change is straightforward. The Rust macro rewrite for `impl
Query<T>` detection is the most complex piece. All existing
`.build()`/`.Build()` calls continue to work.
# Testing
- [x] `cargo test -p spacetimedb-query-builder` — 16/16 tests pass
- [x] `cargo check -p spacetimedb` — clean, no warnings
- [x] `cargo check` on views-query, views-sql, views-basic,
views-trapped smoketest modules — all clean
- [x] `cargo test -p spacetimedb-codegen codegen_csharp` — snapshot
updated, passes
- [x] `npm test` (TypeScript) — 101/101 tests pass
- [x] C# QueryBuilder tests — new tests for `Not()`, `IQuery<T>`
interface
- [ ] CI passes1 parent ef9bee0 commit 2ec07a3
65 files changed
Lines changed: 1733 additions & 961 deletions
File tree
- crates
- bindings-csharp/BSATN.Runtime
- bindings-macro/src
- bindings-typescript
- src
- lib
- react
- sdk
- client_api
- svelte
- tanstack
- vue
- test-app
- src
- module_bindings
- tests
- bindings
- src
- tests/ui
- codegen
- src
- tests/snapshots
- commitlog/src/repo
- query-builder/src
- smoketests/modules
- views-query/src
- demo/Blackholio/client-unity/Assets/Scripts/autogen
- docs/docs
- 00100-intro
- 00200-quickstarts
- 00300-tutorials
- 00200-core-concepts
- 00600-client-sdk-languages
- sdks
- csharp
- examples~/regression-tests
- client/module_bindings
- procedure-client/module_bindings
- republishing/client/module_bindings
- tests~
- rust/src
- smoketests/tests
- templates
- basic-ts/src/module_bindings
- browser-ts/src/module_bindings
- bun-ts/src/module_bindings
- chat-console-cs/module_bindings
- chat-react-ts/src
- module_bindings
- react-ts/src/module_bindings
- svelte-ts/src/module_bindings
- vue-ts/src/module_bindings
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| 95 | + | |
| 96 | + | |
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| |||
247 | 254 | | |
248 | 255 | | |
249 | 256 | | |
250 | | - | |
| 257 | + | |
251 | 258 | | |
252 | 259 | | |
253 | 260 | | |
| |||
301 | 308 | | |
302 | 309 | | |
303 | 310 | | |
304 | | - | |
| 311 | + | |
305 | 312 | | |
306 | 313 | | |
307 | 314 | | |
| |||
324 | 331 | | |
325 | 332 | | |
326 | 333 | | |
327 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
328 | 337 | | |
329 | 338 | | |
330 | 339 | | |
| |||
352 | 361 | | |
353 | 362 | | |
354 | 363 | | |
355 | | - | |
| 364 | + | |
356 | 365 | | |
357 | 366 | | |
358 | 367 | | |
| |||
430 | 439 | | |
431 | 440 | | |
432 | 441 | | |
433 | | - | |
| 442 | + | |
434 | 443 | | |
435 | 444 | | |
436 | | - | |
437 | | - | |
438 | | - | |
| 445 | + | |
439 | 446 | | |
| 447 | + | |
| 448 | + | |
440 | 449 | | |
441 | 450 | | |
442 | 451 | | |
| |||
446 | 455 | | |
447 | 456 | | |
448 | 457 | | |
449 | | - | |
| 458 | + | |
450 | 459 | | |
451 | 460 | | |
452 | 461 | | |
| |||
541 | 550 | | |
542 | 551 | | |
543 | 552 | | |
544 | | - | |
| 553 | + | |
545 | 554 | | |
546 | 555 | | |
547 | 556 | | |
| |||
558 | 567 | | |
559 | 568 | | |
560 | 569 | | |
561 | | - | |
562 | | - | |
563 | | - | |
| 570 | + | |
564 | 571 | | |
| 572 | + | |
| 573 | + | |
565 | 574 | | |
566 | 575 | | |
567 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
49 | 69 | | |
50 | 70 | | |
51 | 71 | | |
| |||
137 | 157 | | |
138 | 158 | | |
139 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
140 | 212 | | |
| 213 | + | |
| 214 | + | |
141 | 215 | | |
142 | 216 | | |
143 | 217 | | |
| |||
146 | 220 | | |
147 | 221 | | |
148 | 222 | | |
149 | | - | |
| 223 | + | |
150 | 224 | | |
151 | 225 | | |
152 | 226 | | |
| |||
183 | 257 | | |
184 | 258 | | |
185 | 259 | | |
186 | | - | |
| 260 | + | |
187 | 261 | | |
188 | 262 | | |
189 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
0 commit comments