Created
April 16, 2018 19:57
-
-
Save eric-burel/db441defe1c4d7da6d9a6c92adb834b5 to your computer and use it in GitHub Desktop.
geeglee-redux-lowdb
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
const lodashId = require('lodash-id') | |
const FileSync = require('lowdb/adapters/FileSync') | |
| |
const adapter = new FileSync('db.json') | |
const db = low(adapter) | |
| |
db._.mixin(lodashId) | |
| |
// We need to set some default values, if the collection does not exist yet | |
// We also can store our collection | |
const collection = db | |
.defaults({ posts: [] }) | |
.get('posts') | |
| |
// Insert a new post... | |
const newPost = collection | |
.insert({ title: 'low!' }) | |
.write() | |
| |
// ...and retrieve it using its id | |
const post = collection | |
.getById(newPost.id) | |
.value() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment