Skip to content

Commit

Permalink
Merge pull request #2158 from TrevorBurnham/fix-binary-expr-type
Browse files Browse the repository at this point in the history
Make Binary expression type def more flexible
  • Loading branch information
taozhi8833998 authored Oct 9, 2024
2 parents e124acb + 49b8211 commit 099e070
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface BaseFrom {
export interface Join extends BaseFrom {
join: "INNER JOIN" | "LEFT JOIN" | "RIGHT JOIN";
using?: string[];
on?: Expr;
on?: Binary;
}
export interface TableExpr {
expr: {
Expand Down Expand Up @@ -127,7 +127,7 @@ export interface Case {
expr: null;
args: Array<
| {
cond: Expr;
cond: Binary;
result: ExpressionValue;
type: "when";
}
Expand Down Expand Up @@ -187,36 +187,29 @@ export type Param = { type: "param"; value: string; loc?: LocationRange };

export type Value = { type: string; value: any; loc?: LocationRange };

export type Binary = {
type: "binary_expr";
operator: string;
left: ExpressionValue | ExprList;
right: ExpressionValue | ExprList;
loc?: LocationRange;
parentheses?: boolean;
};

export type ExpressionValue =
| ColumnRef
| Param
| Function
| Case
| AggrFunc
| Value
| Binary
| Cast
| Interval;
export type Expr =
| {
type: "binary_expr";
operator: "AND" | "OR";
left: Expr;
right: Expr;
loc?: LocationRange;
parentheses?: boolean;
}
| {
type: "binary_expr";
operator: string;
left: ExpressionValue;
right: ExpressionValue | ExprList;
loc?: LocationRange;
parentheses?: boolean;
};

export type ExprList = {
type: "expr_list";
value: ExpressionValue[] | Expr;
value: ExpressionValue[];
loc?: LocationRange;
};
export interface Select {
Expand All @@ -226,14 +219,13 @@ export interface Select {
distinct: "DISTINCT" | null;
columns: any[] | Column[];
from: From[] | null;
where: Expr | Function | null;
where: Binary | Function | null;
groupby: { columns: ColumnRef[] | null, modifiers: ValueExpr<string>[] };
having: any[] | null;
orderby: OrderBy[] | null;
limit: Limit | null;
_orderby?: OrderBy[] | null;
_limit?: Limit | null;
_next?: Select | null;
parentheses_symbol?: boolean;
_parentheses?: boolean;
loc?: LocationRange;
Expand All @@ -251,14 +243,14 @@ export interface Update {
db: string | null;
table: Array<From | Dual> | null;
set: SetList[];
where: Expr | Function | null;
where: Binary | Function | null;
loc?: LocationRange;
}
export interface Delete {
type: "delete";
table: any;
from: Array<From | Dual>;
where: Expr | Function | null;
where: Binary | Function | null;
loc?: LocationRange;
}

Expand Down

0 comments on commit 099e070

Please sign in to comment.