I'm not sold at all on the benefit of fragments over a query builder. In the case of a small simple query, there's virtually no benefit since the SQL generated by the query builder is going to be obvious. In the case of a complex query, it's going to turn into a probably buggy unreadable mess of string concatenation.
Also you can easily use tagged template literals with Knex by writing a simple wrapper around knex.raw:
async function sql(static, ...dynamic) {
const result = await knex.raw(static.join('?'), dynamic);
return result.rows;
}
2
u/Funwithloops Dec 10 '19
I'm not sold at all on the benefit of fragments over a query builder. In the case of a small simple query, there's virtually no benefit since the SQL generated by the query builder is going to be obvious. In the case of a complex query, it's going to turn into a probably buggy unreadable mess of string concatenation.
Also you can easily use tagged template literals with Knex by writing a simple wrapper around
knex.raw: