@@ -82,43 +82,7 @@ func (m *Memory) QueryDocuments(auth internal.Auth, dbName, col string, filter m
82
82
83
83
list = secureRead (auth , col , list )
84
84
85
- var filtered []map [string ]any
86
- for _ , doc := range list {
87
- matches := 0
88
- for k , v := range filter {
89
- op , field := extractOperatorAndValue (k )
90
- switch op {
91
- case "=" :
92
- if equal (doc [field ], v ) {
93
- matches ++
94
- }
95
- case "!=" :
96
- if notEqual (doc [field ], v ) {
97
- matches ++
98
- }
99
- case ">" :
100
- if greater (doc [field ], v ) {
101
- matches ++
102
- }
103
- case "<" :
104
- if lower (doc [field ], v ) {
105
- matches ++
106
- }
107
- case ">=" :
108
- if greaterThanEqual (doc [field ], v ) {
109
- matches ++
110
- }
111
- case "<=" :
112
- if lowerThanEqual (doc [field ], v ) {
113
- matches ++
114
- }
115
- }
116
- }
117
-
118
- if matches == len (filter ) {
119
- filtered = append (filtered , doc )
120
- }
121
- }
85
+ filtered := filterByClauses (list , filter )
122
86
123
87
start := (params .Page - 1 ) * params .Size
124
88
end := start + params .Size - 1
@@ -156,9 +120,7 @@ func (m *Memory) UpdateDocument(auth internal.Auth, dbName, col, id string, doc
156
120
return
157
121
}
158
122
159
- delete (doc , FieldID )
160
- delete (doc , FieldAccountID )
161
- delete (doc , FieldOwnerID )
123
+ removeNotEditableFields (doc )
162
124
163
125
for k , v := range doc {
164
126
exists [k ] = v
@@ -168,6 +130,28 @@ func (m *Memory) UpdateDocument(auth internal.Auth, dbName, col, id string, doc
168
130
return
169
131
}
170
132
133
+ func (m * Memory ) UpdateDocuments (auth internal.Auth , dbName , col string , filter map [string ]interface {}, updateFields map [string ]interface {}) (n int64 , err error ) {
134
+ list , err := all [map [string ]any ](m , dbName , col )
135
+
136
+ if err != nil {
137
+ return
138
+ }
139
+ list = secureRead (auth , col , list )
140
+
141
+ removeNotEditableFields (updateFields )
142
+ filtered := filterByClauses (list , filter )
143
+
144
+ for _ , v := range filtered {
145
+ _ , err := m .UpdateDocument (auth , dbName , col , v [FieldID ].(string ), updateFields )
146
+ if err != nil {
147
+ return n , err
148
+ }
149
+ n ++
150
+ }
151
+
152
+ return
153
+ }
154
+
171
155
func (m * Memory ) IncrementValue (auth internal.Auth , dbName , col , id , field string , n int ) error {
172
156
doc , err := m .GetDocumentByID (auth , dbName , col , id )
173
157
if err != nil {
@@ -239,6 +223,12 @@ func extractOperatorAndValue(s string) (op string, field string) {
239
223
return
240
224
}
241
225
226
+ func removeNotEditableFields (m map [string ]any ) {
227
+ delete (m , FieldID )
228
+ delete (m , FieldAccountID )
229
+ delete (m , FieldOwnerID )
230
+ }
231
+
242
232
func equal (v any , val any ) bool {
243
233
return fmt .Sprintf ("%v" , v ) == fmt .Sprintf ("%v" , val )
244
234
}
0 commit comments