typed-sql-query
v1.2.0
Published
typed sql template string helper
Downloads
47
Maintainers
Readme
typed-sql-query
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
Install:
npm install typed-sql-query
Usage:
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')}`
License:
ISC License
Copyright (c) 2016, Felix Frederick Becker (original author) Copyright (c) 2020, Tan, Shiaw Uen