Skip to content

Commit 1e767d7

Browse files
committed
refactor: update type file
1 parent 6de58ef commit 1e767d7

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

ast/postgresql.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
export type start = multiple_stmt | cmd_stmt | crud_stmt;
99

10-
export type cmd_stmt = drop_stmt | create_stmt | truncate_stmt | rename_stmt | call_stmt | use_stmt | alter_stmt | set_stmt | lock_stmt;
10+
export type cmd_stmt = drop_stmt | create_stmt | truncate_stmt | rename_stmt | call_stmt | use_stmt | alter_stmt | set_stmt | lock_stmt | show_stmt;
1111

1212
export type create_stmt = create_table_stmt | create_constraint_trigger | create_extension_stmt | create_index_stmt | create_sequence | create_db_stmt;
1313

@@ -448,6 +448,13 @@ export interface call_stmt_node {
448448

449449
export type call_stmt = AstStatement<call_stmt_node>;
450450

451+
export interface show_stmt_node {
452+
type: 'show';
453+
keyword: 'tables';
454+
}
455+
456+
export type show_stmt = AstStatement<show_stmt_node>;
457+
451458
export interface select_stmt_node extends select_stmt_nake {
452459
parentheses_symbol: true;
453460
}
@@ -486,7 +493,7 @@ export type array_index = { brackets: boolean, number: number };
486493

487494
export type expr_item = expr & { array_index: array_index };
488495

489-
export type column_list_item = { type: 'cast'; expr: expr; symbol: '::'; target: data_type; as?: null; } | { type: 'star_ref'; expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; };
496+
export type column_list_item = { expr: expr; as: null; } | { type: 'cast'; expr: expr; symbol: '::'; target: data_type; as?: null; } | { type: 'star_ref'; expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; };
490497

491498

492499

@@ -547,7 +554,7 @@ export type on_clause = expr;
547554

548555

549556

550-
export type where_clause = expr;
557+
export type where_clause = binary_expr;
551558

552559

553560

@@ -656,9 +663,16 @@ export type interval_expr = { type: 'interval', expr: expr; unit: interval_unit;
656663

657664

658665

666+
667+
659668
export type case_expr = {
660669
type: 'case';
661-
expr?: expr;
670+
expr: null;
671+
// nb: Only the last element is a case_else
672+
args: (case_when_then | case_else)[];
673+
} | {
674+
type: 'case';
675+
expr: expr;
662676
// nb: Only the last element is a case_else
663677
args: (case_when_then | case_else)[];
664678
};
@@ -696,8 +710,6 @@ export type unary_expr = {
696710

697711
export type or_and_where_expr = binary_expr;
698712

699-
export type parentheses_or_expr = binary_expr | or_expr;
700-
701713
export type or_expr = binary_expr;
702714

703715
export type and_expr = binary_expr;
@@ -750,9 +762,11 @@ export type multiplicative_operator = "*" | "/" | "%";
750762

751763
export type primary = cast_expr | literal | aggr_func | window_func | func_call | case_expr | interval_expr | column_ref | param | expr | binary_expr | expr_list | var_decl | { type: 'origin'; value: string; };
752764

765+
export type string_constants_escape = { type: 'origin'; value: string; };
766+
753767

754768

755-
export type column_ref = {
769+
export type column_ref = string_constants_escape | {
756770
type: 'column_ref';
757771
table: ident;
758772
column: column | '*';

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": "3.8.4",
3+
"version": "3.9.0",
44
"description": "simple node sql parser",
55
"main": "index.js",
66
"types": "types.d.ts",

pegjs/postgresql.pegjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ expr_item
17081708
}
17091709
column_list_item
17101710
= c:string_constants_escape {
1711+
// => { expr: expr; as: null; }
17111712
return { expr: c, as: null }
17121713
}
17131714
/ e:expr_item s:KW_DOUBLE_COLON t:data_type __ alias:alias_clause? {
@@ -2605,6 +2606,7 @@ primary
26052606

26062607
string_constants_escape
26072608
= 'E'i"'" __ n:single_char* __ "'" {
2609+
// => { type: 'origin'; value: string; }
26082610
return {
26092611
type: 'origin',
26102612
value: `E'${n.join('')}'`

0 commit comments

Comments
 (0)