new db: merge database.c into directory.c

wip.