SQL
A simple SQL injection protection module that allows you to use ES6 template strings for escaped statements. Works with pg library.

- Install
- Usage
- Methods
- append
- glue
- How it works?
- Testing, linting, & coverage
- Benchmark
- License
Install
npm install @nearform/sql
Usage
const SQL = require('@nearform/sql')
const db = connectDB()
const username = 'user'
const email = 'user@email.com'
const password = 'Password1'
const sql = SQL`
INSERT INTO users (username, email, password)
VALUES (${username},${email},${password})
`
db.query(sql)
Methods
append(statement)
const username = 'user1'
const email = 'user1@email.com'
const userId = 1
const sql = SQL`UPDATE users SET name = ${username}, email = ${email} `
sql.append(SQL`WHERE id = ${userId}`)
glue(pieces, separator)
const username = 'user1'
const email = 'user1@email.com'
const userId = 1
const sql = SQL` UPDATE users SET `
const updates = []
updates.push(SQL`name = ${username}`)
updates.push(SQL`email = ${email}`)
sql.append(sql.glue(updates, ' , '))
sql.append(SQL`WHERE id = ${userId}`)
How it works?
The SQL template string tag parses query and returns an objects that's understandable by pg library:
const username = 'user'
const email = 'user@email.com'
const password = 'Password1'
const sql = SQL`INSERT INTO users (username, email, password) VALUES (${username},${email},${password})`
sql.text
sql.values
Testing, linting, & coverage
This module can be tested and reported on in a variety of ways...
npm run test
npm run test:security
npm run coverage
npm run lint
Benchmark
Find more about @nearform/sql
speed here
License
Copyright nearForm 2018. Licensed under
Apache 2.0