Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I disagree. Knex isn't an abstraction over SQL itself, as much as an abstraction over the tedious process of writing literal strings, which let's the developer treat SQL queries as code.

My process is generally - write SQL to find the best query, then convert the SQL to Knex for integration.

As a simple example, say you are making a simple query to the db, but in some edge cases you need another column to be selected. Knex lets you do this:

    let query = KNEX("table").select("col_1")
    
    if(weirdCondition) {
      query = query.select("col_2")
    }

    const rows = await query
Which naturally compiles into either

    SELECT col_1 FROM table
or

    SELECT col_1, col_2 FROM table


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: