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

Commit 34c8f18

Browse files
authored
updated docs for setting multiple localfiles in nedb (#981)
1 parent da8686f commit 34c8f18

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/en/savingreading-local-files.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,30 @@ export default new Datastore({
2525
})
2626
```
2727

28+
If we want to setup multiple databases across different files in to our `userData` directory, we can wrap the Datastore into a function and export many databases.
29+
30+
```js
31+
import Datastore from 'nedb'
32+
import path from 'path'
33+
import { remote } from 'electron'
34+
35+
const dbFactory = file =>
36+
new Datastore({
37+
filename: `${path.join(remote.app.getPath('userData'))}/data/${file}`,
38+
autoload: true
39+
})
40+
41+
const db = {
42+
users: dbFactory('users.db'),
43+
config: dbFactory('config.db')
44+
}
45+
46+
export default db
47+
```
48+
2849
**src/renderer/main.js**
2950

30-
To take this a step further, we can then import our datastore into `src/renderer/main.js` and attach it to the Vue prototype. Doing so, we are now able to access the datastore API through the usage of `this.$db` in all component files.
51+
To take this a step further, we can then import our datastore into `src/renderer/main.js` and attach it to the Vue prototype. Doing so, we are now able to access the datastore API through the usage of `this.$db` in all component files. If we had multiple databases, we are able to acces throught the usage of `this.$db.{database-name}`.
3152

3253
```js
3354
import db from './datastore'

0 commit comments

Comments
 (0)