-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathdefaults.html
More file actions
42 lines (31 loc) · 1.29 KB
/
Copy pathdefaults.html
File metadata and controls
42 lines (31 loc) · 1.29 KB
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
36
37
38
39
40
{% include anchor.html edit="true" title="Default settings" hash="defaults" %}
If you find yourself using the same constructor options repeatedly,
you can simplify your code with `PouchDB.defaults()`:
{% highlight "js" %}
PouchDB.defaults({
option1: 'foo',
option2: 'value'
});
{% endhighlight %}
The returned object is a constructor function that works the same as `PouchDB`, except that whenever you invoke it (e.g. with `new`), the given options will be passed in by default.
#### Example Usage:
{% highlight "js" %}
const MyMemPouch = PouchDB.defaults({
adapter: 'memory'
});
// In-memory PouchDB
const myMemPouch = new MyMemPouch('dbname');
const MyPrefixedPouch = PouchDB.defaults({
prefix: '/path/to/my/db/'
});
// db will be named '/path/to/my/db/dbname', useful for LevelDB
const myPrefixedPouch = new MyPrefixedPouch('dbname');
const HTTPPouch = PouchDB.defaults({
prefix: 'http://example.org'
});
// db will be located at 'http://example.org/dbname'
const myHttpPouch = new HTTPPouch('dbname');
{% endhighlight %}
Note the special constructor option `prefix`, which appends a prefix to the database name
and can be helpful for URL-based or file-based LevelDOWN path names.
All [constructor options](#create_database) are supported. Default options can still be overridden individually.