Skip to content

Instantly share code, notes, and snippets.

@k1r0s
Created August 23, 2018 20:43
Show Gist options
  • Select an option

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

Select an option

Save k1r0s/c656bd4d09f2f9095c0c4fe9a46adb51 to your computer and use it in GitHub Desktop.
import low from "lowdb";
import FileAsync from "lowdb/adapters/FileAsync";
import shortid from "shortid";
import config from "../config/database.config";
import { Provider } from "@ritley/decorators";
@Provider.singleton
export default class DataService {
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