Socket
Book a DemoInstallSign in
Socket

interpolated-sql

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interpolated-sql

``` const id = 5 const user = await sql`select * from user where id = ${id}` ```

1.0.9
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Make SQL queries using JavaScript tagged literals for parameters.

Example

const id = 5
const user = await sql`select * from user where id = ${id}`

Best used with MySQL, where you can do

const id = await sql`
    insert into user
    set ${{ email: "my@domain.com", role: Role.ADMIN }}
`.insert()

Getting started

Get package

yarn install interpolated-sql

Create your own exec function, that will bind sql creation and connection handling

import {Sql} from "interpolated-sql"
import mysql from "mysql2/promise"

const connection = await mysql.createConnection({
  host: "localhost",
  user: "root",
  database: "test",
})

function exec(parts, ...params) {
  return new Sql(parts, params, () => connection)
}

async function getUsers() {
    return await exec`select * from users`.all()
}

API

see src/sql.ts

FAQs

Package last updated on 04 Jul 2022

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.