Created
August 23, 2018 00:32
-
-
Save k1r0s/10432f34493af8a9246688d12c9c08b8 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 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