-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathindex.d.ts
74 lines (65 loc) · 1.97 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
export class SQLStatement {
private strings: string[]
/**
* The SQL Statement for [node-postgres](https://www.npmjs.com/package/pg)
*/
text: string
/**
* The SQL Statement for [Sequelize](https://www.npmjs.com/package/sequelize)
*/
query: 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 name for postgres prepared statements, if set
*/
name: string
/**
* 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
*
* ```ts
* pg.query(SQL`SELECT author FROM books WHERE name = ${book}`.setName('my_query'))
* ```
*/
setName(name: string): this
/**
* Use a prepared statement with Sequelize.
* Makes `query` return a query with `$n` syntax instead of `?` and switches the `values` key name to `bind`
* If omitted, `value` defaults to `true`.
*/
useBind(value?: boolean): this
}
/**
* 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: any, ...values: any[]): SQLStatement
export default SQL