@roit/roit-data-firestore 1.2.42 → 1.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,6 +159,7 @@ Ref: [Firstore Operators](https://firebase.google.com/docs/firestore/query-data/
|
|
|
159
159
|
| OrderBy Desc | findByNameAndOrderByNameDesc | .where('name', '==', value).orderBy("name", "desc")|
|
|
160
160
|
| OrderBy Asc | findByNameAndOrderByNameAsc | .where('name', '==', value).orderBy("name", "asc")|
|
|
161
161
|
| Limit | findByNameAndLimit10 | .where('name', '==', value).limit(10) |
|
|
162
|
+
| OR Queries | Manual query with `or` property | Filter.or(...) - See OR Queries section |
|
|
162
163
|
|
|
163
164
|
#### Example
|
|
164
165
|
|
|
@@ -270,6 +271,112 @@ export class Repository1 extends BaseRepository<User> {
|
|
|
270
271
|
}
|
|
271
272
|
```
|
|
272
273
|
|
|
274
|
+
#### OR Queries
|
|
275
|
+
|
|
276
|
+
The library supports OR queries using the `or` property within the query array. This allows you to create complex queries with multiple conditions using logical OR operations.
|
|
277
|
+
|
|
278
|
+
##### Basic OR Query
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
findByStatusOrCategory(): Promise<Array<User>> {
|
|
282
|
+
return this.query({
|
|
283
|
+
query: [
|
|
284
|
+
{
|
|
285
|
+
or: [
|
|
286
|
+
{ field: 'status', operator: '==', value: 'active' },
|
|
287
|
+
{ field: 'status', operator: '==', value: 'pending' }
|
|
288
|
+
]
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
##### OR with Simple Syntax
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
findByStatusOrCategory(): Promise<Array<User>> {
|
|
299
|
+
return this.query({
|
|
300
|
+
query: [
|
|
301
|
+
{
|
|
302
|
+
or: [
|
|
303
|
+
{ status: 'active' },
|
|
304
|
+
{ status: 'pending' }
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
##### Combining AND and OR
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
findByCategoryAndStatusOrRating(): Promise<Array<User>> {
|
|
316
|
+
return this.query({
|
|
317
|
+
query: [
|
|
318
|
+
{ field: 'category', operator: '==', value: 'electronics' }, // AND condition
|
|
319
|
+
{
|
|
320
|
+
or: [
|
|
321
|
+
{ field: 'price', operator: '>', value: 1000 },
|
|
322
|
+
{ field: 'rating', operator: '>', value: 4.5 }
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
]
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
##### Multiple OR Groups
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
findByMultipleConditions(): Promise<Array<User>> {
|
|
334
|
+
return this.query({
|
|
335
|
+
query: [
|
|
336
|
+
{ field: 'active', operator: '==', value: true }, // AND
|
|
337
|
+
{
|
|
338
|
+
or: [
|
|
339
|
+
{ field: 'price', operator: '>', value: 1000 },
|
|
340
|
+
{ field: 'popular', operator: '==', value: true }
|
|
341
|
+
]
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
or: [
|
|
345
|
+
{ field: 'category', operator: 'in', value: ['electronics', 'books'] },
|
|
346
|
+
{ field: 'featured', operator: '==', value: true }
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
})
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
##### OR with Different Operators
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
findByComplexConditions(): Promise<Array<User>> {
|
|
358
|
+
return this.query({
|
|
359
|
+
query: [
|
|
360
|
+
{
|
|
361
|
+
or: [
|
|
362
|
+
{ field: 'status', operator: '==', value: 'active' },
|
|
363
|
+
{ field: 'price', operator: '>', value: 100 },
|
|
364
|
+
{ field: 'tags', operator: 'array-contains', value: 'premium' },
|
|
365
|
+
{ field: 'category', operator: 'in', value: ['electronics', 'books'] }
|
|
366
|
+
]
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
})
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
##### Limitations
|
|
374
|
+
|
|
375
|
+
- Firestore limits OR queries to a maximum of 30 disjunctions
|
|
376
|
+
- OR queries cannot be combined with `not-in` operators in the same query
|
|
377
|
+
- Only one `not-in` or `!=` operator is allowed per query
|
|
378
|
+
- Complex OR queries may require composite indexes in Firestore
|
|
379
|
+
|
|
273
380
|
#### Paginated Query
|
|
274
381
|
|
|
275
382
|
|