sql

package module
v0.0.0-...-532ade1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 9 Imported by: 1

README

sql

Circle CI

This repository holds a pure Go SQL parser based on the SQLite SQL definition. It implements nearly all features of the language except ATTACH, DETACH, and some other minor features.

Credits

This parser was originally created by Ben Johnson. Many thanks to him for making it available for use by rqlite.

Documentation

Index

Constants

View Source
const (
	LowestPrec  = 0 // non-operators
	UnaryPrec   = 13
	HighestPrec = 14
)

Variables

This section is empty.

Functions

func ExprString

func ExprString(expr Expr) string

ExprString returns the string representation of expr. Returns a blank string if expr is nil.

func ForEachSource

func ForEachSource(src Source, fn func(Source) bool)

ForEachSource calls fn for every source within the current scope. Stops iteration if fn returns false.

func IdentName

func IdentName(ident *Ident) string

IdentName returns the name of ident. Returns a blank string if ident is nil.

func IsInteger

func IsInteger(s string) bool

IsInteger returns true if s only contains digits.

func SourceName

func SourceName(src Source) string

SourceName returns the name of the source. Only returns for QualifiedTableName & ParenSource.

func Walk

func Walk(v Visitor, node Node) error

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

Types

type AlterTableStatement

type AlterTableStatement struct {
	Alter Pos    // position of ALTER keyword
	Table Pos    // position of TABLE keyword
	Name  *Ident // table name

	Rename   Pos    // position of RENAME keyword
	RenameTo Pos    // position of TO keyword after RENAME
	NewName  *Ident // new table name

	RenameColumn  Pos    // position of COLUMN keyword after RENAME
	ColumnName    *Ident // new column name
	To            Pos    // position of TO keyword
	NewColumnName *Ident // new column name

	Add       Pos               // position of ADD keyword
	AddColumn Pos               // position of COLUMN keyword after ADD
	ColumnDef *ColumnDefinition // new column definition
}

func (*AlterTableStatement) Clone

Clone returns a deep copy of s.

func (*AlterTableStatement) String

func (s *AlterTableStatement) String() string

String returns the string representation of the statement.

type AnalyzeStatement

type AnalyzeStatement struct {
	Analyze Pos    // position of ANALYZE keyword
	Name    *Ident // table name
}

func (*AnalyzeStatement) Clone

func (s *AnalyzeStatement) Clone() *AnalyzeStatement

Clone returns a deep copy of s.

func (*AnalyzeStatement) String

func (s *AnalyzeStatement) String() string

String returns the string representation of the statement.

type Assignment

type Assignment struct {
	Lparen  Pos      // position of column list left paren
	Columns []*Ident // column list
	Rparen  Pos      // position of column list right paren
	Eq      Pos      // position of =
	Expr    Expr     // assigned expression
}

Assignment is used within the UPDATE statement & upsert clause. It is similiar to an expression except that it must be an equality.

func (*Assignment) Clone

func (a *Assignment) Clone() *Assignment

Clone returns a deep copy of a.

func (*Assignment) String

func (a *Assignment) String() string

String returns the string representation of the clause.

type BeginStatement

type BeginStatement struct {
	Begin       Pos // position of BEGIN
	Deferred    Pos // position of DEFERRED keyword
	Immediate   Pos // position of IMMEDIATE keyword
	Exclusive   Pos // position of EXCLUSIVE keyword
	Transaction Pos // position of TRANSACTION keyword  (optional)
}

func (*BeginStatement) Clone

func (s *BeginStatement) Clone() *BeginStatement

Clone returns a deep copy of s.

func (*BeginStatement) String

func (s *BeginStatement) String() string

String returns the string representation of the statement.

type BinaryExpr

type BinaryExpr struct {
	X     Expr  // lhs
	OpPos Pos   // position of Op
	Op    Token // operator
	Y     Expr  // rhs
}

func (*BinaryExpr) Clone

func (expr *BinaryExpr) Clone() *BinaryExpr

Clone returns a deep copy of expr.

func (*BinaryExpr) String

func (expr *BinaryExpr) String() string

String returns the string representation of the expression.

type BindExpr

type BindExpr struct {
	NamePos Pos    // name position
	Name    string // binding name
}

func (*BindExpr) Clone

func (expr *BindExpr) Clone() *BindExpr

Clone returns a deep copy of expr.

func (*BindExpr) String

func (expr *BindExpr) String() string

String returns the string representation of the expression.

type BlobLit

type BlobLit struct {
	ValuePos Pos    // literal position
	Value    string // literal value
}

func (*BlobLit) Clone

func (lit *BlobLit) Clone() *BlobLit

Clone returns a deep copy of lit.

func (*BlobLit) String

func (lit *BlobLit) String() string

String returns the string representation of the expression.

type BoolLit

type BoolLit struct {
	ValuePos Pos  // literal position
	Value    bool // literal value
}

func (*BoolLit) Clone

func (lit *BoolLit) Clone() *BoolLit

Clone returns a deep copy of lit.

func (*BoolLit) String

func (lit *BoolLit) String() string

String returns the string representation of the expression.

type CTE

type CTE struct {
	TableName     *Ident           // table name
	ColumnsLparen Pos              // position of column list left paren
	Columns       []*Ident         // optional column list
	ColumnsRparen Pos              // position of column list right paren
	As            Pos              // position of AS keyword
	SelectLparen  Pos              // position of select left paren
	Select        *SelectStatement // select statement
	SelectRparen  Pos              // position of select right paren
}

CTE represents an AST node for a common table expression.

func (*CTE) Clone

func (cte *CTE) Clone() *CTE

Clone returns a deep copy of cte.

func (*CTE) String

func (cte *CTE) String() string

String returns the string representation of the CTE.

type Call

type Call struct {
	Name     *Ident        // function name
	Lparen   Pos           // position of left paren
	Star     Pos           // position of *
	Distinct Pos           // position of DISTINCT keyword
	Args     []Expr        // argument list
	Rparen   Pos           // position of right paren
	Filter   *FilterClause // filter clause
	Over     *OverClause   // over clause

	Eval   bool // Evaluate the call before converting to string
	RandFn func() uint64
}

func (*Call) Clone

func (c *Call) Clone() *Call

Clone returns a deep copy of c.

func (*Call) String

func (c *Call) String() string

String returns the string representation of the expression.

type CaseBlock

type CaseBlock struct {
	When      Pos  // position of WHEN keyword
	Condition Expr // block condition
	Then      Pos  // position of THEN keyword
	Body      Expr // result expression
}

func (*CaseBlock) Clone

func (blk *CaseBlock) Clone() *CaseBlock

Clone returns a deep copy of blk.

func (*CaseBlock) String

func (b *CaseBlock) String() string

String returns the string representation of the block.

type CaseExpr

type CaseExpr struct {
	Case     Pos          // position of CASE keyword
	Operand  Expr         // optional condition after the CASE keyword
	Blocks   []*CaseBlock // list of WHEN/THEN pairs
	Else     Pos          // position of ELSE keyword
	ElseExpr Expr         // expression used by default case
	End      Pos          // position of END keyword
}

func (*CaseExpr) Clone

func (expr *CaseExpr) Clone() *CaseExpr

Clone returns a deep copy of expr.

func (*CaseExpr) String

func (expr *CaseExpr) String() string

String returns the string representation of the expression.

type CastExpr

type CastExpr struct {
	Cast   Pos   // position of CAST keyword
	Lparen Pos   // position of left paren
	X      Expr  // target expression
	As     Pos   // position of AS keyword
	Type   *Type // cast type
	Rparen Pos   // position of right paren
}

func (*CastExpr) Clone

func (expr *CastExpr) Clone() *CastExpr

Clone returns a deep copy of expr.

func (*CastExpr) String

func (expr *CastExpr) String() string

String returns the string representation of the expression.

type CheckConstraint

type CheckConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Check      Pos    // position of UNIQUE keyword
	Lparen     Pos    // position of left paren
	Expr       Expr   // check expression
	Rparen     Pos    // position of right paren
}

func (*CheckConstraint) Clone

func (c *CheckConstraint) Clone() *CheckConstraint

Clone returns a deep copy of c.

func (*CheckConstraint) String

func (c *CheckConstraint) String() string

String returns the string representation of the constraint.

type CollateConstraint

type CollateConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Collate    Pos    // position of COLLATE keyword
	Collation  *Ident // collation name
}

func (*CollateConstraint) Clone

Clone returns a deep copy of c.

func (*CollateConstraint) String

func (c *CollateConstraint) String() string

String returns the string representation of the constraint.

type ColumnArg

type ColumnArg interface {
	Node
	// contains filtered or unexported methods
}

type ColumnDefinition

type ColumnDefinition struct {
	Name        *Ident       // column name
	Type        *Type        // data type
	Constraints []Constraint // column constraints
}

func (*ColumnDefinition) Clone

func (d *ColumnDefinition) Clone() *ColumnDefinition

Clone returns a deep copy of d.

func (*ColumnDefinition) String

func (c *ColumnDefinition) String() string

String returns the string representation of the statement.

type CommitStatement

type CommitStatement struct {
	Commit      Pos // position of COMMIT keyword
	End         Pos // position of END keyword
	Transaction Pos // position of TRANSACTION keyword  (optional)
}

func (*CommitStatement) Clone

func (s *CommitStatement) Clone() *CommitStatement

Clone returns a deep copy of s.

func (*CommitStatement) String

func (s *CommitStatement) String() string

String returns the string representation of the statement.

type Constraint

type Constraint interface {
	Node
	// contains filtered or unexported methods
}

func CloneConstraint

func CloneConstraint(cons Constraint) Constraint

CloneConstraint returns a deep copy cons.

type CreateIndexStatement

type CreateIndexStatement struct {
	Create      Pos              // position of CREATE keyword
	Unique      Pos              // position of optional UNIQUE keyword
	Index       Pos              // position of INDEX keyword
	If          Pos              // position of IF keyword
	IfNot       Pos              // position of NOT keyword after IF
	IfNotExists Pos              // position of EXISTS keyword after IF NOT
	Name        *Ident           // index name
	On          Pos              // position of ON keyword
	Table       *Ident           // index name
	Lparen      Pos              // position of column list left paren
	Columns     []*IndexedColumn // column list
	Rparen      Pos              // position of column list right paren
	Where       Pos              // position of WHERE keyword
	WhereExpr   Expr             // conditional expression
}

func (*CreateIndexStatement) Clone

Clone returns a deep copy of s.

func (*CreateIndexStatement) String

func (s *CreateIndexStatement) String() string

String returns the string representation of the statement.

type CreateTableStatement

type CreateTableStatement struct {
	Create      Pos    // position of CREATE keyword
	Table       Pos    // position of CREATE keyword
	If          Pos    // position of IF keyword (optional)
	IfNot       Pos    // position of NOT keyword (optional)
	IfNotExists Pos    // position of EXISTS keyword (optional)
	Name        *Ident // table name

	Lparen      Pos                 // position of left paren of column list
	Columns     []*ColumnDefinition // column definitions
	Constraints []Constraint        // table constraints
	Rparen      Pos                 // position of right paren of column list

	Without Pos // position of WITHOUT keyword (optional)
	Rowid   Pos // position of ROWID keyword (optional)
	Strict  Pos // position of STRICT keyword (optional)

	As     Pos              // position of AS keyword (optional)
	Select *SelectStatement // select stmt to build from
}

func (*CreateTableStatement) Clone

Clone returns a deep copy of s.

func (*CreateTableStatement) String

func (s *CreateTableStatement) String() string

String returns the string representation of the statement.

type CreateTriggerStatement

type CreateTriggerStatement struct {
	Create      Pos    // position of CREATE keyword
	Trigger     Pos    // position of TRIGGER keyword
	If          Pos    // position of IF keyword
	IfNot       Pos    // position of NOT keyword after IF
	IfNotExists Pos    // position of EXISTS keyword after IF NOT
	Name        *Ident // index name

	Before    Pos // position of BEFORE keyword
	After     Pos // position of AFTER keyword
	Instead   Pos // position of INSTEAD keyword
	InsteadOf Pos // position of OF keyword after INSTEAD

	Delete          Pos      // position of DELETE keyword
	Insert          Pos      // position of INSERT keyword
	Update          Pos      // position of UPDATE keyword
	UpdateOf        Pos      // position of OF keyword after UPDATE
	UpdateOfColumns []*Ident // columns list for UPDATE OF
	On              Pos      // position of ON keyword
	Table           *Ident   // table name

	For        Pos // position of FOR keyword
	ForEach    Pos // position of EACH keyword after FOR
	ForEachRow Pos // position of ROW keyword after FOR EACH

	When     Pos  // position of WHEN keyword
	WhenExpr Expr // conditional expression

	Begin Pos         // position of BEGIN keyword
	Body  []Statement // trigger body
	End   Pos         // position of END keyword
}

func (*CreateTriggerStatement) Clone

Clone returns a deep copy of s.

func (*CreateTriggerStatement) String

func (s *CreateTriggerStatement) String() string

String returns the string representation of the statement.

type CreateViewStatement

type CreateViewStatement struct {
	Create      Pos              // position of CREATE keyword
	View        Pos              // position of VIEW keyword
	If          Pos              // position of IF keyword
	IfNot       Pos              // position of NOT keyword after IF
	IfNotExists Pos              // position of EXISTS keyword after IF NOT
	Name        *Ident           // view name
	Lparen      Pos              // position of column list left paren
	Columns     []*Ident         // column list
	Rparen      Pos              // position of column list right paren
	As          Pos              // position of AS keyword
	Select      *SelectStatement // source statement
}

func (*CreateViewStatement) Clone

Clone returns a deep copy of s.

func (*CreateViewStatement) String

func (s *CreateViewStatement) String() string

String returns the string representation of the statement.

type DefaultConstraint

type DefaultConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Default    Pos    // position of DEFAULT keyword
	Lparen     Pos    // position of left paren
	Expr       Expr   // default expression
	Rparen     Pos    // position of right paren
}

func (*DefaultConstraint) Clone

Clone returns a deep copy of c.

func (*DefaultConstraint) String

func (c *DefaultConstraint) String() string

String returns the string representation of the constraint.

type DeleteStatement

type DeleteStatement struct {
	WithClause *WithClause         // clause containing CTEs
	Delete     Pos                 // position of UPDATE keyword
	From       Pos                 // position of FROM keyword
	Table      *QualifiedTableName // table name

	Where     Pos  // position of WHERE keyword
	WhereExpr Expr // conditional expression

	Order         Pos             // position of ORDER keyword
	OrderBy       Pos             // position of BY keyword after ORDER
	OrderingTerms []*OrderingTerm // terms of ORDER BY clause

	Limit       Pos  // position of LIMIT keyword
	LimitExpr   Expr // limit expression
	Offset      Pos  // position of OFFSET keyword
	OffsetComma Pos  // position of COMMA (instead of OFFSET)
	OffsetExpr  Expr // offset expression

	ReturningClause *ReturningClause // optional RETURNING clause
}

func (*DeleteStatement) Clone

func (s *DeleteStatement) Clone() *DeleteStatement

Clone returns a deep copy of s.

func (*DeleteStatement) String

func (s *DeleteStatement) String() string

String returns the string representation of the clause.

type DropIndexStatement

type DropIndexStatement struct {
	Drop     Pos    // position of DROP keyword
	Index    Pos    // position of INDEX keyword
	If       Pos    // position of IF keyword
	IfExists Pos    // position of EXISTS keyword after IF
	Name     *Ident // index name
}

func (*DropIndexStatement) Clone

Clone returns a deep copy of s.

func (*DropIndexStatement) String

func (s *DropIndexStatement) String() string

String returns the string representation of the statement.

type DropTableStatement

type DropTableStatement struct {
	Drop     Pos    // position of DROP keyword
	Table    Pos    // position of TABLE keyword
	If       Pos    // position of IF keyword
	IfExists Pos    // position of EXISTS keyword after IF
	Name     *Ident // view name
}

func (*DropTableStatement) Clone

Clone returns a deep copy of s.

func (*DropTableStatement) String

func (s *DropTableStatement) String() string

String returns the string representation of the statement.

type DropTriggerStatement

type DropTriggerStatement struct {
	Drop     Pos    // position of DROP keyword
	Trigger  Pos    // position of TRIGGER keyword
	If       Pos    // position of IF keyword
	IfExists Pos    // position of EXISTS keyword after IF
	Name     *Ident // trigger name
}

func (*DropTriggerStatement) Clone

Clone returns a deep copy of s.

func (*DropTriggerStatement) String

func (s *DropTriggerStatement) String() string

String returns the string representation of the statement.

type DropViewStatement

type DropViewStatement struct {
	Drop     Pos    // position of DROP keyword
	View     Pos    // position of VIEW keyword
	If       Pos    // position of IF keyword
	IfExists Pos    // position of EXISTS keyword after IF
	Name     *Ident // view name
}

func (*DropViewStatement) Clone

Clone returns a deep copy of s.

func (*DropViewStatement) String

func (s *DropViewStatement) String() string

String returns the string representation of the statement.

type Error

type Error struct {
	Pos Pos
	Msg string
}

Error represents a parse error.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

type Exists

type Exists struct {
	Not    Pos              // position of optional NOT keyword
	Exists Pos              // position of EXISTS keyword
	Lparen Pos              // position of left paren
	Select *SelectStatement // select statement
	Rparen Pos              // position of right paren
}

func (*Exists) Clone

func (expr *Exists) Clone() *Exists

Clone returns a deep copy of expr.

func (*Exists) String

func (expr *Exists) String() string

String returns the string representation of the expression.

type ExplainStatement

type ExplainStatement struct {
	Explain   Pos       // position of EXPLAIN
	Query     Pos       // position of QUERY (optional)
	QueryPlan Pos       // position of PLAN after QUERY (optional)
	Stmt      Statement // target statement
}

func (*ExplainStatement) Clone

func (s *ExplainStatement) Clone() *ExplainStatement

Clone returns a deep copy of s.

func (*ExplainStatement) String

func (s *ExplainStatement) String() string

String returns the string representation of the statement.

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

func CloneExpr

func CloneExpr(expr Expr) Expr

CloneExpr returns a deep copy expr.

func MustParseExprString

func MustParseExprString(s string) Expr

MustParseExprString parses s into an expression. Panic on error.

func ParseExprString

func ParseExprString(s string) (Expr, error)

ParseExprString parses s into an expression. Returns nil if s is blank.

func SplitExprTree

func SplitExprTree(expr Expr) []Expr

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 ExprList

type ExprList struct {
	Lparen Pos    // position of left paren
	Exprs  []Expr // list of expressions
	Rparen Pos    // position of right paren
}

func (*ExprList) Clone

func (l *ExprList) Clone() *ExprList

Clone returns a deep copy of l.

func (*ExprList) String

func (l *ExprList) String() string

String returns the string representation of the expression.

type FilterClause

type FilterClause struct {
	Filter Pos  // position of FILTER keyword
	Lparen Pos  // position of left paren
	Where  Pos  // position of WHERE keyword
	X      Expr // filter expression
	Rparen Pos  // position of right paren
}

func (*FilterClause) Clone

func (c *FilterClause) Clone() *FilterClause

Clone returns a deep copy of c.

func (*FilterClause) String

func (c *FilterClause) String() string

String returns the string representation of the clause.

type ForeignKeyArg

type ForeignKeyArg struct {
	On         Pos // position of ON keyword
	OnUpdate   Pos // position of the UPDATE keyword
	OnDelete   Pos // position of the DELETE keyword
	Set        Pos // position of the SET keyword
	SetNull    Pos // position of the NULL keyword after SET
	SetDefault Pos // position of the DEFAULT keyword after SET
	Cascade    Pos // position of the CASCADE keyword
	Restrict   Pos // position of the RESTRICT keyword
	No         Pos // position of the NO keyword
	NoAction   Pos // position of the ACTION keyword after NO
}

func (*ForeignKeyArg) Clone

func (arg *ForeignKeyArg) Clone() *ForeignKeyArg

Clone returns a deep copy of arg.

func (*ForeignKeyArg) String

func (c *ForeignKeyArg) String() string

String returns the string representation of the argument.

type ForeignKeyConstraint

type ForeignKeyConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name

	Foreign    Pos      // position of FOREIGN keyword (table only)
	ForeignKey Pos      // position of KEY keyword after FOREIGN (table only)
	Lparen     Pos      // position of left paren (table only)
	Columns    []*Ident // indexed columns (table only)
	Rparen     Pos      // position of right paren (table only)

	References         Pos              // position of REFERENCES keyword
	ForeignTable       *Ident           // foreign table name
	ForeignLparen      Pos              // position of left paren
	ForeignColumns     []*Ident         // column list
	ForeignRparen      Pos              // position of right paren
	Args               []*ForeignKeyArg // arguments
	Deferrable         Pos              // position of DEFERRABLE keyword
	Not                Pos              // position of NOT keyword
	NotDeferrable      Pos              // position of DEFERRABLE keyword after NOT
	Initially          Pos              // position of INITIALLY keyword
	InitiallyDeferred  Pos              // position of DEFERRED keyword after INITIALLY
	InitiallyImmediate Pos              // position of IMMEDIATE keyword after INITIALLY
}

func (*ForeignKeyConstraint) Clone

Clone returns a deep copy of c.

func (*ForeignKeyConstraint) String

func (c *ForeignKeyConstraint) String() string

String returns the string representation of the constraint.

type FrameSpec

type FrameSpec struct {
	Range  Pos // position of RANGE keyword
	Rows   Pos // position of ROWS keyword
	Groups Pos // position of GROUPS keyword

	Between Pos // position of BETWEEN keyword

	X           Expr // lhs expression
	UnboundedX  Pos  // position of lhs UNBOUNDED keyword
	PrecedingX  Pos  // position of lhs PRECEDING keyword
	CurrentX    Pos  // position of lhs CURRENT keyword
	CurrentRowX Pos  // position of lhs ROW keyword
	FollowingX  Pos  // position of lhs FOLLOWING keyword

	And Pos // position of AND keyword

	Y           Expr // lhs expression
	UnboundedY  Pos  // position of rhs UNBOUNDED keyword
	FollowingY  Pos  // position of rhs FOLLOWING keyword
	CurrentY    Pos  // position of rhs CURRENT keyword
	CurrentRowY Pos  // position of rhs ROW keyword
	PrecedingY  Pos  // position of rhs PRECEDING keyword

	Exclude           Pos // position of EXCLUDE keyword
	ExcludeNo         Pos // position of NO keyword after EXCLUDE
	ExcludeNoOthers   Pos // position of OTHERS keyword after EXCLUDE NO
	ExcludeCurrent    Pos // position of CURRENT keyword after EXCLUDE
	ExcludeCurrentRow Pos // position of ROW keyword after EXCLUDE CURRENT
	ExcludeGroup      Pos // position of GROUP keyword after EXCLUDE
	ExcludeTies       Pos // position of TIES keyword after EXCLUDE
}

func (*FrameSpec) Clone

func (s *FrameSpec) Clone() *FrameSpec

Clone returns a deep copy of s.

func (*FrameSpec) String

func (s *FrameSpec) String() string

String returns the string representation of the frame spec.

type GeneratedConstraint

type GeneratedConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Generated  Pos    // position of GENERATED keyword
	Always     Pos    // position of ALWAYS keyword
	As         Pos    // position of AS keyword
	Lparen     Pos    // position of left paren
	Expr       Expr   // default expression
	Rparen     Pos    // position of right paren
	Stored     Pos    // position of STORED keyword
	Virtual    Pos    // position of VIRTUAL keyword
}

func (*GeneratedConstraint) Clone

Clone returns a deep copy of c.

func (*GeneratedConstraint) String

func (c *GeneratedConstraint) String() string

String returns the string representation of the constraint.

type Ident

type Ident struct {
	NamePos Pos    // identifier position
	Name    string // identifier name
	Quoted  bool   // true if double quoted
}

func (*Ident) Clone

func (i *Ident) Clone() *Ident

Clone returns a deep copy of i.

func (*Ident) String

func (i *Ident) String() string

String returns the string representation of the expression.

type IndexedColumn

type IndexedColumn struct {
	X         Expr   // column expression
	Collate   Pos    // position of COLLATE keyword
	Collation *Ident // collation name
	Asc       Pos    // position of optional ASC keyword
	Desc      Pos    // position of optional DESC keyword
}

func (*IndexedColumn) Clone

func (c *IndexedColumn) Clone() *IndexedColumn

Clone returns a deep copy of c.

func (*IndexedColumn) String

func (c *IndexedColumn) String() string

String returns the string representation of the column.

type InsertStatement

type InsertStatement struct {
	WithClause *WithClause // clause containing CTEs

	Insert           Pos // position of INSERT keyword
	Replace          Pos // position of REPLACE keyword
	InsertOr         Pos // position of OR keyword after INSERT
	InsertOrReplace  Pos // position of REPLACE keyword after INSERT OR
	InsertOrRollback Pos // position of ROLLBACK keyword after INSERT OR
	InsertOrAbort    Pos // position of ABORT keyword after INSERT OR
	InsertOrFail     Pos // position of FAIL keyword after INSERT OR
	InsertOrIgnore   Pos // position of IGNORE keyword after INSERT OR
	Into             Pos // position of INTO keyword

	Table *Ident // table name
	As    Pos    // position of AS keyword
	Alias *Ident // optional alias

	ColumnsLparen Pos      // position of column list left paren
	Columns       []*Ident // optional column list
	ColumnsRparen Pos      // position of column list right paren

	Values     Pos         // position of VALUES keyword
	ValueLists []*ExprList // lists of lists of values

	Select *SelectStatement // SELECT statement

	Default       Pos // position of DEFAULT keyword
	DefaultValues Pos // position of VALUES keyword after DEFAULT

	UpsertClause    *UpsertClause    // optional upsert clause
	ReturningClause *ReturningClause // optional RETURNING clause
}

func (*InsertStatement) Clone

func (s *InsertStatement) Clone() *InsertStatement

Clone returns a deep copy of s.

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) Clone

func (c *JoinClause) Clone() *JoinClause

Clone returns a deep copy of c.

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.

func CloneJoinConstraint

func CloneJoinConstraint(cons JoinConstraint) JoinConstraint

CloneJoinConstraint returns a deep copy cons.

type JoinOperator

type JoinOperator struct {
	Comma   Pos // position of comma
	Natural Pos // position of NATURAL keyword
	Left    Pos // position of LEFT keyword
	Outer   Pos // position of OUTER keyword
	Inner   Pos // position of INNER keyword
	Cross   Pos // position of CROSS keyword
	Join    Pos // position of JOIN keyword
}

func (*JoinOperator) Clone

func (op *JoinOperator) Clone() *JoinOperator

Clone returns a deep copy of op.

func (*JoinOperator) String

func (op *JoinOperator) String() string

String returns the string representation of the operator.

type Node

type Node interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

type NotNullConstraint

type NotNullConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Not        Pos    // position of NOT keyword
	Null       Pos    // position of NULL keyword
}

func (*NotNullConstraint) Clone

Clone returns a deep copy of c.

func (*NotNullConstraint) String

func (c *NotNullConstraint) String() string

String returns the string representation of the constraint.

type NullLit

type NullLit struct {
	Pos Pos
}

func (*NullLit) Clone

func (lit *NullLit) Clone() *NullLit

Clone returns a deep copy of lit.

func (*NullLit) String

func (lit *NullLit) String() string

String returns the string representation of the expression.

type NumberLit

type NumberLit struct {
	ValuePos Pos    // literal position
	Value    string // literal value
}

func (*NumberLit) Clone

func (lit *NumberLit) Clone() *NumberLit

Clone returns a deep copy of lit.

func (*NumberLit) String

func (lit *NumberLit) String() string

String returns the string representation of the expression.

type OnConstraint

type OnConstraint struct {
	On Pos  // position of ON keyword
	X  Expr // constraint expression
}

func (*OnConstraint) Clone

func (c *OnConstraint) Clone() *OnConstraint

Clone returns a deep copy of c.

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  Pos // position of ASC keyword
	Desc Pos // position of DESC keyword

	Nulls      Pos // position of NULLS keyword
	NullsFirst Pos // position of FIRST keyword
	NullsLast  Pos // position of LAST keyword
}

func (*OrderingTerm) Clone

func (t *OrderingTerm) Clone() *OrderingTerm

Clone returns a deep copy of t.

func (*OrderingTerm) String

func (t *OrderingTerm) String() string

String returns the string representation of the term.

type OverClause

type OverClause struct {
	Over       Pos               // position of OVER keyword
	Name       *Ident            // window name
	Definition *WindowDefinition // window definition
}

func (*OverClause) Clone

func (c *OverClause) Clone() *OverClause

Clone returns a deep copy of c.

func (*OverClause) String

func (c *OverClause) String() string

String returns the string representation of the clause.

type ParenExpr

type ParenExpr struct {
	Lparen Pos  // position of left paren
	X      Expr // parenthesized expression
	Rparen Pos  // position of right paren
}

func (*ParenExpr) Clone

func (expr *ParenExpr) Clone() *ParenExpr

Clone returns a deep copy of expr.

func (*ParenExpr) String

func (expr *ParenExpr) String() string

String returns the string representation of the expression.

type ParenSource

type ParenSource struct {
	Lparen Pos    // position of left paren
	X      Source // nested source
	Rparen Pos    // position of right paren
	As     Pos    // position of AS keyword (select source only)
	Alias  *Ident // optional table alias (select source only)
}

func (*ParenSource) Clone

func (s *ParenSource) Clone() *ParenSource

Clone returns a deep copy of s.

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 NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser that reads from r.

func (*Parser) ParseExpr

func (p *Parser) ParseExpr() (expr Expr, err error)

func (*Parser) ParseStatement

func (p *Parser) ParseStatement() (stmt Statement, err error)

type Pos

type Pos struct {
	Offset int // offset, starting at 0
	Line   int // line number, starting at 1
	Column int // column number, starting at 1 (byte count)
}

func (Pos) IsValid

func (p Pos) IsValid() bool

IsValid returns true if p is non-zero.

func (Pos) String

func (p Pos) String() string

String returns a string representation of the position.

type PrimaryKeyConstraint

type PrimaryKeyConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Primary    Pos    // position of PRIMARY keyword
	Key        Pos    // position of KEY keyword

	Lparen  Pos      // position of left paren (table only)
	Columns []*Ident // indexed columns (table only)
	Rparen  Pos      // position of right paren (table only)

	Autoincrement Pos // position of AUTOINCREMENT keyword (column only)
}

func (*PrimaryKeyConstraint) Clone

Clone returns a deep copy of c.

func (*PrimaryKeyConstraint) String

func (c *PrimaryKeyConstraint) String() string

String returns the string representation of the constraint.

type QualifiedRef

type QualifiedRef struct {
	Table  *Ident // table name
	Dot    Pos    // position of dot
	Star   Pos    // position of * (result column only)
	Column *Ident // column name
}

func (*QualifiedRef) Clone

func (r *QualifiedRef) Clone() *QualifiedRef

Clone returns a deep copy of r.

func (*QualifiedRef) String

func (r *QualifiedRef) String() string

String returns the string representation of the expression.

type QualifiedTableName

type QualifiedTableName struct {
	Name       *Ident // table name
	As         Pos    // position of AS keyword
	Alias      *Ident // optional table alias
	Indexed    Pos    // position of INDEXED keyword
	IndexedBy  Pos    // position of BY keyword after INDEXED
	Not        Pos    // position of NOT keyword before INDEXED
	NotIndexed Pos    // position of NOT keyword before INDEXED
	Index      *Ident // name of index
}

func (*QualifiedTableName) Clone

Clone returns a deep copy of n.

func (*QualifiedTableName) String

func (n *QualifiedTableName) String() string

String returns the string representation of the table name.

func (*QualifiedTableName) TableName

func (n *QualifiedTableName) TableName() string

TableName returns the name used to identify n. Returns the alias, if one is specified. Otherwise returns the name.

type Raise

type Raise struct {
	Raise    Pos        // position of RAISE keyword
	Lparen   Pos        // position of left paren
	Ignore   Pos        // position of IGNORE keyword
	Rollback Pos        // position of ROLLBACK keyword
	Abort    Pos        // position of ABORT keyword
	Fail     Pos        // position of FAIL keyword
	Comma    Pos        // position of comma
	Error    *StringLit // error message
	Rparen   Pos        // position of right paren
}

func (*Raise) Clone

func (r *Raise) Clone() *Raise

Clone returns a deep copy of r.

func (*Raise) String

func (r *Raise) String() string

String returns the string representation of the raise function.

type Range

type Range struct {
	X   Expr // lhs expression
	And Pos  // position of AND keyword
	Y   Expr // rhs expression
}

func (*Range) Clone

func (r *Range) Clone() *Range

Clone returns a deep copy of r.

func (*Range) String

func (r *Range) String() string

String returns the string representation of the expression.

type ReleaseStatement

type ReleaseStatement struct {
	Release   Pos    // position of RELEASE keyword
	Savepoint Pos    // position of SAVEPOINT keyword (optional)
	Name      *Ident // name of savepoint
}

func (*ReleaseStatement) Clone

func (s *ReleaseStatement) Clone() *ReleaseStatement

Clone returns a deep copy of s.

func (*ReleaseStatement) String

func (s *ReleaseStatement) String() string

String returns the string representation of the statement.

type ResultColumn

type ResultColumn struct {
	Star  Pos    // position of *
	Expr  Expr   // column expression (may be "tbl.*")
	As    Pos    // position of AS keyword
	Alias *Ident // alias name
}

func (*ResultColumn) Clone

func (c *ResultColumn) Clone() *ResultColumn

Clone returns a deep copy of c.

func (*ResultColumn) String

func (c *ResultColumn) String() string

String returns the string representation of the column.

type ReturningClause

type ReturningClause struct {
	Returning Pos             // position of RETURNING keyword
	Columns   []*ResultColumn // list of result columns in the SELECT clause
}

func (*ReturningClause) Clone

func (c *ReturningClause) Clone() *ReturningClause

Clone returns a deep copy of c.

func (*ReturningClause) String

func (c *ReturningClause) String() string

String returns the string representation of the clause.

type Rewriter

type Rewriter struct {
	RewriteRand bool
	// contains filtered or unexported fields
}

func (*Rewriter) Do

func (rw *Rewriter) Do(stmt Statement) (Statement, bool, error)

func (*Rewriter) Visit

func (rw *Rewriter) Visit(node Node) (w Visitor, err error)

func (*Rewriter) VisitEnd

func (rw *Rewriter) VisitEnd(node Node) error

type RollbackStatement

type RollbackStatement struct {
	Rollback      Pos    // position of ROLLBACK keyword
	Transaction   Pos    // position of TRANSACTION keyword  (optional)
	To            Pos    // position of TO keyword  (optional)
	Savepoint     Pos    // position of SAVEPOINT keyword  (optional)
	SavepointName *Ident // name of savepoint
}

func (*RollbackStatement) Clone

Clone returns a deep copy of s.

func (*RollbackStatement) String

func (s *RollbackStatement) String() string

String returns the string representation of the statement.

type SavepointStatement

type SavepointStatement struct {
	Savepoint Pos    // position of SAVEPOINT keyword
	Name      *Ident // name of savepoint
}

func (*SavepointStatement) Clone

Clone returns a deep copy of s.

func (*SavepointStatement) String

func (s *SavepointStatement) String() string

String returns the string representation of the statement.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(r io.Reader) *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan() (pos Pos, token Token, lit string)

type Scope

type Scope struct {
	Parent *Scope
	Source Source
}

Scope represents a context for name resolution. Names can be resolved at the current source or in parent scopes.

type SelectStatement

type SelectStatement struct {
	WithClause *WithClause // clause containing CTEs

	Values     Pos         // position of VALUES keyword
	ValueLists []*ExprList // lists of lists of values

	Select   Pos             // position of SELECT keyword
	Distinct Pos             // position of DISTINCT keyword
	All      Pos             // position of ALL keyword
	Columns  []*ResultColumn // list of result columns in the SELECT clause

	From   Pos    // position of FROM keyword
	Source Source // chain of tables & subqueries in FROM clause

	Where     Pos  // position of WHERE keyword
	WhereExpr Expr // condition for WHERE clause

	Group        Pos    // position of GROUP keyword
	GroupBy      Pos    // position of BY keyword after GROUP
	GroupByExprs []Expr // group by expression list
	Having       Pos    // position of HAVING keyword
	HavingExpr   Expr   // HAVING expression

	Window  Pos       // position of WINDOW keyword
	Windows []*Window // window list

	Union     Pos              // position of UNION keyword
	UnionAll  Pos              // position of ALL keyword after UNION
	Intersect Pos              // position of INTERSECT keyword
	Except    Pos              // position of EXCEPT keyword
	Compound  *SelectStatement // compounded SELECT statement

	Order         Pos             // position of ORDER keyword
	OrderBy       Pos             // position of BY keyword after ORDER
	OrderingTerms []*OrderingTerm // terms of ORDER BY clause

	Limit       Pos  // position of LIMIT keyword
	LimitExpr   Expr // limit expression
	Offset      Pos  // position of OFFSET keyword
	OffsetComma Pos  // position of COMMA (instead of OFFSET)
	OffsetExpr  Expr // offset expression
}

func (*SelectStatement) Clone

func (s *SelectStatement) Clone() *SelectStatement

Clone returns a deep copy of s.

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 CloneSource

func CloneSource(src Source) Source

CloneSource returns a deep copy src.

func ResolveSource

func ResolveSource(root Source, name string) Source

ResolveSource returns a source with the given name. This can either be the table name or the alias for a source.

func SourceList

func SourceList(src Source) []Source

SourceList returns a list of scopes in the current scope.

func StatementSource

func StatementSource(stmt Statement) Source

StatementSource returns the root statement for a statement.

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

func CloneStatement

func CloneStatement(stmt Statement) Statement

CloneStatement returns a deep copy stmt.

type StringLit

type StringLit struct {
	ValuePos Pos    // literal position
	Value    string // literal value (without quotes)
}

func (*StringLit) Clone

func (lit *StringLit) Clone() *StringLit

Clone returns a deep copy of lit.

func (*StringLit) String

func (lit *StringLit) String() string

String returns the string representation of the expression.

type TimestampLit

type TimestampLit struct {
	ValuePos Pos    // literal position
	Value    string // literal value
}

func (*TimestampLit) Clone

func (lit *TimestampLit) Clone() *TimestampLit

Clone returns a deep copy of lit.

func (*TimestampLit) String

func (lit *TimestampLit) String() string

String returns the string representation of the expression.

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"
	STRING  // 'string'
	BLOB    // ???
	FLOAT   // 123.45
	INTEGER // 123
	NULL    // NULL
	TRUE    // true
	FALSE   // false
	BIND    //? or ?NNN or :VVV or @VVV or $VVV

	SEMI   // ;
	LP     // (
	RP     // )
	COMMA  // ,
	NE     // !=
	EQ     // =
	LE     // <=
	LT     // <
	GT     // >
	GE     // >=
	BITAND // &
	BITOR  // |
	BITNOT // !
	LSHIFT // <<
	RSHIFT // >>
	PLUS   // +
	MINUS  // -
	STAR   // *
	SLASH  // /
	REM    // %
	CONCAT // ||
	DOT    // .

	JSON_EXTRACT_JSON // ->
	JSON_EXTRACT_SQL  // ->>

	ABORT
	ACTION
	ADD
	AFTER
	AGG_COLUMN
	AGG_FUNCTION
	ALL
	ALTER
	ALWAYS
	ANALYZE
	AND
	AS
	ASC
	ASTERISK
	ATTACH
	AUTOINCREMENT
	BEFORE
	BEGIN
	BETWEEN
	BY
	CASCADE
	CASE
	CAST
	CHECK
	COLLATE
	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
	GENERATED
	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
	OR
	ORDER
	OTHERS
	OUTER
	OVER
	PARTITION
	PLAN
	PRAGMA
	PRECEDING
	PRIMARY
	QUERY
	RAISE
	RANGE
	RECURSIVE
	REFERENCES
	REGEXP
	REGISTER
	REINDEX
	RELEASE
	RENAME
	REPLACE
	RESTRICT
	RETURNING
	ROLLBACK
	ROW
	ROWID
	ROWS
	SAVEPOINT
	SELECT
	SELECT_COLUMN
	SET
	SPAN
	STORED
	STRICT
	TABLE
	TEMP
	THEN
	TIES
	TO
	TRANSACTION
	TRIGGER
	TRUTH
	UNBOUNDED
	UNION
	UNIQUE
	UPDATE
	USING
	VACUUM
	VALUES
	VARIABLE
	VECTOR
	VIEW
	VIRTUAL
	WHEN
	WHERE
	WINDOW
	WITH
	WITHOUT

	ANY // ???

)

The list of tokens.

func Lookup

func Lookup(ident string) Token

func (Token) IsBinaryOp

func (tok Token) IsBinaryOp() bool

func (Token) IsLiteral

func (tok Token) IsLiteral() bool

func (Token) Precedence

func (op Token) Precedence() int

func (Token) String

func (tok Token) String() string

type Type

type Type struct {
	Name      *Ident     // type name
	Lparen    Pos        // position of left paren (optional)
	Precision *NumberLit // precision (optional)
	Scale     *NumberLit // scale (optional)
	Rparen    Pos        // position of right paren (optional)
}

func (*Type) Clone

func (t *Type) Clone() *Type

Clone returns a deep copy of t.

func (*Type) String

func (t *Type) String() string

String returns the string representation of the type.

type UnaryExpr

type UnaryExpr struct {
	OpPos Pos   // operation position
	Op    Token // operation
	X     Expr  // target expression
}

func (*UnaryExpr) Clone

func (expr *UnaryExpr) Clone() *UnaryExpr

Clone returns a deep copy of expr.

func (*UnaryExpr) String

func (expr *UnaryExpr) String() string

String returns the string representation of the expression.

type UniqueConstraint

type UniqueConstraint struct {
	Constraint Pos    // position of CONSTRAINT keyword
	Name       *Ident // constraint name
	Unique     Pos    // position of UNIQUE keyword

	Lparen  Pos              // position of left paren (table only)
	Columns []*IndexedColumn // indexed columns (table only)
	Rparen  Pos              // position of right paren (table only)
}

func (*UniqueConstraint) Clone

func (c *UniqueConstraint) Clone() *UniqueConstraint

Clone returns a deep copy of c.

func (*UniqueConstraint) String

func (c *UniqueConstraint) String() string

String returns the string representation of the constraint.

type UpdateStatement

type UpdateStatement struct {
	WithClause *WithClause // clause containing CTEs

	Update           Pos // position of UPDATE keyword
	UpdateOr         Pos // position of OR keyword after UPDATE
	UpdateOrReplace  Pos // position of REPLACE keyword after UPDATE OR
	UpdateOrRollback Pos // position of ROLLBACK keyword after UPDATE OR
	UpdateOrAbort    Pos // position of ABORT keyword after UPDATE OR
	UpdateOrFail     Pos // position of FAIL keyword after UPDATE OR
	UpdateOrIgnore   Pos // position of IGNORE keyword after UPDATE OR

	Table *QualifiedTableName // table name

	Set         Pos           // position of SET keyword
	Assignments []*Assignment // list of column assignments
	Where       Pos           // position of WHERE keyword
	WhereExpr   Expr          // conditional expression

	ReturningClause *ReturningClause // optional RETURNING clause
}

func (*UpdateStatement) Clone

func (s *UpdateStatement) Clone() *UpdateStatement

Clone returns a deep copy of s.

func (*UpdateStatement) String

func (s *UpdateStatement) String() string

String returns the string representation of the clause.

type UpsertClause

type UpsertClause struct {
	On         Pos // position of ON keyword
	OnConflict Pos // position of CONFLICT keyword after ON

	Lparen    Pos              // position of column list left paren
	Columns   []*IndexedColumn // optional indexed column list
	Rparen    Pos              // position of column list right paren
	Where     Pos              // position of WHERE keyword
	WhereExpr Expr             // optional conditional expression

	Do              Pos           // position of DO keyword
	DoNothing       Pos           // position of NOTHING keyword after DO
	DoUpdate        Pos           // position of UPDATE keyword after DO
	DoUpdateSet     Pos           // position of SET keyword after DO UPDATE
	Assignments     []*Assignment // list of column assignments
	UpdateWhere     Pos           // position of WHERE keyword for DO UPDATE SET
	UpdateWhereExpr Expr          // optional conditional expression for DO UPDATE SET
}

func (*UpsertClause) Clone

func (c *UpsertClause) Clone() *UpsertClause

Clone returns a deep copy of c.

func (*UpsertClause) String

func (c *UpsertClause) String() string

String returns the string representation of the clause.

type UsingConstraint

type UsingConstraint struct {
	Using   Pos      // position of USING keyword
	Lparen  Pos      // position of left paren
	Columns []*Ident // column list
	Rparen  Pos      // position of right paren
}

func (*UsingConstraint) Clone

func (c *UsingConstraint) Clone() *UsingConstraint

Clone returns a deep copy of c.

func (*UsingConstraint) String

func (c *UsingConstraint) String() string

String returns the string representation of the constraint.

type VisitEndFunc

type VisitEndFunc func(Node) error

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

type VisitFunc func(Node) error

VisitFunc represents a function type that implements Visitor. Only executes on node entry.

func (VisitFunc) Visit

func (fn VisitFunc) Visit(node Node) (Visitor, error)

Visit executes fn. Walk visits node children if fn returns true.

func (VisitFunc) VisitEnd

func (fn VisitFunc) VisitEnd(node Node) error

VisitEnd is a no-op.

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor, err error)
	VisitEnd(node Node) error
}

A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

type Window

type Window struct {
	Name       *Ident            // name of window
	As         Pos               // position of AS keyword
	Definition *WindowDefinition // window definition
}

func (*Window) Clone

func (w *Window) Clone() *Window

Clone returns a deep copy of w.

func (*Window) String

func (w *Window) String() string

String returns the string representation of the window.

type WindowDefinition

type WindowDefinition struct {
	Lparen        Pos             // position of left paren
	Base          *Ident          // base window name
	Partition     Pos             // position of PARTITION keyword
	PartitionBy   Pos             // position of BY keyword (after PARTITION)
	Partitions    []Expr          // partition expressions
	Order         Pos             // position of ORDER keyword
	OrderBy       Pos             // position of BY keyword (after ORDER)
	OrderingTerms []*OrderingTerm // ordering terms
	Frame         *FrameSpec      // frame
	Rparen        Pos             // position of right paren
}

func (*WindowDefinition) Clone

func (d *WindowDefinition) Clone() *WindowDefinition

Clone returns a deep copy of d.

func (*WindowDefinition) String

func (d *WindowDefinition) String() string

String returns the string representation of the window definition.

type WithClause

type WithClause struct {
	With      Pos    // position of WITH keyword
	Recursive Pos    // position of RECURSIVE keyword
	CTEs      []*CTE // common table expressions
}

func (*WithClause) Clone

func (c *WithClause) Clone() *WithClause

Clone returns a deep copy of c.

func (*WithClause) String

func (c *WithClause) String() string

String returns the string representation of the clause.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL