Closed ohenepee closed 7 years ago
Perhaps you can use jsondown or sqldown with SQLite? If you want to combine backends, see cachedown or level-live-cache.
Awesome!!! Thanks a bunch
If you want to use memdb still, you could import / export data on demand like this:
var fs = require('fs')
var JSONStream = require('JSONStream')
var WriteStream = require('level-ws').WriteStream
function store (db, file, cb) {
db.createReadStream()
.pipe(JSONStream.stringify())
.pipe(fs.createWriteStream(file))
.on('finish', cb)
}
function restore (db, file, cb) {
fs.createReadStream(file)
.pipe(JSONStream.parse([true]))
.pipe(WriteStream(db))
.on('end', cb)
}
Yeah I think this approach is much efficient and performance since jsondown isn't streaming and sqldown is for me like "really?". Also both seem to have been abandoned, my guess.
it looks like the above example would save the entire contents of the DB to a .json file every save? is that correct? are there examples of being able to save just a single batch or put to disk rather than the entire DB, assuming levelDOWN is not an option.
it looks like the above example would save the entire contents of the DB to a .json file every save? is that correct?
Yep, that's correct.
are there examples of being able to save just a single batch or put to disk rather than the entire DB, assuming levelDOWN is not an option.
You could tweak the above store
and restore
functions to just stream stuff you're interested in, that could be an option. But I don't know anything about storing/restoring single batches or puts. Another thing you can do is to use sublevels e.g. subleveldown and call store/restore on single sublevels.
I want to use levelgraph, which requires levelup, which in-turn requires either leveldown/memdown/level.js... Unfortunately the platform is mobile without an IndexedDB (Fuse to be precise ) so I can't use level.js. So I was thinking there was a way to work with memdown and write the database to the filesystem, then load it anytime I need it