Skip to content

Commit 04c5a70

Browse files
Merge pull request taozhi8833998#1675 from taozhi8833998/refactor-where-type
refactor: update type for where field
2 parents e2b3c66 + 5cae45d commit 04c5a70

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

ast/postgresql.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ export type on_clause = or_and_where_expr;
833833

834834

835835

836-
export type where_clause = binary_expr;
836+
export type where_clause = or_and_where_expr;
837837

838838

839839

@@ -1115,6 +1115,8 @@ export type backticks_quoted_ident = string;
11151115

11161116
export type ident_without_kw = ident_name | quoted_ident;
11171117

1118+
export type column_without_kw = column_name | quoted_ident;
1119+
11181120

11191121

11201122
export type column = string | quoted_ident;

pegjs/postgresql.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ on_clause
31263126
= KW_ON __ e:or_and_where_expr { /* => or_and_where_expr */ return e; }
31273127

31283128
where_clause
3129-
= KW_WHERE __ e:or_and_where_expr { /* => binary_expr */ return e; }
3129+
= KW_WHERE __ e:or_and_where_expr { /* => or_and_where_expr */ return e; }
31303130

31313131
group_by_clause
31323132
= KW_GROUP __ KW_BY __ e:expr_list { /* => expr_list['value'] */ return e.value; }

types.d.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,30 @@ export interface Column {
6868
as: string;
6969
}
7070

71+
type Param = { type: 'param'; value: string };
72+
73+
export type Expr =
74+
| {
75+
type: 'binary_expr';
76+
operator: 'AND' | 'OR';
77+
left: Expr;
78+
right: Expr;
79+
}
80+
| {
81+
type: 'binary_expr';
82+
operator: string;
83+
left: ColumnRef | Param;
84+
right: ColumnRef | Param;
85+
};
86+
7187
export interface Select {
7288
with: With | null;
7389
type: "select";
7490
options: any[] | null;
7591
distinct: "DISTINCT" | null;
7692
columns: any[] | Column[];
7793
from: Array<From | Dual | any> | null;
78-
where: any;
94+
where: Expr;
7995
groupby: ColumnRef[] | null;
8096
having: any[] | null;
8197
orderby: OrderBy[] | null;
@@ -97,13 +113,13 @@ export interface Update {
97113
db: string | null;
98114
table: Array<From | Dual> | null;
99115
set: SetList[];
100-
where: any;
116+
where: Expr;
101117
}
102118
export interface Delete {
103119
type: "delete";
104120
table: any;
105121
from: Array<From | Dual>;
106-
where: any;
122+
where: Expr;
107123
}
108124

109125
export interface Alter {

0 commit comments

Comments
 (0)