mirror of
https://github.com/caoer/RxFirebase.git
synced 2026-04-30 05:35:48 +08:00
Readme
This commit is contained in:
87
README.md
87
README.md
@@ -23,6 +23,7 @@ it, simply add the following line to your Podfile:
|
||||
```ruby
|
||||
pod 'RxFirebase/Firestore'
|
||||
pod 'RxFirebase/RemoteConfig'
|
||||
pod 'RxFirebase/Database'
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -31,6 +32,92 @@ pod 'RxFirebase/RemoteConfig'
|
||||
import RxFirebase
|
||||
```
|
||||
|
||||
### Database
|
||||
|
||||
Basic write operation:
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
ref.child("users")
|
||||
.child("1")
|
||||
.rx
|
||||
.setValue(["username": "Arnonymous"])
|
||||
.subscribe(onNext: { _ in
|
||||
print("Document successfully updated")
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#basic_write
|
||||
```
|
||||
|
||||
Listen for value events:
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
ref.child("users")
|
||||
.child("1")
|
||||
.rx
|
||||
.observeEvent(.value)
|
||||
.subscribe(onNext: { snapshot in
|
||||
print("Value:\(snapshot.value)")
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#listen_for_value_events
|
||||
```
|
||||
|
||||
Read data once:
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
ref.child("users")
|
||||
.child("1")
|
||||
.rx
|
||||
.observeSingleEvent(.value)
|
||||
.subscribe(onNext: { snapshot in
|
||||
print("Value:\(snapshot.value)")
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#read_data_once
|
||||
```
|
||||
|
||||
Update specific fields:
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
let childUpdates = ["/posts/\(key)": post,
|
||||
"/user-posts/\(userID)/\(key)/": post]
|
||||
ref.rx.updateChildValues(childUpdates)
|
||||
.subscribe(onNext: { _ in
|
||||
// Success
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#update_specific_fields
|
||||
```
|
||||
|
||||
Delete data:
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
ref.rx.removeValue()
|
||||
.subscribe(onNext: { _ in
|
||||
// Success
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#delete_data
|
||||
```
|
||||
|
||||
Save data as transactions
|
||||
```swift
|
||||
let ref = Database.database().reference()
|
||||
|
||||
ref.rx.runTransactionBlock { currentData in
|
||||
// TransactionResult
|
||||
}.subscribe(onNext: { _ in
|
||||
// Success
|
||||
}).disposed(by: disposeBag)
|
||||
|
||||
// https://firebase.google.com/docs/database/ios/read-and-write#save_data_as_transactions
|
||||
```
|
||||
|
||||
### Firestore
|
||||
|
||||
Setting data:
|
||||
|
||||
Reference in New Issue
Block a user