Created
August 23, 2018 20:43
-
-
Save k1r0s/c656bd4d09f2f9095c0c4fe9a46adb51 to your computer and use it in GitHub Desktop.
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 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