-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
api_overview.html
35 lines (22 loc) · 1.36 KB
/
api_overview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{% include anchor.html title="API overview" hash="overview" %}
PouchDB has an asynchronous API, supporting both [callbacks](http:https://docs.nodejitsu.com/articles/getting-started/control-flow/what-are-callbacks) and [promises][promise].
Most of the API is exposed as:
{% highlight js %}
db.doSomething(args..., [options], [callback])
{% endhighlight %}
… where both the `options` and `callback` are optional.
Callbacks use the standard Node.js idiom of:
{% highlight js %}
function(error, result) { /* ... */ }
{% endhighlight %}
… where the `error` will be undefined if there's no error.
If you don't specify a `callback`, then the API returns a [promise][]. In [supported browsers](http:https://caniuse.com/#feat=promises) or Node.js, native promises are used, falling back to the minimal library [lie][] as needed.
{% include alert/start.html variant="info"%}
{% markdown %}
**Using Ionic/Angular?** You can wrap PouchDB promises in [`$q.when()`](https://docs.angularjs.org/api/ng/service/$q#when). This will notify Angular to update the UI when the PouchDB promise has resolved.
{% endmarkdown %}
{% include alert/end.html%}
For more info, check out the [guide to asynchronous code](/guides/async-code.html).
[promise]: https://www.promisejs.org/
[lie]: https://github.com/calvinmetcalf/lie
[event emitter]: http:https://nodejs.org/api/events.html#events_class_events_eventemitter