Commit ca70aee
refactor(gomongo): return native Go types instead of JSON strings (#22)
* refactor(gomongo): return native Go types instead of JSON strings
Change Result type from returning JSON strings to native Go types for
better type safety and usability.
Key changes:
- Add types.OperationType enum in new types/ package (single source of truth)
- Result.Value is now []any containing native Go types (bson.D, string,
int64, bool) instead of JSON-encoded strings
- Result.Operation indicates the operation type for callers to determine
expected element types in Value slice
Return types by operation:
- Find/Aggregate/GetIndexes/GetCollectionInfos: []bson.D
- FindOne/FindOneAnd*: 0 or 1 bson.D
- CountDocuments/EstimatedDocumentCount: int64
- Distinct: values of various types
- ShowDatabases/ShowCollections/GetCollectionNames: strings
- Write operations: bson.D with operation result
- Admin operations: bson.D with {ok: 1} or bool/string
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Address PR review feedback
- Optimize executeFind to append directly to []any, avoiding intermediate slice
- Use checked type assertions in README examples for safer error handling
- Fix misleading comment on containsDatabaseName (values are always strings)
- Fix misleading comment on getDocField helper in tests
- Consolidate duplicate valueToJSON test helpers into single shared function
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 3b10cff commit ca70aee
File tree
19 files changed
+765
-993
lines changed- internal
- executor
- testutil
- translator
- types
19 files changed
+765
-993
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
53 | 71 | | |
54 | 72 | | |
55 | 73 | | |
| |||
74 | 92 | | |
75 | 93 | | |
76 | 94 | | |
77 | | - | |
| 95 | + | |
78 | 96 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
87 | 108 | | |
88 | 109 | | |
89 | 110 | | |
| |||
191 | 212 | | |
192 | 213 | | |
193 | 214 | | |
194 | | - | |
| 215 | + | |
195 | 216 | | |
196 | 217 | | |
197 | 218 | | |
198 | 219 | | |
199 | 220 | | |
200 | | - | |
| 221 | + | |
201 | 222 | | |
202 | | - | |
203 | | - | |
| 223 | + | |
| 224 | + | |
204 | 225 | | |
205 | 226 | | |
206 | 227 | | |
207 | 228 | | |
208 | 229 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
213 | 234 | | |
214 | 235 | | |
215 | 236 | | |
| |||
0 commit comments