Convert all database code to use the Knex SQL builder