55⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔
66*/
77
8- export type start = multiple_stmt | cmd_stmt | crud_stmt ;
8+ export type start = multiple_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 | show_stmt | deallocate_stmt ;
10+ export type cmd_stmt = drop_stmt | create_stmt | declare_stmt | truncate_stmt | rename_stmt | call_stmt | use_stmt | alter_stmt | set_stmt | lock_stmt | show_stmt | deallocate_stmt | grant_revoke_stmt | if_else_stmt | raise_stmt | execute_stmt | for_loop_stmt ;
1111
12- export type create_stmt = create_table_stmt | create_constraint_trigger | create_extension_stmt | create_index_stmt | create_sequence | create_db_stmt | create_domain_stmt | create_type_stmt | create_view_stmt ;
12+ export type create_stmt = create_table_stmt | create_constraint_trigger | create_extension_stmt | create_index_stmt | create_sequence | create_db_stmt | create_domain_stmt | create_type_stmt | create_view_stmt | create_aggregate_stmt ;
1313
1414export type alter_stmt = alter_table_stmt | alter_schema_stmt | alter_domain_type_stmt | alter_function_stmt | alter_aggregate_stmt ;
1515
@@ -77,6 +77,51 @@ export type create_view_stmt = {
7777
7878export type create_view_stmt = AstStatement < create_view_stmt > ;
7979
80+ export type create_aggregate_opt_required = { type : string ; symbol : '=' ; value : expr ; } [ ] ;
81+
82+ export type create_aggregate_opt_optional = { type : string ; symbol : '=' ; value : ident | expr ; } ;
83+
84+ export type create_aggregate_opts = create_aggregate_opt_optional [ ] ;
85+
86+ export type create_aggregate_stmt = {
87+ type : 'create' ,
88+ keyword : 'aggregate' ,
89+ replace ?: 'or replace' ,
90+ name : table_name ,
91+ args ?: aggregate_signature ,
92+ options : create_aggregate_opt_optional [ ]
93+ }
94+
95+ export type create_aggregate_stmt = AstStatement < create_aggregate_stmt > ;
96+
97+ export type column_data_type = { column : column_ref ; definition : data_type ; } ;
98+
99+ export type column_data_type_list = column_data_type [ ] ;
100+
101+ export type func_returns = { type : "returns" ; keyword ?: "setof" ; expr : data_type ; } | { type : "returns" ; keyword ?: "table" ; expr : column_data_type_list ; } ;
102+
103+ export type declare_variable_item = { keyword : 'variable' ; name : string , constant ?: string ; datatype : data_type ; collate ?: collate ; not_null ?: string ; default ?: { type : 'default' ; keyword : string ; value : literal | expr ; } ; } ;
104+
105+ export type declare_variables = declare_variable_item [ ] ;
106+
107+ export type declare_stmt = { type : 'declare' ; declare : declare_variable_item [ ] ; }
108+
109+ export type declare_stmt = AstStatement < declare_stmt > ;
110+
111+ export type create_func_opt = literal_string | { type : 'as' ; begin ?: string ; declare ?: declare_stmt ; expr : multiple_stmt ; end ?: string ; symbol : string ; } | literal_numeric | { type : "set" ; parameter : ident_name ; value ?: { prefix : string ; expr : expr } } ;
112+
113+ export type create_function_stmt = {
114+ type : 'create' ;
115+ replace ?: string ;
116+ name : { schema ?: string ; name : string } ;
117+ args ?: alter_func_args ;
118+ returns ?: func_returns ;
119+ keyword : 'function' ;
120+ options ?: create_func_opt [ ] ;
121+ }
122+
123+ export type create_function_stmt = AstStatement < create_function_stmt > ;
124+
80125export type create_type_stmt = {
81126 type : 'create' ,
82127 keyword : 'type' ,
@@ -230,6 +275,8 @@ export type column_format = { type: 'column_format'; value: 'fixed' | 'dynamic'
230275
231276export type storage = { type : 'storage' ; value : 'disk' | 'memory' } ;
232277
278+ export type default_arg_expr = { type : 'default' ; keyword : string , value : literal | expr ; } ;
279+
233280export type default_expr = { type : 'default' ; value : literal | expr ; } ;
234281
235282export type drop_index_opt = ( ALTER_ALGORITHM | ALTER_LOCK ) [ ] ;
@@ -269,7 +316,7 @@ export type aggregate_signature = { name: ”*“ } | alter_func_args;
269316
270317export type alter_func_argmode = ignore ;
271318
272- export type alter_func_arg_item = { mode ?: string ; name ?: string ; type : data_type ; } ;
319+ export type alter_func_arg_item = { mode ?: string ; name ?: string ; type : data_type ; default : default_arg_expr ; } ;
273320
274321export type alter_func_args = alter_func_arg_item [ ] ;
275322
@@ -463,7 +510,8 @@ export type reference_option = { type: 'function'; name: string; args: expr_list
463510
464511export type create_constraint_trigger = {
465512 type : 'create' ;
466- constraint : string ;
513+ replace ?: string ;
514+ constraint ?: string ;
467515 location : 'before' | 'after' | 'instead of' ;
468516 events : trigger_event_list ;
469517 table : table_name ;
@@ -472,7 +520,7 @@ export type create_constraint_trigger = {
472520 for_each ?: trigger_for_row ;
473521 when ?: trigger_when ;
474522 execute : {
475- keyword : 'execute procedure' ;
523+ keyword : string ;
476524 expr : proc_func_call ;
477525 } ;
478526 constraint_type : 'trigger' ;
@@ -562,6 +610,114 @@ export interface deallocate_stmt_node {
562610
563611export type deallocate_stmt = AstStatement < deallocate_stmt_node > ;
564612
613+ export interface origin_str_stmt {
614+ type : 'origin' ;
615+ value : string ;
616+ }
617+
618+ export type priv_type_table = origin_str_stmt ;
619+
620+ export type priv_type_sequence = origin_str_stmt ;
621+
622+ export type priv_type_database = origin_str_stmt ;
623+
624+ export type prive_type_all = origin_str_stmt ;
625+
626+ export type prive_type_usage = origin_str_stmt | prive_type_all ;
627+
628+ export type prive_type_execute = origin_str_stmt | prive_type_all ;
629+
630+ export type priv_type = priv_type_table | priv_type_sequence | priv_type_database | prive_type_usage | prive_type_execute ;
631+
632+ export type priv_item = { priv : priv_type ; columns : column_ref_list ; } ;
633+
634+ export type priv_list = priv_item [ ] ;
635+
636+ export type object_type = origin_str_stmt ;
637+
638+ export type priv_level = { prefix : string ; name : string ; } ;
639+
640+ export type priv_level_list = priv_level [ ] ;
641+
642+ export type user_or_role = origin_str_stmt ;
643+
644+ export type user_or_role_list = user_or_role [ ] ;
645+
646+ export type with_grant_option = origin_str_stmt ;
647+
648+ export type with_admin_option = origin_str_stmt ;
649+
650+ export type grant_revoke_keyword = { type : 'grant' } | { type : 'revoke' ; grant_option_for ?: origin_str_stmt ; } ;
651+
652+ export interface grant_revoke_stmt {
653+ type : string ;
654+ grant_option_for ?: origin_str_stmt ;
655+ keyword : 'priv' ;
656+ objects : priv_list ;
657+ on : {
658+ object_type ?: object_type ;
659+ priv_level : priv_level_list ;
660+ } ;
661+ to_from : 'to' | 'from' ;
662+ user_or_roles ?: user_or_role_list ;
663+ with ?: with_grant_option ;
664+ }
665+
666+ export type grant_revoke_stmt = AstStatement < grant_revoke_stmt > | => AstStatement < grant_revoke_stmt > ;
667+
668+ export type elseif_stmt = { type : 'elseif' ; boolean_expr : expr ; then : curd_stmt ; semicolon ?: string ; } ;
669+
670+ export type elseif_stmt_list = elseif_stmt [ ] ;
671+
672+ export interface if_else_stmt {
673+ type : 'if' ;
674+ keyword : 'if' ;
675+ boolean_expr : expr ;
676+ semicolons : string [ ] ;
677+ if_expr : crud_stmt ;
678+ elseif_expr : elseif_stmt [ ] ;
679+ else_expr : curd_stmt ;
680+ prefix : literal_string ;
681+ suffix : literal_string ;
682+ }
683+
684+ export type if_else_stmt = AstStatement < if_else_stmt > ;
685+
686+ export type raise_level = "DEBUG" | "LOG" | "INFO" | "NOTICE" | "WARNING" | "EXCEPTION" ;
687+
688+ export type raise_opt = { type : 'using' ; option : string ; symbol : '=' ; expr : expr [ ] ; } ;
689+
690+ type raise_item = never ;
691+
692+ export interface raise_stmt {
693+ type : 'raise' ;
694+ level ?: string ;
695+ raise ?: raise_item ;
696+ using ?: raise_opt ;
697+ }
698+
699+ export type raise_stmt = AstStatement < raise_stmt > ;
700+
701+ export interface execute_stmt {
702+ type : 'execute' ;
703+ name : string ;
704+ args ?: { type : expr_list ; value : proc_primary_list ; }
705+ }
706+
707+ export type execute_stmt = AstStatement < execute_stmt > ;
708+
709+ export type for_label = { label ?: string ; keyword : 'for' ; } ;
710+
711+ export interface for_loop_stmt {
712+ type : 'for' ;
713+ label ?: string
714+ target : string ;
715+ query : select_stmt ;
716+ stmts : multiple_stmt ;
717+ }
718+
719+ export type for_loop_stmt = AstStatement < for_loop_stmt > ;
720+
565721export interface select_stmt_node extends select_stmt_nake {
566722 parentheses : true ;
567723 }
@@ -719,7 +875,7 @@ export type order_by_clause = order_by_list;
719875
720876export type order_by_list = order_by_element [ ] ;
721877
722- export type order_by_element = { expr : expr ; type : 'ASC' | 'DESC' ; nulls : 'NULLS FIRST' | 'NULLS LAST' | undefined } ;
878+ export type order_by_element = { expr : expr ; type : 'ASC' | 'DESC' | undefined ; nulls : 'NULLS FIRST' | 'NULLS LAST' | undefined } ;
723879
724880export type number_or_param = literal_numeric | var_decl | param ;
725881
@@ -937,6 +1093,8 @@ export type column_list = column[];
9371093
9381094export type ident = string ;
9391095
1096+ export type ident_list = ident [ ] ;
1097+
9401098export type alias_ident = string ;
9411099
9421100export type quoted_ident = double_quoted_ident | single_quoted_ident | backticks_quoted_ident ;
@@ -1396,6 +1554,8 @@ type KW_CURRENT_TIMESTAMP = never;
13961554
13971555type KW_CURRENT_USER = never ;
13981556
1557+ type KW_CURRENT_ROLE = never ;
1558+
13991559type KW_SESSION_USER = never ;
14001560
14011561type KW_SYSTEM_USER = never ;
@@ -1524,7 +1684,9 @@ type EOF = never;
15241684
15251685export type proc_stmts = ( proc_stmt ) [ ] ;
15261686
1527- export type proc_stmt = { type : 'proc' ; stmt : assign_stmt | return_stmt ; vars : any } ;
1687+ export interface proc_stmt { type : 'proc' ; stmt : assign_stmt | return_stmt ; vars : any }
1688+
1689+ export type proc_stmt = AstStatement < proc_stmt > ;
15281690
15291691export type assign_stmt = { type : 'assign' ; left : var_decl | without_prefix_var_decl ; symbol : ':=' | '=' ; right : proc_expr ; } ;
15301692
@@ -1538,7 +1700,7 @@ export type proc_multiplicative_expr = binary_expr;
15381700
15391701export type proc_join = { type : 'join' ; ltable : var_decl ; rtable : var_decl ; op : join_op ; expr : on_clause ; } ;
15401702
1541- export type proc_primary = literal | var_decl | proc_func_call | param | proc_additive_expr & { parentheses : true ; } ;
1703+ export type proc_primary = literal | var_decl | proc_func_call | param | proc_additive_expr & { parentheses : true ; } | { type : 'var' ; prefix : null ; name : number ; members : [ ] ; quoted : null } | column_ref ;
15421704
15431705export type proc_func_name = string ;
15441706
@@ -1637,4 +1799,8 @@ export type text_type = data_type;
16371799
16381800
16391801
1640- export type uuid_type = data_type ;
1802+ export type uuid_type = data_type ;
1803+
1804+
1805+
1806+ export type record_type = data_type ;
0 commit comments