Commit 4196d19
authored
refactor(sql): simplify Iter API to use iter.Seq2[T, error] (#536)
Refactored the RowsIter design to provide a cleaner and more idiomatic API:
- Removed RowsIter struct and Err() method
- Changed Iter() to directly return (iter.Seq2[T, error], error)
- Errors are now yielded during iteration instead of checked afterwards
- Added rows.Err() check after iteration completes
- Updated all tests to use the new API signature
Breaking Changes:
- Iter() now returns (iter.Seq2[T, error], error) instead of *RowsIter[T]
- Users must handle errors in the range loop: for v, err := range seq
Benefits:
- More concise API with less boilerplate
- Immediate error handling in iteration loop
- Follows Go's standard error handling patterns
- Better suited for use in shortcuts
Added:
- QueryIterContext() shortcut function with automatic row cleanup
Files changed:
- sql/binder.go: Simplified Iter implementation (-78 lines)
- sql/binder_test.go: Updated tests for new API
- bind.go: Updated documentation and function signature
- shortcuts.go: Added QueryIterContext helper1 parent aaf013c commit 4196d19
4 files changed
+65
-78
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
118 | | - | |
| 122 | + | |
119 | 123 | | |
120 | | - | |
| 124 | + | |
| 125 | + | |
121 | 126 | | |
122 | | - | |
123 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
124 | 135 | | |
125 | 136 | | |
126 | 137 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 138 | | |
131 | 139 | | |
132 | 140 | | |
133 | | - | |
134 | | - | |
| 141 | + | |
| 142 | + | |
135 | 143 | | |
136 | 144 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
180 | 179 | | |
181 | 180 | | |
182 | 181 | | |
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 | | - | |
212 | | - | |
213 | | - | |
| 182 | + | |
| 183 | + | |
214 | 184 | | |
215 | | - | |
216 | | - | |
| 185 | + | |
217 | 186 | | |
| 187 | + | |
218 | 188 | | |
219 | 189 | | |
220 | 190 | | |
221 | | - | |
222 | | - | |
| 191 | + | |
223 | 192 | | |
224 | 193 | | |
225 | 194 | | |
| |||
229 | 198 | | |
230 | 199 | | |
231 | 200 | | |
| 201 | + | |
| 202 | + | |
232 | 203 | | |
233 | 204 | | |
234 | 205 | | |
| |||
248 | 219 | | |
249 | 220 | | |
250 | 221 | | |
251 | | - | |
| 222 | + | |
252 | 223 | | |
253 | 224 | | |
254 | 225 | | |
255 | 226 | | |
256 | 227 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 228 | + | |
| 229 | + | |
260 | 230 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 231 | + | |
266 | 232 | | |
267 | 233 | | |
268 | 234 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
282 | 241 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
273 | | - | |
274 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
275 | 275 | | |
276 | | - | |
277 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
278 | 281 | | |
279 | 282 | | |
280 | 283 | | |
| |||
291 | 294 | | |
292 | 295 | | |
293 | 296 | | |
294 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
295 | 301 | | |
296 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
297 | 306 | | |
298 | 307 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | 308 | | |
303 | 309 | | |
304 | 310 | | |
| |||
0 commit comments