LowDB – A flat JSON file database
github.com
github.com
Imagine how to fix low-level data corruption on your <Insert your DBMS name> Server.
Unfortunately, in this case, you can't necessarily. One of the issues here is that holding on to handles to multiple collections doesn't do what it seems to, and also doesn't fail. Try running this:
var low = require('lowdb');
var foo = low('foo');
low('bar');
low.on('add', function(collection) {
console.log("this should be foo:", collection);
});
foo.insert({ name: 'foo' }); low('foo').insert({ name: 'foo' })
low('bar').insert({ name: 'bar' })
low('foo').insert({ name: 'foo' })
So never really considered this way of writing or had this bug.But I can see that it's a flaw and unexpected behavior. I'm adding this to the enhancements for the next version.
Thanks for spotting it :)
It fixes some initial flaws/bugs and includes some new features. Also, writing is now fault-tolerant and fully asynchronous.
https://github.com/adewes/blitzdb
It's a serverless, flat-file, document-oriented database which supports indexing and transactions and comes with a built-in ORM layer and a rich query language modeled after MongoDB.
https://github.com/jamesmoss/flywheel
It's no way near as powerful as BlitzDB but I'm slowly adding features to it.
Also benchmarks should be runnable by users :)
The shared global state (see here: https://github.com/typicode/lowdb/blob/481cf43d6b0a52c1cb996...) means that attempting to use more than one collection will cause issues but it will silently succeed. The synchronous file I/O will grind your process to a halt.
If you are serving a mock API for the purpose of local development you might be fine. If you're trying to build any web application at all, this isn't the right choice.
My somewhat ignorant inclination is to suggest that maildir fits this description.
I don't believe maildir would be described as a flat file.
You must go via the actual sqlite process.
On the other hand maildir, composed of multiple ascii compatible text files, can be read by any email client- provided it follows the protocol for reading and writing of files in the maildir spec.
Would you consider MySQL to be a flat file database?
I suppose the other use of "flat file" I've heard is a flat directory with no sub-directories, but I've never heard that applied to a "flat file database".
emp_id emp_fname emp_lname emp_phone1 emp_phone1_type emp_phone2 emp_phone1_type dept_id dept_manager dept_manager_phone1 dept_manager_phone1_type
This approach has all kinds of problems (solved 40+ years ago by Codd and others). Examples: how do you add a third phone for an employee. How do you keep the managers phone from getting out of sync across rows.
I took "flat JSON file database" to mean essentially the same thing. Something like this:
emp_id emp_JSON_object
JSON perhaps solves some issues (e.g. adding a third phone for an employee), but still suffers from most of the issues (e.g. keeping the managers phone from getting out of sync across employees). Plus it suffers from new issues, namely the fact that each JSON object could have its own layout (e.g. one of them could have a third phone) so there is a bunch of parsing overhead compared to say knowing that phone number is at a specific offset on every row.
Flat files doesn't mean neither text file, nor human-readable. Text format, human-readable format is a terrible one to store data, esp. numbers.
https://en.wikipedia.org/wiki/Flat_file_database#Contemporar...
SQLite files are not "flat files" by any definition commonly in use, including the "narrow" and "broader" definitions in that article. (Which, incidentally, is almost entirely unsourced fact claims, which violates Wikipedia's own quality standards.)
What are the definitions in common use that you know? Is it possible there are others you aren't aware of?
http://sqlite.1065341.n5.nabble.com/think-I-need-better-erro...
You handle the result codes you know what to do with, and everything that remains means your program should explode immediately.
If you want a full serialization of the memory to the 'flat' file - then no. It just makes no sense. Yet, a single file databases that's multi-user, mulch-threaded and mult-transaction is all viable.
Also interesting is PouchDB[1], another document storage library. It can be used with Node or in the browser through various backends (like IndexedDB), and can even replicate to CouchDB.
First, thanks for all the interest, it’s quite sudden and unexpected.
Actually, LowDB is an extract from JSON Server, a mocking REST server based on plain JSON (https://github.com/typicode/json-server).
So, basically, it's not meant to be used in critical / intensive applications.
Instead, it's much more a new convenient way to store data in simple use cases.
Regarding file writing, if your database is small or if you don't run a cluster of Node processes, you should be fine.
Regarding benchmark, as someone pointed it out, it’s mainly to show that storing to JSON file is fast enough and to compare operations speed. I agree that it says nothing about other databases and LowDB doesn't try to be the fastest either, just fast enough. By the way, 'npm run benchmark' lets you run it on your machine.
However, keep in mind too that LowDB official release is quite recent so it should be improved over time.
Anyway, thanks for all the feedbacks and I hope you’ll have fun with it :)
upward compatible with mongodb.
Ive also used nedb, which is ok but tends to delete the datastore when it runs out of disk space :P
Could you post an issue on https://github.com/louischatriot/nedb with your environment details and how to reproduce this?
var topFiveSongs = low('songs')
.where({published: true})
.sortBy('views')
.first(5)
.value();
If any db engines figure when the dataset is really large and the limit is really small (no idea what the cutoff would be), if instead of sorting and giving the first five, it instead just looks for the 5 largest/smallest. Anyone have any idea on this?Yes, there are analyzers with the smarts to recognize that indices on particular fields would have helped a given query, but even if the engine's going to auto-create those for you, it then has to scan every row in the table to create the index that first time.
For example, I had a 6 million entry table sitting around, and asked for top 5 rows by an unindexed column. With LIMIT 5 applied it told me:
Sort Method: top-N heapsort Memory: 95kB
Without: Sort Method: quicksort Memory: 577595kB
So if Postgres had to store all the 6 million rows sorted it would need 577 MB of work memory. If (see SHOW work_mem) it was below that that would lead to it writing a lot of temporary files to disk: Sort Method: external merge Disk: 144072kB
Note how Postgres is more wasteful with memory usage than disk writes for temp storage.Generally a query that requires you to do a full table scan on a large table should be used sparingly however.
My usecase would be to keep the data for a website in it and keep the datafiles themselves in repository so it can be backed up there, monitored and possibly merged.
You don't see those around anymore.
I think it's fairly safe to assume that this isn't going to be a wise choice for a server back-end.