You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- for `select *`, `delete` and `insert into tableName values()` without specified columns, the `.*` column authority regex is required
122
134
123
135
```javascript
136
+
constopt= {
137
+
database:'MySQL'
138
+
}
124
139
const { Parser } =require('node-sql-parser');
125
140
constparser=newParser();
126
-
constcolumnList=parser.columnList('SELECT t.id FROM t');
141
+
// opt is optional
142
+
constcolumnList=parser.columnList('SELECT t.id FROM t', opt);
127
143
128
144
console.log(columnList); // ["select::t::id"]
129
145
```
130
146
131
147
### Check the SQL with Authority List
132
148
133
149
- check table authority
134
-
-`whiteListCheck` function check on `table` mode by default
150
+
-`whiteListCheck` function check on `table` mode and `MySQL` database by default
135
151
136
152
```javascript
137
153
const { Parser } =require('node-sql-parser');
138
154
constparser=newParser();
139
155
constsql='UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'
140
156
constwhiteTableList= ['(select|update)::(.*)::(a|b)'] // array that contain multiple authorities
141
-
parser.whiteListCheck(sql, whiteTableList, 'table') // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
157
+
constopt= {
158
+
database:'MySQL',
159
+
type:'table',
160
+
}
161
+
// opt is optional
162
+
parser.whiteListCheck(sql, whiteTableList, opt) // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
constsql='UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'
150
171
constwhiteColumnList= ['select::null::name', 'update::a::id'] // array that contain multiple authorities
151
-
parser.whiteListCheck(sql, whiteColumnList, 'column') // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
172
+
constopt= {
173
+
database:'MySQL',
174
+
type:'column',
175
+
}
176
+
// opt is optional
177
+
parser.whiteListCheck(sql, whiteColumnList, opt) // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
0 commit comments