Skip to content

Commit cf2faba

Browse files
committed
Document QuerySet extensions
1 parent 5d03b9b commit cf2faba

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
# RxQueryKit
22

3+
[RxSwift]() extensions for QueryKit.
4+
35
## Usage
46

7+
### QuerySet
8+
9+
RxQueryKit extends QueryKit and provides methods to evaluate and execute
10+
operations as observables.
11+
12+
```swift
13+
let queryset = Person.queryset(context).filter(Person.age > 25)
14+
```
15+
16+
```swift
17+
queryset.objects().subscribeNext {
18+
print($0)
19+
}
20+
```
21+
22+
```swift
23+
queryset.count().subscribeNext {
24+
print("There are now \($0) people who are more than 25.")
25+
}
26+
```
27+
528
### Managed Object Context
629

730
RxQueryKit provides extensions on managed object context to observe when the

RxQueryKit/RxQueryKit.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import RxSwift
33
import QueryKit
44

55

6+
/// Extension to QuerySet to provide observables
67
extension QuerySet {
8+
/// Performs a query for all objects matching the set predicate ordered by any set sort descriptors.
9+
/// Emits a value with an array of all objects when the managed object context is changed.
710
func objects() throws -> Observable<[ModelType]> {
811
return context.qk_objectsDidChange().map { [unowned self] notification in
912
return try self.array()
1013
}.startWith(try self.array())
1114
}
1215

16+
/// Performs a query for the count of all objects matching the set predicate.
17+
/// Emits an Int containing the amount of objects matching the predicate and updates when the managed object context is changed.
1318
func count() throws -> Observable<Int> {
1419
return context.qk_objectsDidChange().map { [unowned self] notification in
1520
return try self.count()

0 commit comments

Comments
 (0)