This library is partial rewrote of sql-template-strings to add type support to the generate query config
This helper generates a postgres
’s QueryConfig
object for the given query
npm install typed-sql-query
import { sql } from 'typed-sql-query'
interface IResult {
id: number
name: string
}
const filter = sql`WHERE id = ${1}`
const query = sql`SELECT id, name FROM table ${filter};`
const client = await pgPool.connect()
const result = await client.query<IResult>(query)
const query2 = sql`SELECT * FROM table ORDER BY ${sql.raw('created_at')}`
const conditions = [sql`id = ${1}`, sql`id = ${2}`]
const query3 = sql`SELECT * FROM table WHERE ${sql.join(conditions, 'AND')}`
ISC License
Copyright (c) 2016, Felix Frederick Becker (original author)
Copyright (c) 2020, Tan, Shiaw Uen