-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite-parser.d.ts
More file actions
158 lines (142 loc) · 3.79 KB
/
sqlite-parser.d.ts
File metadata and controls
158 lines (142 loc) · 3.79 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
declare module 'sqlite-parser' {
export type ExpressionNode =
| LiteralNode
| VariableNode
| BinaryOperationNode
| ExpressionListNode
type TransactionStatementNode = {
type: 'statement'
variant: 'transaction'
action: 'begin' | 'commit' | 'rollback'
defer?: 'deferred' | 'immediate' | 'exclusive' // only for 'begin'
}
type LiteralNode = {
type: 'literal'
variant: 'string' | 'decimal' | 'integer' | 'boolean' | 'null'
value: string | number | boolean | null
normalized?: string
}
export type ExpressionListNode = {
type: 'expression'
variant: 'list'
expression: ExpressionNode[]
}
export type BinaryOperationNode = {
type: 'expression'
format: 'binary'
variant: 'operation'
operation: '=' | '!=' | '<' | '<=' | '>' | '>=' | 'AND' | 'OR' // extend as needed
left: ExpressionNode
right: ExpressionNode
}
export type VariableNode = {
type: 'variable'
format: 'numbered' | 'named'
name: string // e.g. "?" or ":id"
}
export type TableInsertTargetNode = {
type: 'identifier'
variant: 'expression'
format: 'table'
name: string
columns: ColumnIdentifierNode[]
}
export type AssignmentNode = {
type: 'assignment'
target: ColumnIdentifierNode
value: ExpressionNode
}
type PragmaStatementNode = {
type: 'statement'
variant: 'pragma'
target: {
type: 'identifier'
variant: 'pragma'
name: string
}
args?: ExpressionNode | ExpressionListNode
}
export type InsertStatementNode = {
type: 'statement'
variant: 'insert'
action: 'insert'
into: TableInsertTargetNode
result: ExpressionListNode[]
}
export type DeleteStatementNode = {
type: 'statement'
variant: 'delete'
from: TableIdentifierNode
where?: ExpressionNode[]
}
export type UpdateStatementNode = {
type: 'statement'
variant: 'update'
table: TableIdentifierNode
set: AssignmentNode[]
where?: ExpressionNode[]
}
export type StatementNode =
| SelectStatementNode
| InsertStatementNode
| DeleteStatementNode
| UpdateStatementNode
| PragmaStatementNode
| TransactionStatementNode
/** A column identifier, e.g. { type: "identifier", variant: "column", name: "pants" } */
export interface ColumnIdentifierNode {
type: 'identifier'
variant: 'column'
name: string
}
/** A table identifier, e.g. { type: "identifier", variant: "table", name: "laundry" } */
export interface TableIdentifierNode {
type: 'identifier'
variant: 'table'
name: string
}
export interface SelectStatementNode {
type: 'statement'
variant: 'select'
/** the list of selected columns (in your example, one ColumnIdentifierNode) */
result: ColumnIdentifierNode[]
/** the FROM clause (in your example, a single TableIdentifierNode) */
from: TableIdentifierNode
[extraField: string]: any
}
export interface StatementListNode {
type: 'statement'
variant: 'list'
statement: StatementNode[]
[extraField: string]: any
}
/**
* Parse a SQL string and synchronously return its AST.
* @param source SQL code to parse
* @param options (optional) parser options
* @returns a StatementListNode
*/
function sqliteParser(source: string, options?: any): StatementListNode
/**
* Parse a SQL string asynchronously via callback.
* @param source SQL code to parse
* @param options (optional) parser options
* @param callback callback(err, resultAST)
*/
function sqliteParser(
source: string,
options: any,
callback: (err: Error | null, result?: StatementListNode) => void
): void
namespace sqliteParser {
/** Create a streaming parser transform (for Node streams). */
function createParser(): any
/** Create a stitcher (single-node transform) for streaming. */
function createStitcher(): any
/** Package name. */
const NAME: string
/** Package version (string placeholder). */
const VERSION: string
}
export default sqliteParser
}