Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions ast/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export type create_table_definition = create_definition[];

export type create_definition = create_column_definition | create_index_definition | create_fulltext_spatial_index_definition | create_constraint_definition;

export type column_definition_opt = column_constraint | { auto_increment: 'auto_increment'; } | { unique: 'unique' | 'unique key'; } | { unique: 'key' | 'primary key'; } | { comment: keyword_comment; } | { collate: collate_expr; } | { column_format: column_format; } | { storage: storage } | { reference_definition: reference_definition; } | { check: check_constraint_definition; } | { character_set: collate_expr };
export type column_definition_opt = column_constraint | { auto_increment: 'auto_increment'; } | { unique: 'unique' | 'unique key'; } | { unique: 'key' | 'primary key'; } | { comment: keyword_comment; } | { collate: collate_expr; } | { column_format: column_format; } | { storage: storage } | { reference_definition: reference_definition; } | { check: check_constraint_definition; } | { character_set: { type: 'CHARACTER SET'; symbol: '=' | null; value: ident_without_kw_type; } };



Expand Down Expand Up @@ -314,7 +314,7 @@ export type create_column_definition = {

export type column_constraint = { nullable: literal_null | literal_not_null; default_val: default_expr; };

export type collate_expr = { type: 'collate'; symbol: '=' | null; value: ident; };
export type collate_expr = { type: 'collate'; keyword: 'collate'; collate: { symbol: '=' ; name: ident_type; value: ident_type; }} | { type: 'collate'; keyword: 'collate'; collate: { symbol: '=' | null ; name: ident_type; }};

export type column_format = { type: 'column_format'; value: 'fixed' | 'dynamic' | 'default'; };

Expand Down Expand Up @@ -391,21 +391,25 @@ export type alter_schema_stmt = AstStatement<alter_resource_stmt_node>;
export interface alter_table_stmt_node {
type: 'alter';
table: table_ref_list;
keyword: 'table';
if_exists: if_exists;
prefix?: literal_string;
expr: alter_action_list;
}

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_ADD_CONSTRAINT | ALTER_DROP_COLUMN | ALTER_ADD_INDEX_OR_KEY | ALTER_ADD_FULLETXT_SPARITAL_INDEX | ALTER_RENAME | 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 | ALTER_ALGORITHM | ALTER_LOCK | ALTER_COLUMN_DATA_TYPE | ALTER_COLUMN_DEFAULT | ALTER_COLUMN_NOT_NULL;



export type ALTER_ADD_COLUMN = {
action: 'add';
keyword: KW_COLUMN;
resource: 'column';
if_not_exists: ife;
type: 'alter';
} & create_column_definition;;

Expand All @@ -415,6 +419,7 @@ export type ALTER_DROP_COLUMN = {
action: 'drop';
collumn: column_ref;
keyword: KW_COLUMN;
if_exists: if_exists;
resource: 'column';
type: 'alter';
};
Expand Down Expand Up @@ -471,6 +476,35 @@ export type ALTER_LOCK = {



export type ALTER_COLUMN_DATA_TYPE = {
action: 'alter';
keyword?: KW_COLUMN;
using?: expr;
type: 'alter';
} & create_column_definition;;





export type ALTER_COLUMN_DEFAULT = {
action: 'alter';
keyword?: KW_COLUMN;
default_val?: { type: 'set default', value: expr };
type: 'alter';
} & create_column_definition;;



export type ALTER_COLUMN_NOT_NULL = {
action: 'alter';
keyword?: KW_COLUMN;
nullable: literal_not_null;
type: 'alter';
} & create_column_definition;;



export type create_index_definition = {
index: column;
definition: cte_column_definition;
Expand Down Expand Up @@ -611,7 +645,7 @@ export type create_option_character_set_kw = string;
export type create_option_character_set = {
keyword: 'character set' | 'charset' | 'collate' | 'default character set' | 'default charset' | 'default collate';
symbol: '=';
value: ident_name;
value: ident_without_kw_type;
};


Expand Down Expand Up @@ -838,7 +872,7 @@ export type expr_item = binary_column_expr & { array_index: array_index };

export type cast_data_type = data_type & { quoted?: string };

export type column_list_item = { expr: expr; as: null; } | { type: 'cast'; expr: expr; symbol: '::'; target: cast_data_type; as?: null; arrows?: ('->>' | '->')[]; property?: (literal_string | literal_numeric)[]; } | { expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; };
export type column_list_item = { expr: expr; as: null; } | { type: 'cast'; expr: expr; symbol: '::'; target: cast_data_type; as?: null; jsonb?: jsonb_or_json_op_right[]; } | { expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; };



Expand Down Expand Up @@ -881,7 +915,7 @@ export type table_ref = table_base | table_join;
export type table_join = table_base & {join: join_op; using: ident_name[]; } | table_base & {join: join_op; on?: on_clause; } | {
expr: (union_stmt | table_ref_list) & { parentheses: true; };
as?: alias_clause;
join: join_op;
join: join_op | set_op;
on?: on_clause;
};

Expand Down Expand Up @@ -1114,7 +1148,7 @@ export type exists_expr = unary_expr;

export type exists_op = 'NOT EXISTS' | KW_EXISTS;

export type comparison_op_right = arithmetic_op_right | in_op_right | between_op_right | is_op_right | like_op_right | jsonb_op_right | regex_op_right;
export type comparison_op_right = arithmetic_op_right | in_op_right | between_op_right | is_op_right | like_op_right | jsonb_or_json_op_right | regex_op_right;

export type arithmetic_op_right = { type: 'arithmetic'; tail: any };

Expand Down Expand Up @@ -1146,7 +1180,7 @@ export type like_op_right = { op: like_op; right: (literal | comparison_expr) &

export type in_op_right = {op: in_op; right: expr_list | var_decl | literal_string; };

export type jsonb_op_right = { op: string; right: expr };
export type jsonb_or_json_op_right = { op: string; right: { type: 'expr'; expr: expr_item } };

export type additive_expr = binary_expr;

Expand Down Expand Up @@ -1175,14 +1209,11 @@ export type column_ref = string_constants_escape | {
schema: string;
table: string;
column: column | '*';
arrows?: ('->>' | '->')[];
property?: (literal_string | literal_numeric)[];
jsonb?: jsonb_or_json_op_right[];
} | {
type: 'column_ref';
table: ident;
column: column | '*';
arrows?: ('->>' | '->')[];
property?: (literal_string | literal_numeric)[];
};

export type column_ref_quoted = unknown;
Expand Down Expand Up @@ -1307,8 +1338,7 @@ export type cast_double_colon = {
as?: alias_clause,
symbol: '::' | 'as',
target: data_type;
arrows?: ('->>' | '->')[];
property?: (literal_string | literal_numeric)[];
jsonb?: jsonb_or_json_op_right[];
};


Expand Down Expand Up @@ -1851,6 +1881,8 @@ export type data_type = {





export type array_type = data_type;


Expand Down
24 changes: 21 additions & 3 deletions pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ comparison_op_right
/ between_op_right
/ is_op_right
/ like_op_right
/ jsonb_or_json_op_right

arithmetic_op_right
= l:(__ arithmetic_comparison_operator __ additive_expr)+ {
Expand Down Expand Up @@ -1781,6 +1782,24 @@ in_op_right
return { op: op, right: e };
}

jsonb_or_json_op_right
= s: ('@>' / '<@' / '?|' / '?&' / '?' / '#-') __ e:expr {
// => { op: string; right: expr }
return {
type: 'jsonb',
op: s,
right: { type: 'expr', expr: e }
}
}
/ s: ('#>>' / '#>' / DOUBLE_ARROW / SINGLE_ARROW) __ e:expr {
// => { op: string; right: expr }
return {
type: 'json',
op: s,
right: { type: 'expr', expr: e }
}
}

additive_expr
= head:multiplicative_expr
tail:(__ additive_operator __ multiplicative_expr)* {
Expand Down Expand Up @@ -1826,15 +1845,14 @@ unary_operator
= '!' / '-' / '+' / '~'

column_ref
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ (literal_string / literal_numeric))+ {
= tbl:(ident __ DOT __)? col:column __ jo:jsonb_or_json_op_right+ {
const tableName = tbl && tbl[0] || null
columnList.add(`select::${tableName}::${col}`);
return {
type: 'column_ref',
table: tableName,
column: col,
arrows: a.map(item => item[0]),
properties: a.map(item => item[2])
jsonb: jo,
};
}
/ tbl:ident __ DOT __ col:column_without_kw {
Expand Down
23 changes: 15 additions & 8 deletions pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ comparison_op_right
/ is_op_right
/ like_op_right
/ similar_to_op_right
/ jsonb_op_right
/ jsonb_or_json_op_right

arithmetic_op_right
= l:(__ arithmetic_comparison_operator __ additive_expr)+ {
Expand Down Expand Up @@ -2576,13 +2576,21 @@ exists_op_right
return { op: op, right: l };
}

jsonb_op_right
= s: ('@>' / '<@' / OPERATOR_CONCATENATION / DOUBLE_WELL_ARROW / WELL_ARROW / '?' / '?|' / '?&' / '#-') __
c:column_list_item {
jsonb_or_json_op_right
= s: ('@>' / '<@' / '?|' / '?&' / '?' / '#-') __ e:expr {
// => { op: string; right: expr }
return {
type: 'jsonb',
op: s,
right: c && c.expr || c
right: { type: 'expr', expr: e }
}
}
/ s: ('#>>' / '#>' / DOUBLE_ARROW / SINGLE_ARROW) __ e:expr {
// => { op: string; right: expr }
return {
type: 'json',
op: s,
right: { type: 'expr', expr: e }
}
}

Expand Down Expand Up @@ -2682,16 +2690,15 @@ column_ref
column: '*'
}
}
/ tbl:(ident __ DOT)? __ col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ (literal_string / literal_numeric))+ {
/ tbl:(ident __ DOT)? __ col:column __ jo:jsonb_or_json_op_right+ {
// => IGNORE
const tableName = tbl && tbl[0] || null
columnList.add(`select::${tableName}::${col}`);
return {
type: 'column_ref',
table: tableName,
column: col,
arrows: a.map(item => item[0]),
properties: a.map(item => item[2])
jsonb: jo,
};
}
/ tbl:ident __ DOT __ col:column {
Expand Down
23 changes: 20 additions & 3 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,24 @@ in_op_right
return { op: op, right: e };
}

jsonb_or_json_op_right
= s: ('@>' / '<@' / '?|' / '?&' / '?' / '#-') __ e:expr {
// => { op: string; right: expr }
return {
type: 'jsonb',
op: s,
right: { type: 'expr', expr: e }
}
}
/ s: ('#>>' / '#>' / DOUBLE_ARROW / SINGLE_ARROW) __ e:expr {
// => { op: string; right: expr }
return {
type: 'json',
op: s,
right: { type: 'expr', expr: e }
}
}

additive_expr
= head: multiplicative_expr
tail:(__ additive_operator __ multiplicative_expr)* {
Expand Down Expand Up @@ -3090,15 +3108,14 @@ primary
}

column_ref
= tbl:(ident __ DOT __)? col:column __ a:((DOUBLE_ARROW / SINGLE_ARROW) __ literal)+ {
= tbl:(ident __ DOT __)? col:column __ jo:jsonb_or_json_op_right+ {
const tableName = tbl && tbl[0] || null
columnList.add(`select::${tableName}::${col}`);
return {
type: 'column_ref',
table: tableName,
column: col,
arrows: a.map(item => item[0]),
properties: a.map(item => item[2]),
jsonb: jo,
...getLocationObject(),
};
}
Expand Down
Loading