Last active
November 26, 2019 19:58
-
-
Save nathandaly/d8612bec12c016cd65c0b4cc1c63d998 to your computer and use it in GitHub Desktop.
Using a DB with Vuex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function createPerson ({ commit }, payload) { | |
const person = { | |
...payload, | |
type: 'member' | |
} | |
this._vm.$db.insert(person, (err, newDoc) => { | |
// NeDB: Callback is optional | |
// newDoc is the newly inserted document, including its _id | |
if (err) { | |
return err | |
} | |
// commit mutation | |
commit('createPerson', newDoc) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Datastore from 'nedb' | |
import path from 'path' | |
import { remote } from 'electron' | |
// leave the export, even if you don't use it | |
export default async ({ app, router, Vue }) => { | |
// something to do | |
const db = new Datastore({ | |
filename: path.join(remote.app.getPath('userData', '/users.db')), | |
autoload: true | |
}) | |
Vue.prototype.$db = db | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boot: [ | |
'i18n', | |
'nedb', | |
'filters' | |
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment