sql-template-strings
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "sql-template-strings", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Allows you to use ES6 tagged template strings for prepared statements with mysql and postgres", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,2 +9,3 @@ A simple yet powerful module to allow you to use ES6 tagged template strings for prepared/escaped statements in [mysql](https://www.npmjs.com/package/mysql) / [mysql2](https://www.npmjs.com/package/mysql2) and [postgres](https://www.npmjs.com/package/pq) (and with simple, I mean only 7 lines of code!). | ||
// mysql (for mysql2 prepared statements, just replace query with execute): | ||
mysql.query('SELECT author FROM books WHERE name = ?', [book]); | ||
@@ -14,2 +15,3 @@ // is equivalent to | ||
// postgres: | ||
pg.query('SELECT author FROM books WHERE name = $1', [book]); | ||
@@ -19,3 +21,2 @@ // is equivalent to | ||
``` | ||
For mysql2 prepared statements, just replace `query` with `execute`. | ||
This might not seem like a big deal, but when you do an INSERT with a lot columns writing all the placeholders becomes a nightmare: | ||
@@ -28,3 +29,3 @@ | ||
); | ||
// is equivalent to | ||
// is better written as | ||
db.query(SQL` | ||
@@ -31,0 +32,0 @@ INSERT |
3124
49