Skip to content

Instantly share code, notes, and snippets.

@eric-burel
Created April 16, 2018 19:57
Show Gist options
  • Save eric-burel/db441defe1c4d7da6d9a6c92adb834b5 to your computer and use it in GitHub Desktop.
Save eric-burel/db441defe1c4d7da6d9a6c92adb834b5 to your computer and use it in GitHub Desktop.
geeglee-redux-lowdb
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