Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 9715862

Browse files
committed
[docs][database] - Update webapi query documentation
1 parent 687c23b commit 9715862

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

docs/DATABASE.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,24 @@ Alternatively you can use the web api to query data. See [docs](https://firebase
227227

228228
Some key notes:
229229

230+
The DataSnapshot returned is vastly different from the native api's snapshot! Please follow the web api docs to see what
231+
you can do with the datasnapshot returned. Note that Datasnapshot.ref() is yet implemented.
232+
233+
`Query.on()` does not accept a cancelCallbackOrContext. Similar to the native api, check if result.error is true before continuing.
234+
235+
`once("eventType")` behaves differently on Android and iOS. On Android once only works with an eventType of `value` whereas
236+
iOS will work with all the eventTypes like `child_added, child_removed` etc.
237+
230238
`off("eventType")` will remove all listeners for "eventType" at the given path. So you do not need to call `off()`
231239
the same number of times you call `on()`. Listeners for all eventTypes will be removed if no eventType is provided.
232240

233-
Filters (equalTo, starAt, endAt, LimitBy, etc) are only usable after you chain it with a sort. (While Firebase exposes these without doing
234-
a sort, your callback is never called). Think about it, if you apply equalTo without an orderBy what are you checking key, value, priority ???
241+
Filters (`equalTo, startAt, endAt, LimitBy`, etc) should be used with a sort. If not, you may not get the result expected.
242+
If you apply equalTo without an orderBy what are you checking for (key, value, priority)?
235243

236-
DO NOT try to apply more than one orderBy to the same query as this will throw (follows the api)
244+
When using `equalTo, startAt or endAt` chained with `orderByKey()`, you MUST make sure they are all strings. Otherwise expect
245+
an exception to be thrown.
246+
247+
DO NOT try to apply more than one orderBy to the same query as this will crash the application (follows the api)
237248
```typescript
238249
const bad = firebaseWebApi.database().ref(path).orderByKey();
239250
bad.orderByValue(); // <------ will throw here!
@@ -251,7 +262,23 @@ DO NOT try to apply more than one orderBy to the same query as this will throw (
251262

252263
// You can also do the following
253264
firebase.webQuery("/companies").orderByKey().on("value", onQueryEvent);
265+
266+
const onQueryEvent = (result: any) {
267+
if (!result.error) {
268+
console.log("Exists: " + result.exists());
269+
console.log("Key: " + result.key);
270+
console.log("Value: " + JSON.stringify(result.val()));
271+
result.forEach(
272+
snapshot => {
273+
// Do something forEach children. Note that this goes one level deep
274+
console.log(snapshot.toJSON());
275+
}
276+
);
277+
}
278+
};
279+
254280
```
281+
Since the webapi queries follow the Google Documentation you can look at their examples for more reference.
255282
</details>
256283

257284
### update

0 commit comments

Comments
 (0)