-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathsimple-statements.ne
More file actions
186 lines (147 loc) · 6.81 KB
/
simple-statements.ne
File metadata and controls
186 lines (147 loc) · 6.81 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
@lexer lexerAny
@include "base.ne"
@include "expr.ne"
simplestatements_all
-> simplestatements_start_transaction
| simplestatements_commit
| simplestatements_rollback
| simplestatements_tablespace
| simplestatements_set
| simplestatements_show
| simplestatements_begin
array_of[EXP] -> $EXP (%comma $EXP {% last %}):* {% ([head, tail]) => {
return [unwrap(head), ...(tail.map(unwrap) || [])];
} %}
# https://www.postgresql.org/docs/12/sql-start-transaction.html
simplestatements_start_transaction -> (kw_start kw_transaction) {% x => track(x, { type: 'start transaction' }) %}
# https://www.postgresql.org/docs/12/sql-commit.html
simplestatements_commit -> kw_commit {% x => track(x, { type: 'commit' }) %}
# https://www.postgresql.org/docs/12/sql-rollback.html
simplestatements_rollback -> kw_rollback {% x => track(x, { type: 'rollback' }) %}
simplestatements_tablespace -> kw_tablespace word {% x => track(x, {
type: 'tablespace',
tablespace: asName(x[1]),
}) %}
simplestatements_set -> kw_set (simplestatements_set_simple
| simplestatements_set_timezone
| simplestatements_set_session
| simplestatements_set_transaction_snapshot
| simplestatements_set_transaction) {% last %}
simplestatements_set_timezone -> kw_time kw_zone simplestatements_set_timezone_val {% x => track(x, { type: 'set timezone', to: x[2] }) %}
simplestatements_set_timezone_val
-> (string | int) {% x => track(x, { type: 'value', value: unwrap(x[0]) }) %}
| kw_local {% x => track(x, { type: 'local'}) %}
| %kw_default {% x => track(x, { type: 'default'}) %}
| kw_interval string kw_hour %kw_to kw_minute {% x => track(x, { type: 'interval', value: unbox(x[1]) }) %}
simplestatements_set_simple -> ident (%op_eq | %kw_to) simplestatements_set_val {% x => track(x, {
type: 'set',
variable: asName(x[0]),
set: unbox(x[2]),
}) %}
simplestatements_set_val
-> simplestatements_set_val_raw {% unwrap %}
| %kw_default {% x => track(x, {type: 'default'}) %}
| simplestatements_set_val_raw (comma simplestatements_set_val_raw):+ {% x => track(x, {
type: 'list',
values: [x[0], ...(x[1] || [])]
}) %}
simplestatements_set_val_raw
-> (string | int) {% x => track(x, { type: 'value', value: unwrap(x) }) %}
| (%word | %kw_on | %kw_true | %kw_false) {% x => track(x, { type: 'identifier', name: unwrap(x).value }) %}
simplestatements_show -> kw_show ident {% x => track(x, { type: 'show', variable: asName(x[1]) }) %}
# https://www.postgresql.org/docs/current/sql-set-transaction.html
simplestatements_set_transaction_snapshot
-> kw_transaction kw_snapshot ident {% x => track(x, { type: 'set transaction snapshot', snapshotId: asName(x[2]) }) %}
simplestatements_set_session
-> kw_session kw_characteristics %kw_as kw_transaction
(simplestatements_begin_isol | simplestatements_begin_writ | simplestatements_begin_def):* {%
x => track(x, {
type: 'set session characteristics as transaction',
...x[4].reduce((a: any, b: any) => ({...unwrap(a), ...unwrap(b)}), {}),
})
%}
simplestatements_set_transaction
-> kw_transaction (simplestatements_begin_isol | simplestatements_begin_writ | simplestatements_begin_def):* {%
x => track(x, {
type: 'set transaction',
...x[1].reduce((a: any, b: any) => ({...unwrap(a), ...unwrap(b)}), {}),
})
%}
# https://www.postgresql.org/docs/current/sql-createschema.html
create_schema -> (%kw_create kw_schema) kw_ifnotexists:? ident {% x => track(x, {
type: 'create schema',
name: asName(x[2]),
... !!x[1] ? { ifNotExists: true } : {},
}) %}
# https://www.postgresql.org/docs/13/plpgsql-errors-and-messages.html
raise_statement -> kw_raise
(%word {% anyKw('debug', 'log', 'info', 'notice', 'warning', 'exception') %}):?
string
(comma expr_list_raw {% last %}):?
raise_using:? {% x => track(x, {
type: 'raise',
format: toStr(x[2]),
...x[1] && { level: toStr(x[1]) },
...x[3] && x[3].length && { formatExprs: x[3] },
...x[4] && x[4].length && { using: x[4] },
}) %}
raise_using -> %kw_using array_of[raise_using_one] {% last %}
raise_using_one -> raise_using_what %op_eq expr {% x => track(x, {
type: toStr(x[0]),
value: x[2],
}) %}
raise_using_what -> %kw_table
| %word {% anyKw('message',
'detail',
'hint',
'errcode',
'column',
'constraint',
'datatype',
'schema') %}
# https://www.postgresql.org/docs/13/sql-comment.html
comment_statement -> kw_comment %kw_on comment_what %kw_is string {% x => track(x, {
type: 'comment',
comment: unbox(last(x)),
on: unwrap(x[2]),
}) %}
comment_what -> comment_what_col | comment_what_nm
comment_what_nm -> (%kw_table
| kw_materialized kw_view
| %word {% anyKw('database', 'index', 'trigger', 'type', 'view') %})
qualified_name {% x => track(x, {
type: toStr(x[0]),
name: x[1],
}) %}
comment_what_col -> kw_column qcolumn {% x => track(x, {
type: 'column',
column: last(x),
}) %}
# https://www.postgresql.org/docs/current/sql-begin.html
simplestatements_begin -> kw_begin
(kw_transaction | kw_work):?
(simplestatements_begin_isol | simplestatements_begin_writ | simplestatements_begin_def):* {%
x => track(x, {
type: 'begin',
...x[2].reduce((a: any, b: any) => ({...unwrap(a), ...unwrap(b)}), {}),
})
%}
simplestatements_begin_isol -> (kw_isolation kw_level)
( kw_serializable
| (word {% kw('repeatable') %}) kw_read
| kw_read (word {% kw('committed') %})
| kw_read (word {% kw('uncommitted') %})
)
{% x => track(x, {
isolationLevel: toStr(x[1], ' '),
}) %}
simplestatements_begin_writ
-> (kw_read kw_write | kw_read %kw_only)
{% x => track(x, {
writeable: toStr(x, ' '),
}) %}
simplestatements_begin_def
-> %kw_not:? %kw_deferrable
{% x => track(x, {
deferrable: !x[0]
}) %}