Last active
July 29, 2020 09:25
-
-
Save khalidx/dd457cb045582582db91c9e331aeb444 to your computer and use it in GitHub Desktop.
Using lowdb with TypeScript; instantly instantiates a typed db with defaults and compile-time-checked queries
This file contains 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 FileSync from 'lowdb/adapters/FileSync' | |
export const database = <T> (defaults: T) => { | |
const adapter = new FileSync<T>('db.json') | |
const db = low(adapter) | |
db.defaults(defaults).write() | |
return db | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment