Socket
Socket
Sign inDemoInstall

typed-sql-query

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typed-sql-query

typed sql template string helper


Version published
Maintainers
1
Install size
10.2 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 09 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc