v2.0.0
I rewrote the project so that the tag function now returns an instance of SQLStatement
. This has a method append()
that allows to append another SQLStatement
or a simple string to the statement to build complex queries.
const query = SQL`SELECT * FROM books`
if (params.name) {
query.append(SQL` WHERE name = ${params.name}`)
}
You can also set the name of the query without Object.assign()
through .setName()
.
I also updated the docs, rewrote the tests, added CI and TypeScript definitions.
Breaking Change
The append()
method also allows to append raw values (like SQL.raw()
did previously). I removed SQL.raw()
because it would have complicated the implementation for keeping a duplicate, mostly unused feature. You can upgrade your code like this
db.query(SQL`SELECT * FROM ${SQL.raw(table)} WHERE name = ${name}`))
// becomes
db.query(SQL`SELECT * FROM `.append(table).append(SQL` WHERE name = ${name}`))
or simply stay at 1.x, no one will blame you :)