Skip to content

Commit 2525ef3

Browse files
committed
feat: works in web-woker
1 parent 149b99a commit 2525ef3

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

ast/postgresql.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ export type column_order_list = column_order[];
132132

133133

134134
export type column_order = {
135-
column: expr;
136135
collate: collate_expr;
137136
opclass: ident;
138137
order: 'asc' | 'desc';
@@ -200,10 +199,10 @@ export interface drop_stmt_node {
200199

201200
export interface drop_index_stmt_node {
202201
type: 'drop';
202+
prefix?: 'CONCURRENTLY';
203203
keyword: string;
204204
name: column_ref;
205-
table: table_name;
206-
options?: drop_index_opt;
205+
options?: 'cascade' | 'restrict';
207206
}
208207

209208
export type drop_stmt = AstStatement<drop_stmt_node> | AstStatement<drop_index_stmt_node>;
@@ -233,7 +232,7 @@ export type alter_table_stmt = AstStatement<alter_table_stmt_node>;
233232

234233
export type alter_action_list = alter_action[];
235234

236-
export type alter_action = ALTER_ADD_COLUMN | ALTER_DROP_COLUMN | ALTER_ADD_INDEX_OR_KEY | ALTER_ADD_FULLETXT_SPARITAL_INDEX | ALTER_RENAME_TABLE | ALTER_ALGORITHM | ALTER_LOCK;
235+
export type alter_action = ALTER_ADD_COLUMN | ALTER_ADD_CONSTRAINT | ALTER_DROP_COLUMN | ALTER_ADD_INDEX_OR_KEY | ALTER_ADD_FULLETXT_SPARITAL_INDEX | ALTER_RENAME_TABLE | ALTER_ALGORITHM | ALTER_LOCK;
237236

238237

239238

@@ -256,6 +255,15 @@ export type ALTER_DROP_COLUMN = {
256255

257256

258257

258+
export type ALTER_ADD_CONSTRAINT = {
259+
action: 'add';
260+
create_definitions: create_db_definition;
261+
resource: 'constraint';
262+
type: 'alter';
263+
};
264+
265+
266+
259267
export type ALTER_ADD_INDEX_OR_KEY = {
260268
action: 'add';
261269
type: 'alter';
@@ -352,14 +360,17 @@ export type create_constraint_foreign = {
352360

353361

354362

363+
364+
355365
export type reference_definition = {
356366
definition: cte_column_definition;
357367
table: table_ref_list;
358368
keyword: 'references';
359369
match: 'match full' | 'match partial' | 'match simple';
360-
on_delete?: on_reference;
361-
on_update?: on_reference;
362-
};
370+
on_action: [on_reference?];
371+
} | {
372+
on_action: [on_reference];
373+
};
363374

364375
export type on_reference = { type: 'on delete' | 'on update'; value: reference_option; };
365376

@@ -632,9 +643,11 @@ export type number_or_param = literal_numeric | var_decl | param;
632643
export type limit_clause = { separator: 'offset' | ''; value: [number_or_param | { type: 'origin', value: 'all' }, number_or_param?] };
633644

634645
export interface update_stmt_node {
646+
with?: with_clause;
635647
type: 'update';
636648
table: table_ref_list;
637649
set: set_list;
650+
from?: from_clause;
638651
where?: where_clause;
639652
returning?: returning_stmt;
640653
}
@@ -799,7 +812,7 @@ export type additive_operator = "+" | "-";
799812

800813
export type multiplicative_expr = binary_expr;
801814

802-
export type multiplicative_operator = "*" | "/" | "%";
815+
export type multiplicative_operator = "*" | "/" | "%" | "||";
803816

804817
export type primary = cast_expr | literal | aggr_func | window_func | func_call | case_expr | interval_expr | column_ref | param | or_and_where_expr | var_decl | { type: 'origin'; value: string; };
805818

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ export {
66
util,
77
}
88

9-
if (!global && window) window.global = window
9+
// for web worker
10+
if (typeof self === "object" && self) {
11+
self.NodeSQLParser = {
12+
Parser,
13+
util,
14+
}
15+
}
16+
17+
if (!global && typeof window === "object" && window) window.global = window
1018

11-
if (global && global.window) {
19+
if (typeof global === "object" && global && global.window) {
1220
global.window.NodeSQLParser = {
1321
Parser,
1422
util,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-sql-parser",
3-
"version": "4.6.6",
3+
"version": "4.7.0",
44
"description": "simple node sql parser",
55
"main": "index.js",
66
"types": "types.d.ts",

pegjs/postgresql.pegjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ ALTER_DROP_COLUMN
10251025

10261026
ALTER_ADD_CONSTRAINT
10271027
= KW_ADD __ c:create_constraint_definition {
1028+
/* => {
1029+
action: 'add';
1030+
create_definitions: create_db_definition;
1031+
resource: 'constraint';
1032+
type: 'alter';
1033+
} */
10281034
return {
10291035
action: 'add',
10301036
create_definitions: c,
@@ -1268,6 +1274,10 @@ reference_definition
12681274
}
12691275
}
12701276
/ oa:on_reference {
1277+
/* => {
1278+
on_action: [on_reference];
1279+
}
1280+
*/
12711281
return {
12721282
on_action: [oa]
12731283
}

webpack.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ const getPlugins = (parserName, target, plugins = []) => {
100100
}
101101
return pluginList
102102
}
103-
const getOutput = (target) => ({
103+
const getOutput = (target) => {
104+
const output = {
104105
path: outputPath,
105106
library: '',
106107
libraryTarget: target === 'web' ? 'umd' : 'commonjs',
107108
// this ensures that source maps are mapped to actual files (not "webpack:" uris)
108109
devtoolModuleFilenameTemplate: info => path.resolve(__dirname, info.resourcePath),
109-
})
110+
}
111+
if (target === 'web') output.globalObject = 'this'
112+
return output
113+
}
114+
110115
function buildConfig(parserName, target, entry, plugins) {
111116
const watch = !(isProd || isTest || isCoverage)
112117
return {

0 commit comments

Comments
 (0)