sql-template-strings
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -5,3 +5,3 @@ { | ||
{ | ||
"name": "Mocha", | ||
"name": "Launch", | ||
"type": "node", | ||
@@ -19,3 +19,3 @@ "request": "launch", | ||
"env": { | ||
"NODE_ENV": "testing" | ||
"NODE_ENV": "development" | ||
}, | ||
@@ -39,2 +39,2 @@ "externalConsole": false, | ||
] | ||
} | ||
} |
declare class SQLStatement { | ||
private strings: string[] | ||
private strings: string[]; | ||
/** The SQL Statement for node-postgres */ | ||
text: string | ||
/** | ||
* The SQL Statement for [node-postgres](https://www.npmjs.com/package/pg) | ||
*/ | ||
text: string; | ||
/** The SQL Statement for mysql */ | ||
sql: string | ||
/** | ||
* The SQL Statement for [mysql](https://www.npmjs.com/package/mysql) | ||
*/ | ||
sql: string; | ||
/** The values to be inserted for the placeholders */ | ||
values: any[] | ||
/** | ||
* The values to be inserted for the placeholders | ||
*/ | ||
values: any[]; | ||
/** The name for postgres prepared statements, if set */ | ||
name: string | ||
/** | ||
* The name for postgres prepared statements, if set | ||
*/ | ||
name: string; | ||
/** Appends a string or another statement */ | ||
append(statement: SQLStatement|string|number): this | ||
/** | ||
* Appends a string or another statement | ||
* | ||
* ```ts | ||
* query.append(SQL`AND genre = ${genre}`).append(' ORDER BY rating') | ||
* query.text // => 'SELECT author FROM books WHERE name = $1 AND author = $2 AND genre = $3 ORDER BY rating' | ||
* query.sql // => 'SELECT author FROM books WHERE name = ? AND author = ? AND genre = ? ORDER BY rating' | ||
* query.values // => ['harry potter', 'J. K. Rowling', 'Fantasy'] ORDER BY rating` | ||
* | ||
* const query = SQL`SELECT * FROM books` | ||
* if (params.name) { | ||
* query.append(SQL` WHERE name = ${params.name}`) | ||
* } | ||
* query.append(SQL` LIMIT 10 OFFSET ${params.offset || 0}`) | ||
* ``` | ||
*/ | ||
append(statement: SQLStatement|string|number): this; | ||
/** Sets the name property of this statement for prepared statements in postgres */ | ||
setName(name: string): this | ||
/** | ||
* Sets the name property of this statement for prepared statements in postgres | ||
* | ||
* ```ts | ||
* pg.query(SQL`SELECT author FROM books WHERE name = ${book}`.setName('my_query')) | ||
* ``` | ||
*/ | ||
setName(name: string): this; | ||
} | ||
/** Template string tag */ | ||
export default function SQL(strings: string[], values: any[]): SQLStatement | ||
/** | ||
* The template string tag | ||
* | ||
* ```ts | ||
* import {SQL} from 'sql-template-strings'; | ||
* | ||
* pg.query(SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`) | ||
* ``` | ||
*/ | ||
export function SQL(strings: string[], values: any[]): SQLStatement; | ||
export default SQL; |
@@ -61,2 +61,4 @@ 'use strict' | ||
module.exports = exports.default = SQL | ||
module.exports = SQL | ||
module.exports.SQL = SQL | ||
module.exports.default = SQL |
{ | ||
"name": "sql-template-strings", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "ES6 tagged template strings for prepared statements with mysql and postgres", | ||
@@ -15,3 +15,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "eslint index.js && mocha" | ||
"test": "eslint index.js && mocha", | ||
"typedoc": "typedoc --module es2015 --target es2015 --includeDeclarations --mode file --readme none --out typedoc index.d.ts" | ||
}, | ||
@@ -35,4 +36,5 @@ "keywords": [ | ||
"eslint": "^2.9.0", | ||
"mocha": "^2.3.3" | ||
"mocha": "^2.3.3", | ||
"typedoc": "^0.4.4" | ||
} | ||
} |
@@ -7,2 +7,4 @@ [![Version](https://img.shields.io/npm/v/sql-template-strings.svg?maxAge=2592000)](https://www.npmjs.com/package/sql-template-strings) | ||
[API Documentation](http://node-sql-template-strings.surge.sh/) | ||
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/pg). | ||
@@ -9,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15382
267
113
3
13