Internal API to deal with the database by generating SQL statements.