Skip to content

Commit

Permalink
Merge pull request #1883 from DemonHa/fix-types
Browse files Browse the repository at this point in the history
fix: broken type generator
  • Loading branch information
taozhi8833998 authored Apr 29, 2024
2 parents 5158a5b + 2e44a67 commit 3996769
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
42 changes: 41 additions & 1 deletion ast/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface create_table_stmt_node_like extends create_table_stmt_node_base
like: create_like_table;
}

export type create_table_stmt = AstStatement<create_table_stmt_node> | AstStatement<create_table_stmt_node>;;
export type create_table_stmt = AstStatement<create_table_stmt_node_base & { partition_of: create_table_partition_of }> | AstStatement<create_table_stmt_node>;

export type create_sequence_stmt = {
type: 'create',
Expand Down Expand Up @@ -230,6 +230,46 @@ export type create_like_table_simple = { type: 'like'; table: table_ref_list; };

export type create_like_table = create_like_table_simple | create_like_table_simple & { parentheses?: boolean; };







export type for_values_item = {
type: 'for_values_item';
keyword: 'from';
from: literal_string;
to: literal_string;
} | {
type: 'for_values_item';
keyword: 'in';
in: expr_list;
} | {
type: 'for_values_item';
keyword: 'with';
modulus: literal_numeric;
remainder: literal_numeric;
};



export type for_values = {
type: 'for_values';
keyword: 'for values';
expr: for_values_item;
};



export type create_table_partition_of = {
type: 'partition_of';
keyword: 'partition of';
table: table_name;
for_values: for_values;
tablespace: ident_without_kw_type | undefined;
};

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;
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"mocha": "^10.0.0",
"mochapack": "^2.0.3",
"nyc": "15.1.0",
"pegjs": "^0.10.0",
"pegjs-loader": "^0.5.6",
"pre-commit": "^1.2.2",
"rimraf": "^5.0.1",
Expand All @@ -95,7 +96,7 @@
"sourceMap": false
},
"dependencies": {
"big-integer": "^1.6.48",
"@types/pegjs": "^0.10.0"
"@types/pegjs": "^0.10.0",
"big-integer": "^1.6.48"
}
}
39 changes: 31 additions & 8 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,7 @@ create_table_stmt
ife:if_not_exists_stmt? __
t:table_ref_list __
po:create_table_partition_of {
/*
export interface create_table_partition_of extends create_table_stmt_node_base {
partition_of: create_table_partition_of;
}
=> AstStatement<create_table_partition_of>;
*/
// => AstStatement<create_table_stmt_node_base & { partition_of: create_table_partition_of }>
if(t) t.forEach(tt => tableList.add(`create::${tt.db}::${tt.table}`));
return {
tableList: Array.from(tableList),
Expand Down Expand Up @@ -876,7 +870,7 @@ create_table_stmt
export interface create_table_stmt_node_like extends create_table_stmt_node_base{
like: create_like_table;
}
=> AstStatement<create_table_stmt_node>;
=> AstStatement<create_table_stmt_node>
*/
if(t) t.forEach(tt => tableList.add(`create::${tt.db}::${tt.table}`));
return {
Expand Down Expand Up @@ -1145,6 +1139,12 @@ create_like_table

for_values_item
= KW_FROM __ LPAREN __ f:literal_string __ RPAREN __ KW_TO __ LPAREN __ t:literal_string __ RPAREN {
/* => {
type: 'for_values_item';
keyword: 'from';
from: literal_string;
to: literal_string;
} */
return {
type: 'for_values_item',
keyword: 'from',
Expand All @@ -1153,13 +1153,24 @@ for_values_item
}
}
/ KW_IN __ LPAREN __ e:expr_list __ RPAREN {
/* => {
type: 'for_values_item';
keyword: 'in';
in: expr_list;
} */
return {
type: 'for_values_item',
keyword: 'in',
in: e,
}
}
/ KW_WITH __ LPAREN __ 'MODULUS'i __ m:literal_numeric __ COMMA __ 'REMAINDER'i __ r:literal_numeric __ RPAREN {
/* => {
type: 'for_values_item';
keyword: 'with';
modulus: literal_numeric;
remainder: literal_numeric;
} */
return {
type: 'for_values_item',
keyword: 'with',
Expand All @@ -1170,6 +1181,11 @@ for_values_item

for_values
= 'FOR'i __ KW_VALUES __ fvi:for_values_item {
/* => {
type: 'for_values';
keyword: 'for values';
expr: for_values_item;
} */
return {
type: 'for_values',
keyword: 'for values',
Expand All @@ -1178,6 +1194,13 @@ for_values
}
create_table_partition_of
= KW_PARTITION __ 'OF'i __ t:table_name __ fv:for_values __ ts:(KW_TABLESPACE __ ident_without_kw_type)? {
/* => {
type: 'partition_of';
keyword: 'partition of';
table: table_name;
for_values: for_values;
tablespace: ident_without_kw_type | undefined;
} */
return {
type: 'partition_of',
keyword: 'partition of',
Expand Down

0 comments on commit 3996769

Please sign in to comment.