Skip to content

Instantly share code, notes, and snippets.

@k1r0s
Created August 23, 2018 00:32
Show Gist options
  • Select an option

  • Save k1r0s/10432f34493af8a9246688d12c9c08b8 to your computer and use it in GitHub Desktop.

Select an option

Save k1r0s/10432f34493af8a9246688d12c9c08b8 to your computer and use it in GitHub Desktop.
import low from "lowdb";
import FileAsync from "lowdb/adapters/FileAsync";
import config from "./database.config";
import shortid from "shortid";
export default class DataBase {
onConnected = undefined
constructor() {
this.onConnected = low(new FileAsync(config.path, {
defaultValue: config.defaults
}))
}
create(entity, newAttributes) {
return this.onConnected.then(database =>
database
.get(entity)
.push({ uid: shortid.generate(), ...newAttributes })
.last()
.write()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment