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

Commit e040bee

Browse files
committed
[readme] - Added documentation for webApi queries
1 parent ffef603 commit e040bee

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/DATABASE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ Firebase supports querying data and this plugin does too, since v2.0.0.
163163

164164
Let's say we have the structure as defined at `setValue`, then use this query to retrieve the companies in country 'Bulgaria':
165165

166+
<details>
167+
<summary>Native API</summary>
168+
166169
```js
167170
var onQueryEvent = function(result) {
168171
// note that the query returns 1 match at a time
@@ -216,6 +219,40 @@ Let's say we have the structure as defined at `setValue`, then use this query to
216219
```
217220

218221
For supported values of the orderBy/range/ranges/limit's `type` properties, take a look at the [`firebase-common.d.ts`](firebase-common.d.ts) TypeScript definitions in this repo.
222+
</details>
223+
<details>
224+
<summary>Web API</summary>
225+
226+
Alternatively you can use the web api to query data. See [docs](https://firebase.google.com/docs/reference/js/firebase.database.Query) for more examples and the full api
227+
228+
Some key notes:
229+
230+
`off("eventType")` will remove all listeners for "eventType" at the given path. So you do not need to call `off()`
231+
the same number of times you call `on()`. Listeners for all eventTypes will be removed if no eventType is provided.
232+
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 ???
235+
236+
DO NOT try to apply more than one orderBy to the same query as this will throw (follows the api)
237+
```typescript
238+
const bad = firebaseWebApi.database().ref(path).orderByKey();
239+
bad.orderByValue(); // <------ will throw here!
240+
241+
// However you could do the following:
242+
firebaseWebApi.database().ref("/companies").orderByKey()
243+
.equalTo("Google")
244+
.on("value", onQueryEvent);
245+
246+
firebaseWebApi.database().ref("/companies").orderByValue()
247+
.startAt(1999)
248+
.on("child_added", onQueryEvent);
249+
250+
firebaseWebApi.database().ref("/companies").off("value");
251+
252+
// You can also do the following
253+
firebase.webQuery("/companies").orderByKey().on("value", onQueryEvent);
254+
```
255+
</details>
219256

220257
### update
221258
Changes the values of the keys specified in the dictionary without overwriting other keys at this location.

0 commit comments

Comments
 (0)