write to the database