typed-sql-query
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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

Package Sidebar

Install

npm i typed-sql-query

Weekly Downloads

1

Version

1.2.0

License

ISC

Unpacked Size

10.4 kB

Total Files

10

Last publish

Collaborators

  • shiawuen