r/javascript • • Dec 10 '19

Stop using Knex.js

https://medium.com/@gajus/stop-using-knex-js-and-earn-30-bf410349856c
0 Upvotes

20 comments sorted by

View all comments

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:

async function sql(static, ...dynamic) {
    const result = await knex.raw(static.join('?'), dynamic);
    return result.rows;
}