Using Higher-Order Functions to Build Queries in Knex.js

My team has been using Knex.js to build database queries for our latest project. To create increasingly complex queries, we developed a pattern to generate SQL queries using higher-order functions. I’d like to share how we leverage these higher-order functions to make our query builders modular, concise, and very easy to understand.