forked from nearform/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL.d.ts
103 lines (88 loc) · 2.99 KB
/
SQL.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/** A tagged template containing strings and values */
interface StatementLike {
strings: string[]
values: any[]
}
interface StatementOptions {
unsafe?: boolean
}
/**
* An SQL statement tagged template
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
*/
declare class SqlStatement implements StatementLike {
constructor (strings: string[], values: any[])
/** The string components of this tagged template */
strings: string[]
/** The value components of this tagged template */
values: any[]
/**
* Safely glues multiple SQL statements together
* @param pieces the statements to be glued
* @param separator the glue separator placed between each statement
* @example
* const sql = SQL`SELECT id FROM customers WHERE `
* sql.glue([
* sql,
* SQL`email = ${email}`
* ])
*/
glue (pieces: StatementLike[], separator: string): SqlStatement
/**
* Safely glues multiple SQL statements together
* @param pieces the statements to be glued
* @param separator the glue separator placed between each statement
* @example
* SQL.glue([
* SQL`SELECT id FROM customers WHERE `,
* SQL`email = ${email}`
* ])
* )
*/
static glue (pieces: StatementLike[], separator: string): SqlStatement
/**
* Generates a PostgreSQL or MySQL statement string from this statement's strings and values
* @param type the type of statement string to be generated
*/
generateString (type?: 'pg' | 'mysql'): string
/** Returns a formatted but unsafe statement of strings and values, useful for debugging */
get debug (): string
/** Returns a formatted statement suitable for use in PostgreSQL */
get text (): string
/** Returns a formatted statement suitable for use in MySQL */
get sql (): string
/**
* Appends another statement onto this statement
* @param statement a statement to be appended onto this existing statement
* @param options allows disabling the safe template escaping while appending
* @example
* SQL`UPDATE users SET name = ${username}, email = ${email} `
* .append(SQL`SET ${dynamicName} = '2'`, { unsafe: true })
* .append(SQL`WHERE id = ${userId}`)
*/
append (statement: StatementLike, options?: StatementOptions): SqlStatement
}
declare namespace SQL {
export { SqlStatement }
/**
* Safely glues multiple SQL statements together
* @param pieces the statements to be glued
* @param separator the glue separator placed between each statement
* @example
* SQL.glue([
* SQL`SELECT id FROM customers WHERE `,
* SQL`email = ${email}`
* ])
* )
*/
export function glue (pieces: StatementLike[], separator: string): SqlStatement
}
/**
* Create an SQL statement tagged template
* @param strings template literal string components
* @param values template literal value components
* @example
* SQL`SELECT id FROM customers WHERE name = ${userInput}`
*/
declare function SQL (strings: any, ...values: any[]): SqlStatement
export = SQL