Published by typicode over 8 years ago
Standalone UMD builds are now available.
Check dist
directory after installing lowdb
.
You can also use npmcdn to access them:
http://npmcdn.com/lowdb@^0.12.4/dist/lowdb.min.js
This version uses lodash v4. Lowdb API doesn't change, however you may have to update the lodash methods you're using.
// lowdb v0.11 (with lodash v3)
const low = require('lowdb')
const db = low()
db('posts').where({ title: 'JavaScript' })
// lowdb v0.12 (with lodash v4)
const low = require('lowdb')
const db = low()
// .where() has been replaced by .filter() in lodash v4
// so you need to use the new method
db('posts').filter({ title: 'JavaScript' })
Read lodash breaking changes.
Thank you everyone for all the Pull Requests, feedbacks, ideas, issues, questions... it helped a lot!
This is a major release that adds browser and custom storage support.
low()
method has changed..value()
and db[lodash-method]()
will return a Promise when storage is asynchronous and database is modified.You can find detailed explanations below and in the README
.
For the past few months, there were many requests to support more storage options (LocalStorage, multiple files, MongoDB, ...).
Unfortunatly, despite the fact that there were great ideas, it wasn't possible to extend lowdb and supporting all these storages inside the project would have made it bloated
With this release, it's now possible to tell lowdb how to store data by passing storage.read
and storage.write
functions when creating database.
const myStorage = {
read: (source, serialize) => // ...
// when writing, you can return a Promise for asynchronous operations
// or undefined if syncrhonous
write: (source, object, deserialize) => // ...
}
const source = 'db.json'
const db = low(source, { storage })
Lowdb comes bundled with lowdb/file-sync
, lowdb/file-async
and lowdb/browser
storages.
const format = {
serialize: (obj) => // data
deserialize: (data) => // obj
}
const db = low(source, { format })
If format.serialize
or format.deserialize
functions are set, lowdb will automatically pass them to storage.write
and storage.read
functions.
If storage.write
is asynchronous and returns a Promise, when the database is modified .value()
and db[lodash-method]()
will return a Promise that resolves to the value.
const storage = require('lowdb/file-async')
const db = low('db.json', storage)
const posts = db('posts')
// Return a Promise because writing is asynchronous
posts.push({ title: 'lowdb' }).then(post => /* */)
posts.chain().push({ title: 'lowdb' }).value().then(post => /* */)
// No promise because reading is done in memory and is synchronous
const post = posts.first()
Async mode (don't forget that in async mode, promises will be returned when modifying the database)
// before
const db = low('db.json')
// after
const storage = require('lowdb/file-async')
const db = low('db.json', { storage })
In-memory
// doesn't change
const db = low()
Sync mode
// before
const db = low('db.json', { async: false })
// after
const db = low('db.json', { storage: require('lowdb/file-sync') })
autoSave
option is now an argument in low()
// before
const db = low('db.json', { autoSave: false })
// after
const db = low('db.json', { storage }, false)
low.parse
and low.stringify
has been moved too
// before
low.parse = myParse
low.stringify = myStringify
// after
const db = low('db.json', {
format: { serialize: myStringify, deserialize: myParse }
})
db.save()
has been renamed to db.write()
db.saveSync()
has been removed, use lowdb/file-sync
and call db.write()
Published by typicode over 9 years ago
Because of the way chaining works now in lodash, chain()
must be explicitly called. In other cases, simply calling the method returns the value.
Before
var songs = db('songs').push({ title: 'some song' }).value()
db('songs')
.find({ title: 'low!' })
.assign({ title: 'hi!'})
.value()
After
var songs = db('songs').push({ title: 'some song' })
db('songs')
.chain()
.find({ title: 'low!' })
.assign({ title: 'hi!'})
.value()
Published by typicode about 10 years ago
stringify
and parse
methods #25Published by typicode about 10 years ago
Fix #19
Published by typicode about 10 years ago
Fix #19 EXDEV exception on Windows when running LowDB in another partition than C:/
Published by typicode about 10 years ago
Version 0.4.0 is a complete rewrite of the project in order to achieve:
low.mixin()
.low.mixin()
.low(filename)
During the process, some compromises needed to be made. Here's the list of the breaking changes:
v0.3.x
var low = require('lowdb').load() // loads db.json (by default)
var posts = low('posts').sortBy('title').value()
v0.4.0
var low = require('lowdb')
var db = low('db.json') // loads db.json (must be explicit)
var posts = db('posts').sortBy('title').value()
Removed to simplify code. You can use Watch.js to monitor database object or similar projects.
Also Object.observe()
will be available in Node 0.12, so it's just a matter of time before you can have database object events back.
Removed. Use low()
instead.
var db = low() // same as autoSave: false
var db = low('db.json') // same as autoSave: true and path: 'db.json'
Removed. Short syntax was mainly an experiment. If you need it back, please create an issue.
Underscore.db dependency was removed. You can use Lo-Dash methods to query or manipulate data like push()
, where()
, ... instead of insert()
, get()
, ...
Or you can use mixin()
to add Underscore.db back .
See README for informations about how to extend LowDB.
Published by typicode about 10 years ago
Initial public release.