| {% include anchor.html title="API overview" hash="overview" %} |
| |
| PouchDB has an asynchronous API, supporting both [callbacks](http://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://caniuse.com/#feat=promises), native promises are used, falling back to the minimal library [lie][] as needed. In Node.js, promises come from [Bluebird][]. |
| |
| 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 |
| [bluebird]: https://github.com/petkaantonov/bluebird |
| [event emitter]: http://nodejs.org/api/events.html#events_class_events_eventemitter |