# sqltag

> SQL generation using ES6 tagged template strings

Latest version **1.1.0** (published 2017-01-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install sqltag
pnpm add sqltag
yarn add sqltag
bun add sqltag
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-01-19 |
| First published | 2016-03-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | eknkc |

## Links

- npm: https://www.npmjs.com/package/sqltag
- Repository: https://github.com/eknkc/node-sqltag
- Homepage: https://github.com/eknkc/node-sqltag#readme
- Issues: https://github.com/eknkc/node-sqltag/issues
- npm.io page: https://npm.io/package/sqltag

## Recent versions

- 1.1.0 (latest) — 2017-01-19
- 1.0.2 — 2016-03-29
- 1.0.1 — 2016-03-08
- 1.0.0 — 2016-03-08

## README

# sqltag

SQL generation using ES6 tagged template strings for [mysql](https://www.npmjs.com/package/mysql) / [mysql2](https://www.npmjs.com/package/mysql2) and [postgres](https://www.npmjs.com/package/pq).

## install

```sh
npm install sqltag
```

## basic usage

You can use `${}` syntax for value interpolation.

```js
import SQL from 'sqltag'

mysql.query(SQL`SELECT * FROM users WHERE id = ${15}`)
mysql.query(SQL`SELECT * FROM users WHERE id = ${15} AND age > ${30}`)

pg.query(SQL`SELECT * FROM users WHERE id = ${15}`)
pg.query(SQL`SELECT * FROM users WHERE id = ${15} AND age > ${30}`)
```

## extensions

### raw

Raw values are inserted into resulting SQL as is.

```js
pg.query(SQL`SELECT * FROM ${SQL.raw('users')} WHERE id = ${15}`)
```

### ident

Identifiers are escaped according to database engine. Use for table / field names.

```js
pg.query(SQL`SELECT * FROM ${SQL.ident('users')} WHERE id = ${15}`)
```

### where

```js
pg.query(SQL`SELECT * FROM users ${SQL.where({ id: 15, name: 'foo' })}`)
pg.query(SQL`SELECT * FROM users ${SQL.where({ id: 15, age: SQL.op('>', 30) })}`)
```

### set

```js
pg.query(SQL`UPDATE users ${SQL.set({ name: 'foo', age: 40 })} WHERE id = ${33}`)
```

### values

```js
pg.query(SQL`INSERT INTO users ${SQL.values({ name: 'foo', age: 40 })}`)
pg.query(SQL`INSERT INTO users ${SQL.values([{ name: 'foo', age: 40 }, { name: 'bar', age: 50 }])}`)
```

### spread

```js
pg.query(SQL`SELECT * FROM users WHERE tags IN (${SQL.spread(['foo', 'bar', 'baz'])})`)
```

---
_Source: https://npm.io/package/sqltag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
