views:

103

answers:

3

I am looking for a database library that can be used within an editor to replace a custom document format. In my case the document would contain a functional program.

I want application data to be persistent even while editing, so that when the program crashes, no data is lost. I know that all databases offer that.

On top of that, I want to access and edit the document from multiple threads, processes, possibly even multiple computers.

Format: a simple key/value database would totally suffice. SQL usually needs to be wrapped, and if I can avoid pulling in a heavy ORM dependency, that would be splendid.

Revisions: I want to be able to roll back changes up to the first change to the document that has ever been made, not only in one session, but also between sessions/program runs.

I need notifications: each process must be able to be notified of changes to the document so it can update its view accordingly.

I see these requirements as rather basic, a foundation to solve the usual tough problems of an editing application: undo/redo, multiple views on the same data. Thus, the database system should be lightweight and undemanding.

Thank you for your insights in advance :)

+1  A: 

Berkeley DB is an undemanding, light-weight key-value database that supports locking and transactions. There are bindings for it in a lot of programming languages, including C++ and python. You'll have to implement revisions and notifications yourself, but that's actually not all that difficult.

Michiel Buddingh'
I know Berkeley DB since a long time, and I guess that's the best answer so far, although I don't like it ;) I started a prototype that goes pretty well so far. As you proposed, the additional features were easy to implement.
paniq
A: 

Check out ZODB. It doesn't have notifications built in, so you would need a messaging system there (since you may use separate computers). But it has transactions, you can roll back forever (unless you pack the database, which removes earlier revisions), you can access it directly as an integrated part of the application, or it can run as client/server (with multiple clients of course), you can have automatic persistency, there is no ORM, etc.

It's pretty much Python-only though (it's based on Pickles).

http://en.wikipedia.org/wiki/Zope_Object_Database

http://pypi.python.org/pypi/ZODB3

http://wiki.zope.org/ZODB/guide/index.html

http://wiki.zope.org/ZODB/Documentation

Lennart Regebro
+1  A: 

It might be a bit more power than what you ask for, but You should definitely look at CouchDB.

It is a document database with "document" being defined as a JSON record. It stores all the changes to the documents as revisions, so you instantly get revisions. It has powerful javascript based view engine to aggregate all the data you need from the database.

All the commits to the database are written to the end of the repository file and the writes are atomic, meaning that unsuccessful writes do not corrupt the database.

Another nice bonus You'll get is easy and flexible replication and of your database.

See the full feature list on their homepage

On the minus side (depending on Your point of view) is the fact that it is written in Erlang and (as far as I know) runs as an external process...

I don't know anything about notifications though - it seems that if you are working with replicated databases, the changes are instantly replicated/synchronized between databases. Other than that I suppose you should be able to roll your own notification schema...

Roland Tepp
I am not so sure about CouchDB storing revisions. That seems to be only short-term, in order to allow for view consistency and lock-free queries. The revisions get purged from time to time, I think.
Thilo
I had no such impression from anywhere in the documentation... To be completely honest - I've not yet had any real-world experience with CouchDB and thus could not back up any such claims...
Roland Tepp