Commit 60cedea
cosmos: Add Query::with_text() and Query::append_text() methods (Azure#3045)
Adds methods to modify query text after creation, enabling more
ergonomic query building patterns when working with optional parameters.
## Problem
The `Query` type only allowed adding parameters via `with_parameter()`,
but the query text could not be changed once created. This made it
cumbersome to build queries with optional filters:
```rust
// Previous approach required recreating Query objects
if let Some(high) = high_time {
query_text.push_str(&format!(" AND c.time <= @high_time"));
query = Query::from(query_text.as_str());
query = query.with_parameter("@high_time", high)?;
}
```
## Solution
Added two new methods following the same consumption pattern as
`with_parameter()`:
- `Query::with_text(String) -> Self` - Replaces the current query text
- `Query::append_text(&str) -> Self` - Appends text to the current query
text
Both methods preserve existing parameters and support method chaining:
```rust
// New ergonomic approach
if let Some(high) = high_time {
query = query.append_text(" AND c.time <= @high_time")
.with_parameter("@high_time", high)?;
}
```
## Changes
- Added `Query::with_text()` and `Query::append_text()` methods
- Added comprehensive unit tests covering functionality and method
chaining
- Updated documentation with usage examples
- Updated CHANGELOG.md
All existing functionality remains unchanged and fully backward
compatible.
<!-- START COPILOT CODING AGENT SUFFIX -->
----
**Additional instructions:**
> Make sure you structure your commits in a sensible way and include a
concise but descriptive PR description. PREFER concise descriptions and
code. The team knows how this code should work, they don't need
explanations of it. The code should be largely self-explanatory.
Fixes Azure#3044
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start
the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: analogrelay <[email protected]>1 parent 56fe61e commit 60cedea
2 files changed
+81
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
30 | 45 | | |
31 | 46 | | |
32 | 47 | | |
| |||
92 | 107 | | |
93 | 108 | | |
94 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
95 | 122 | | |
96 | 123 | | |
97 | 124 | | |
| |||
169 | 196 | | |
170 | 197 | | |
171 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
172 | 251 | | |
0 commit comments