| {% 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 %} |
| var MyMemPouch = PouchDB.defaults({ |
| adapter: 'memory' |
| }); |
| // In-memory PouchDB |
| var myMemPouch = new MyMemPouch('dbname'); |
| |
| var MyPrefixedPouch = PouchDB.defaults({ |
| prefix: '/path/to/my/db/' |
| }); |
| // db will be named '/path/to/my/db/dbname', useful for LevelDB |
| var myPrefixedPouch = new MyPrefixedPouch('dbname'); |
| |
| var HTTPPouch = PouchDB.defaults({ |
| prefix: 'http://example.org' |
| }); |
| |
| // db will be located at 'http://example.org/dbname' |
| var 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 overriden individually. |
| |
| |