Skip to content

Instantly share code, notes, and snippets.

@nathandaly
Last active November 26, 2019 19:58
Show Gist options
  • Save nathandaly/d8612bec12c016cd65c0b4cc1c63d998 to your computer and use it in GitHub Desktop.
Save nathandaly/d8612bec12c016cd65c0b4cc1c63d998 to your computer and use it in GitHub Desktop.
Using a DB with Vuex.
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)
})
}
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
}
boot: [
'i18n',
'nedb',
'filters'
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment