Documentation ¶
Index ¶
- Constants
- Variables
- func ExprString(expr Expr) string
- func ForEachSource(src Source, fn func(Source) bool)
- func IdentName(ident *Ident) string
- func IsInteger(s string) bool
- func SourceName(src Source) string
- func Walk(v Visitor, node Node) error
- type Assignment
- type BinaryExpr
- type BindExpr
- type BlobLit
- type BoolLit
- type Call
- type CaseBlock
- type CaseExpr
- type ColumnArg
- type Constraint
- type DeleteStatement
- type Error
- type Exists
- type Expr
- type Exprs
- type FilterClause
- type Hint
- type Ident
- type IndexedColumn
- type InsertStatement
- type JoinClause
- type JoinConstraint
- type JoinOperator
- type Lexer
- type LockOption
- type LockStrength
- type LockingClause
- type Node
- type NullLit
- type NumberLit
- type OnConstraint
- type OrderingTerm
- type OutputNames
- type ParenExpr
- type ParenSource
- type Parser
- type Pos
- type QualifiedRef
- type Range
- type ResultColumn
- type Scope
- type SelectStatement
- type Source
- type Statement
- type StringLit
- type TableName
- type Token
- type Type
- type UnaryExpr
- type UpdateStatement
- type UpsertClause
- type UsingConstraint
- type VisitEndFunc
- type VisitFunc
- type Visitor
Constants ¶
const ( LowestPrec = 0 // non-operators UnaryPrec = 13 HighestPrec = 14 )
Variables ¶
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented not implemented
Functions ¶
func ExprString ¶
ExprString returns the string representation of expr. Returns a blank string if expr is nil.
func ForEachSource ¶
ForEachSource calls fn for every source within the current scope. Stops iteration if fn returns false.
func SourceName ¶
SourceName returns the name of the source. Only returns for TableName & ParenSource.
Types ¶
type Assignment ¶
Assignment is used within the UPDATE statement & upsert clause. It is similiar to an expression except that it must be an equality.
func (*Assignment) String ¶
func (a *Assignment) String() string
String returns the string representation of the clause.
type BinaryExpr ¶
func (*BinaryExpr) String ¶
func (expr *BinaryExpr) String() string
String returns the string representation of the expression.
type Call ¶
type Call struct { Name *Ident // function name Star bool Distinct bool Args []Expr // argument list Filter *FilterClause // filter clause }
type CaseExpr ¶
type Constraint ¶
type Constraint interface { Node // contains filtered or unexported methods }
type DeleteStatement ¶
type DeleteStatement struct { Only bool TableName *TableName TableStar bool Alias *Ident UsingList []*TableName Condition Expr CursorName *Ident OutputExpressions *OutputNames }
DeleteStatement see http://www.postgres.cn/docs/12/sql-delete.html
func (*DeleteStatement) String ¶
func (s *DeleteStatement) String() string
String returns the string representation of the clause.
type Exists ¶
type Exists struct { Not bool Select *SelectStatement // select statement }
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
func MustParseExprString ¶
MustParseExprString parses s into an expression. Panic on error.
func ParseExprString ¶
ParseExprString parses s into an expression. Returns nil if s is blank.
func SplitExprTree ¶
SplitExprTree splits apart expr so it is a list of all AND joined expressions. For example, the expression "A AND B AND (C OR (D AND E))" would be split into a list of "A", "B", "C OR (D AND E)".
type FilterClause ¶
type FilterClause struct {
X Expr // filter expression
}
func (*FilterClause) String ¶
func (c *FilterClause) String() string
String returns the string representation of the clause.
type Ident ¶
type IndexedColumn ¶
func (*IndexedColumn) String ¶
func (c *IndexedColumn) String() string
String returns the string representation of the column.
type InsertStatement ¶
type InsertStatement struct { TableName *TableName ColumnNames []*Ident Overriding string DefaultValues bool Expressions []*Exprs Query *SelectStatement UpsertClause *UpsertClause OutputExpressions *OutputNames }
InsertStatement see http://www.postgres.cn/docs/12/sql-insert.html
func (*InsertStatement) String ¶
func (s *InsertStatement) String() string
String returns the string representation of the statement.
type JoinClause ¶
type JoinClause struct { X Source // lhs source Operator *JoinOperator // join operator Y Source // rhs source Constraint JoinConstraint // join constraint }
func (*JoinClause) String ¶
func (c *JoinClause) String() string
String returns the string representation of the clause.
type JoinConstraint ¶
type JoinConstraint interface { Node // contains filtered or unexported methods }
JoinConstraint represents either an ON or USING join constraint.
type JoinOperator ¶
func (*JoinOperator) String ¶
func (op *JoinOperator) String() string
String returns the string representation of the operator.
type LockOption ¶ added in v0.3.2
type LockOption int
const ( Nowait LockOption = iota SkipLocked )
func (LockOption) ToPtr ¶ added in v0.3.2
func (l LockOption) ToPtr() *LockOption
type LockStrength ¶ added in v0.3.2
type LockStrength int
const ( Update LockStrength = iota NoKeyUpdate )
type LockingClause ¶ added in v0.3.2
type LockingClause struct { Strength LockStrength Option *LockOption }
func (*LockingClause) String ¶ added in v0.3.2
func (c *LockingClause) String() string
type OnConstraint ¶
type OnConstraint struct {
X Expr // constraint expression
}
func (*OnConstraint) String ¶
func (c *OnConstraint) String() string
String returns the string representation of the constraint.
type OrderingTerm ¶
type OrderingTerm struct { X Expr // ordering expression Asc bool Desc bool NullsFirst bool NullsLast bool }
func (*OrderingTerm) String ¶
func (t *OrderingTerm) String() string
String returns the string representation of the term.
type OutputNames ¶
type OutputNames []*ResultColumn
func (OutputNames) String ¶
func (on OutputNames) String() string
type ParenSource ¶
type ParenSource struct { X Source // nested source Alias *Ident // optional table alias (select source only) }
func (*ParenSource) String ¶
func (s *ParenSource) String() string
String returns the string representation of the source.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a SQL parser.
func (*Parser) ParseStatement ¶
type Pos ¶
type QualifiedRef ¶
func (*QualifiedRef) String ¶
func (r *QualifiedRef) String() string
String returns the string representation of the expression.
type ResultColumn ¶
type ResultColumn struct { Star bool Expr Expr // column expression (may be "tbl.*") Alias *Ident // alias name }
func (*ResultColumn) String ¶
func (c *ResultColumn) String() string
String returns the string representation of the column.
type Scope ¶
Scope represents a context for name resolution. Names can be resolved at the current source or in parent scopes.
type SelectStatement ¶
type SelectStatement struct { All bool Distinct bool Columns *OutputNames // list of result columns in the SELECT clause FromItems Source Condition Expr GroupingElements []Expr HavingCondition Expr Union bool UnionAll bool Intersect bool Except bool Compound *SelectStatement // compounded SELECT statement OrderBy []*OrderingTerm // terms of ORDER BY clause Limit Expr Offset Expr // offset expression Locking *LockingClause Hint *Hint }
SelectStatement see http://www.postgres.cn/docs/12/sql-select.html
func (*SelectStatement) String ¶
func (s *SelectStatement) String() string
String returns the string representation of the statement.
type Source ¶
type Source interface { Node // contains filtered or unexported methods }
Source represents a table or subquery.
func ResolveSource ¶
ResolveSource returns a source with the given name. This can either be the table name or the alias for a source.
func SourceList ¶
SourceList returns a list of scopes in the current scope.
func StatementSource ¶
StatementSource returns the root statement for a statement.
type TableName ¶
type Token ¶
type Token int
Token is the set of lexical tokens of the Go programming language.
const ( // Special tokens ILLEGAL Token = iota EOF COMMENT SPACE IDENT // IDENT QIDENT // "IDENT" or `IDENT` STRING // 'string' BLOB // ??? FLOAT // 123.45 INTEGER // 123 MLCOMMENT // multiline comment NULL // NULL TRUE // true FALSE // false BIND //? or ?NNN or :VVV or @VVV or $VVV SEMI // ; LP // ( RP // ) COMMA // , NE // != EQ // = LE // <= LG // <> LT // < GT // > GE // >= BITAND // & BITOR // | BITNOT // ! LSHIFT // << RSHIFT // >> PLUS // + MINUS // - STAR // * SLASH // / REM // % CONCAT // || DOT // . ABORT ACTION ADD AFTER AGG_COLUMN AGG_FUNCTION ALL ALTER ANALYZE AND AS ASC ASTERISK ATTACH AUTOINCREMENT BEFORE BEGIN BETWEEN BY CASCADE CASE CAST CHECK COLUMN COLUMNKW COMMIT CONFLICT CONSTRAINT CREATE CROSS CTIME_KW CURRENT CURRENT_TIME CURRENT_DATE CURRENT_TIMESTAMP DATABASE DEFAULT DEFERRABLE DEFERRED DELETE DESC DETACH DISTINCT DO DROP EACH ELSE END ESCAPE EXCEPT EXCLUDE EXCLUSIVE EXISTS EXPLAIN FAIL FILTER FIRST FOLLOWING FOR FOREIGN FROM FUNCTION GLOB GROUP GROUPS HAVING IF IF_NULL_ROW IGNORE IMMEDIATE IN INDEX INDEXED INITIALLY INNER INSERT INSTEAD INTERSECT INTO IS ISNOT ISNULL // TODO: REMOVE? JOIN KEY LAST LEFT LIKE LIMIT MATCH NATURAL NO NOT NOTBETWEEN NOTEXISTS NOTGLOB NOTHING NOTIN NOTLIKE NOTMATCH NOTNULL NOTREGEXP NULLS OF OFFSET ON ONLY OR ORDER OTHERS OUTER OVER OVERRIDING PARTITION PLAN PRAGMA PRECEDING PRIMARY QUERY RAISE RANGE RECURSIVE REFERENCES REGEXP REGISTER REINDEX RELEASE RENAME RESTRICT RETURNING ROLLBACK ROW ROWS SELECT SELECT_COLUMN SET SPAN SYSTEM TABLE TEMP THEN TIES TO TRANSACTION TRIGGER TRUTH UNBOUNDED UNION UNIQUE UPDATE USER USING VACUUM VALUE VALUES VARIABLE VECTOR VIEW VIRTUAL WHEN WHERE WINDOW WITH WITHOUT DUPLICATE SHARE NOWAIT SKIP LOCKED ANY // ??? )
The list of tokens.
func (Token) IsBinaryOp ¶
func (Token) Precedence ¶
type Type ¶
type UpdateStatement ¶
type UpdateStatement struct { Only bool TableName *TableName TableStar bool Alias *Ident Assignments []*Assignment FromList []*TableName Condition Expr CursorName *Ident OutputExpressions *OutputNames }
UpdateStatement see http://www.postgres.cn/docs/12/sql-update.html
func (*UpdateStatement) String ¶
func (s *UpdateStatement) String() string
String returns the string representation of the clause.
type UpsertClause ¶
type UpsertClause struct { Columns []*IndexedColumn // optional indexed column list WhereExpr Expr // optional conditional expression DoNothing bool // position of NOTHING keyword after DO DoUpdate bool // position of UPDATE keyword after DO DuplicateKey bool // position of ON DUPLICATE KEY UPDATE keyword Assignments []*Assignment // list of column assignments UpdateWhereExpr Expr // optional conditional expression for DO UPDATE SET }
func (*UpsertClause) String ¶
func (c *UpsertClause) String() string
String returns the string representation of the clause.
type UsingConstraint ¶
type UsingConstraint struct {
Columns []*Ident // column list
}
func (*UsingConstraint) String ¶
func (c *UsingConstraint) String() string
String returns the string representation of the constraint.
type VisitEndFunc ¶
VisitEndFunc represents a function type that implements Visitor. Only executes on node exit.
func (VisitEndFunc) Visit ¶
func (fn VisitEndFunc) Visit(node Node) (Visitor, error)
Visit is a no-op.
func (VisitEndFunc) VisitEnd ¶
func (fn VisitEndFunc) VisitEnd(node Node) error
VisitEnd executes fn.
type VisitFunc ¶
VisitFunc represents a function type that implements Visitor. Only executes on node entry.