Skip to content

Commit

Permalink
feat: works in web-woker
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed May 22, 2023
1 parent 149b99a commit 2525ef3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
29 changes: 21 additions & 8 deletions ast/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export type column_order_list = column_order[];


export type column_order = {
column: expr;
collate: collate_expr;
opclass: ident;
order: 'asc' | 'desc';
Expand Down Expand Up @@ -200,10 +199,10 @@ export interface drop_stmt_node {

export interface drop_index_stmt_node {
type: 'drop';
prefix?: 'CONCURRENTLY';
keyword: string;
name: column_ref;
table: table_name;
options?: drop_index_opt;
options?: 'cascade' | 'restrict';
}

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

export type alter_action_list = alter_action[];

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;
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;



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



export type ALTER_ADD_CONSTRAINT = {
action: 'add';
create_definitions: create_db_definition;
resource: 'constraint';
type: 'alter';
};



export type ALTER_ADD_INDEX_OR_KEY = {
action: 'add';
type: 'alter';
Expand Down Expand Up @@ -352,14 +360,17 @@ export type create_constraint_foreign = {





export type reference_definition = {
definition: cte_column_definition;
table: table_ref_list;
keyword: 'references';
match: 'match full' | 'match partial' | 'match simple';
on_delete?: on_reference;
on_update?: on_reference;
};
on_action: [on_reference?];
} | {
on_action: [on_reference];
};

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

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

export interface update_stmt_node {
with?: with_clause;
type: 'update';
table: table_ref_list;
set: set_list;
from?: from_clause;
where?: where_clause;
returning?: returning_stmt;
}
Expand Down Expand Up @@ -799,7 +812,7 @@ export type additive_operator = "+" | "-";

export type multiplicative_expr = binary_expr;

export type multiplicative_operator = "*" | "/" | "%";
export type multiplicative_operator = "*" | "/" | "%" | "||";

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; };

Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ export {
util,
}

if (!global && window) window.global = window
// for web worker
if (typeof self === "object" && self) {
self.NodeSQLParser = {
Parser,
util,
}
}

if (!global && typeof window === "object" && window) window.global = window

if (global && global.window) {
if (typeof global === "object" && global && global.window) {
global.window.NodeSQLParser = {
Parser,
util,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-sql-parser",
"version": "4.6.6",
"version": "4.7.0",
"description": "simple node sql parser",
"main": "index.js",
"types": "types.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,12 @@ ALTER_DROP_COLUMN

ALTER_ADD_CONSTRAINT
= KW_ADD __ c:create_constraint_definition {
/* => {
action: 'add';
create_definitions: create_db_definition;
resource: 'constraint';
type: 'alter';
} */
return {
action: 'add',
create_definitions: c,
Expand Down Expand Up @@ -1268,6 +1274,10 @@ reference_definition
}
}
/ oa:on_reference {
/* => {
on_action: [on_reference];
}
*/
return {
on_action: [oa]
}
Expand Down
9 changes: 7 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ const getPlugins = (parserName, target, plugins = []) => {
}
return pluginList
}
const getOutput = (target) => ({
const getOutput = (target) => {
const output = {
path: outputPath,
library: '',
libraryTarget: target === 'web' ? 'umd' : 'commonjs',
// this ensures that source maps are mapped to actual files (not "webpack:" uris)
devtoolModuleFilenameTemplate: info => path.resolve(__dirname, info.resourcePath),
})
}
if (target === 'web') output.globalObject = 'this'
return output
}

function buildConfig(parserName, target, entry, plugins) {
const watch = !(isProd || isTest || isCoverage)
return {
Expand Down

0 comments on commit 2525ef3

Please sign in to comment.