How to write a database