Files
mayfly-go/server/internal/db/dbm/sqlparser/sqlstmt/select.go
2026-05-08 20:45:13 +08:00

70 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package sqlstmt
// SelectItemKind SELECT 元素类型
type SelectItemKind int
const (
SelectItemStar SelectItemKind = iota
SelectItemColumn
SelectItemExpr
SelectItemFunction
)
// SelectItem 表示 SELECT 列表中的一个元素
type SelectItem struct {
Kind SelectItemKind
Text string // 原始文本
Alias string
TableAlias string // 对于 t.* 或 t.col这是表别名
ColumnName string // 对于列引用
}
// IsStar 判断是否为 *
func (s SelectItem) IsStar() bool {
return s.Kind == SelectItemStar
}
// JoinKind JOIN 类型
type JoinKind int
const (
JoinKindInner JoinKind = iota
JoinKindLeft
JoinKindRight
JoinKindFull
JoinKindCross
JoinKindNatural
)
// JoinClause JOIN 子句
type JoinClause struct {
Kind JoinKind
Table TableRef
On *Expr
Text string
}
// UnionClause UNION 子句
type UnionClause struct {
Select *SelectStmt
All bool
Text string
}
// SelectStmt SELECT 语句(含 UNION、子查询等
type SelectStmt struct {
Base
Distinct bool
Items []SelectItem
From []TableRef
Joins []JoinClause
Where *Expr
GroupBy []string
Having *Expr
OrderBy []OrderByItem
Limit *Limit
Unions []UnionClause
}
func (*SelectStmt) StmtKind() Kind { return KindSelect }