Backport database abstraction from croggle-desktop. Tested and works. Tests have become very slow, though