Documentation
¶
Index ¶
- func DetectSQL(input string) bool
- func IsSelectAll(fields []SelectField) bool
- type Condition
- type DeleteStatement
- type InsertStatement
- type JoinClause
- type JoinType
- type Lexer
- type OrderByClause
- type OrderDirection
- type Parser
- type SQLStatement
- type SelectField
- type SelectStatement
- type StatementType
- type TableRef
- type Token
- type TokenType
- type UpdateStatement
- type WhereClause
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSelectAll ¶
func IsSelectAll(fields []SelectField) bool
IsSelectAll checks if the SELECT fields represent SELECT *
Types ¶
type Condition ¶
type Condition struct {
Field string // Field name
Operator string // "=", ">", "<", ">=", "<=", "!=", "LIKE", "IN", "NOT IN", "IS NULL", "IS NOT NULL"
Value any // Single value
Values []any // Multiple values for IN clause
Subquery *SelectStatement // Subquery for IN/EXISTS clauses
}
Condition represents a single condition
func NewCondition ¶
NewCondition creates a new simple condition
func NewInCondition ¶
NewInCondition creates a new IN condition
type DeleteStatement ¶
type DeleteStatement struct {
Table string
Where *WhereClause
}
DeleteStatement represents a DELETE statement
func (*DeleteStatement) GetTableName ¶
func (s *DeleteStatement) GetTableName() string
func (*DeleteStatement) GetType ¶
func (s *DeleteStatement) GetType() StatementType
type InsertStatement ¶
type InsertStatement struct {
Table string
Fields []string
Values [][]any // Multiple rows of values
}
InsertStatement represents an INSERT statement
func (*InsertStatement) GetTableName ¶
func (s *InsertStatement) GetTableName() string
func (*InsertStatement) GetType ¶
func (s *InsertStatement) GetType() StatementType
type JoinClause ¶
type JoinClause struct {
Type JoinType
Table TableRef
Condition *WhereClause
}
JoinClause represents a JOIN clause
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer represents the lexical analyzer
type OrderByClause ¶
type OrderByClause struct {
Field string
Direction OrderDirection
}
OrderByClause represents an ORDER BY clause
type OrderDirection ¶
type OrderDirection int
OrderDirection represents sort direction
const ( OrderDirectionAsc OrderDirection = iota OrderDirectionDesc )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents the SQL parser
func (*Parser) Parse ¶
func (p *Parser) Parse() (SQLStatement, error)
Parse parses the SQL statement and returns AST
type SQLStatement ¶
type SQLStatement interface {
GetType() StatementType
GetTableName() string
}
SQLStatement represents a parsed SQL statement
type SelectField ¶
type SelectField struct {
Expression string // Field name or expression
Alias string // Optional alias
}
SelectField represents a field in SELECT clause
type SelectStatement ¶
type SelectStatement struct {
Fields []SelectField
From TableRef
Where *WhereClause
OrderBy []*OrderByClause
GroupBy []string
Having *WhereClause
Limit *int
Offset *int
Joins []*JoinClause
}
SelectStatement represents a SELECT statement
func (*SelectStatement) GetTableName ¶
func (s *SelectStatement) GetTableName() string
func (*SelectStatement) GetType ¶
func (s *SelectStatement) GetType() StatementType
type StatementType ¶
type StatementType int
StatementType represents the type of SQL statement
const ( StatementTypeSelect StatementType = iota StatementTypeInsert StatementTypeUpdate StatementTypeDelete )
type TokenType ¶
type TokenType int
TokenType represents the type of token
const ( // Special tokens TokenIllegal TokenType = iota TokenEOF // Literals TokenIdent // table names, column names TokenInt // 123 TokenFloat // 123.45 TokenString // 'string' or "string" // Keywords TokenSelect TokenFrom TokenWhere TokenInsert TokenInto TokenValues TokenUpdate TokenSet TokenDelete TokenOrder TokenBy TokenGroup TokenHaving TokenLimit TokenOffset TokenJoin TokenInner TokenLeft TokenRight TokenFull TokenOn TokenAs TokenAnd TokenOr TokenNot TokenIn TokenIs TokenNull TokenLike TokenBetween TokenDistinct TokenTrue TokenFalse // Operators TokenEqual // = TokenNotEqual // !=, <> TokenLess // < TokenLessEqual // <= TokenGreater // > TokenGreaterEqual // >= // Delimiters TokenComma // , TokenSemicolon // ; TokenLParen // ( TokenRParen // ) TokenStar // * TokenQuestion // ? TokenDot // . )
type UpdateStatement ¶
type UpdateStatement struct {
Table string
Set map[string]any
Where *WhereClause
}
UpdateStatement represents an UPDATE statement
func (*UpdateStatement) GetTableName ¶
func (s *UpdateStatement) GetTableName() string
func (*UpdateStatement) GetType ¶
func (s *UpdateStatement) GetType() StatementType
type WhereClause ¶
type WhereClause struct {
Operator string // "AND", "OR", "NOT"
Left *WhereClause // Left operand for logical operators
Right *WhereClause // Right operand for logical operators
Condition *Condition // Leaf condition
}
WhereClause represents a WHERE condition
func NewWhereClause ¶
func NewWhereClause(condition *Condition) *WhereClause
NewWhereClause creates a new WHERE clause with a single condition
func (*WhereClause) And ¶
func (w *WhereClause) And(other *WhereClause) *WhereClause
And combines two WHERE clauses with AND
func (*WhereClause) Or ¶
func (w *WhereClause) Or(other *WhereClause) *WhereClause
Or combines two WHERE clauses with OR