visitors

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LimitOffset is param name of the first ? of limit ?,?
	LimitOffset = "Offset"
	// LimitCount is param name of the second ? of limit ?,?
	LimitCount = "Count"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Type   ErrorType
	Detail string
}

Error -

func NewError

func NewError(t ErrorType, detail string) Error

NewError -

func NewErrorf

func NewErrorf(t ErrorType, format string, arg ...interface{}) Error

NewErrorf -

func (Error) Error

func (e Error) Error() string

type ErrorType

type ErrorType int

ErrorType -

const (
	// ErrNotSupported not supported sql syntax
	ErrNotSupported ErrorType = iota
	// ErrInvalidExpr invalid
	ErrInvalidExpr
	// ErrTypeCheck type check failed
	ErrTypeCheck
	// ErrCompilerError unexpected behavior in code.
	ErrCompilerError
)

type GoParam

type GoParam struct {
	Name      string
	TableName string
	InPattern bool
	Order     int
	Marker    *driver.ParamMarkerExpr
}

GoParam is a param with name, order, and the pointer to param obj.

func (GoParam) GoType

func (g GoParam) GoType() schema.GoType

GoType return GoType of the param.

func (GoParam) String

func (g GoParam) String() string

type GoVar

type GoVar struct {
	TableName string
	Name      string
	Type      schema.GoType
}

GoVar - is a go variable with name and type.

type NameResolveVisitor

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

NameResolveVisitor -

func NewNameResolveVisitor

func NewNameResolveVisitor(db []schema.SQLTable) *NameResolveVisitor

NewNameResolveVisitor - after: all ColumnName will have fully qualified names (i.e. table.col), aliasing will be kept.

func (NameResolveVisitor) AppendErr

func (b NameResolveVisitor) AppendErr(err Error)

func (NameResolveVisitor) DisableLogging added in v0.3.0

func (b NameResolveVisitor) DisableLogging(y bool)

func (*NameResolveVisitor) Enter

func (c *NameResolveVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (NameResolveVisitor) Errors

func (b NameResolveVisitor) Errors() []error

func (NameResolveVisitor) FindInCtx

func (b NameResolveVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (NameResolveVisitor) FindInCtxAnyOf

func (b NameResolveVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (NameResolveVisitor) IsEnteringRoot

func (b NameResolveVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (NameResolveVisitor) IsLeavingRoot

func (b NameResolveVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*NameResolveVisitor) Leave

func (c *NameResolveVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

func (NameResolveVisitor) LogCE

func (b NameResolveVisitor) LogCE(f string, args ...interface{})

compiler error

func (NameResolveVisitor) LogInfo

func (b NameResolveVisitor) LogInfo(f string, args ...interface{})

user info

func (NameResolveVisitor) LogWarn

func (b NameResolveVisitor) LogWarn(f string, args ...interface{})

user warning

type OutputExtractVisitor

type OutputExtractVisitor struct {
	Output []GoVar
	// contains filtered or unexported fields
}

OutputExtractVisitor -

func NewOutputExtractVisitor

func NewOutputExtractVisitor() *OutputExtractVisitor

NewOutputExtractVisitor -

func (OutputExtractVisitor) AppendErr

func (b OutputExtractVisitor) AppendErr(err Error)

func (OutputExtractVisitor) DisableLogging added in v0.3.0

func (b OutputExtractVisitor) DisableLogging(y bool)

func (*OutputExtractVisitor) Enter

func (s *OutputExtractVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (OutputExtractVisitor) Errors

func (b OutputExtractVisitor) Errors() []error

func (OutputExtractVisitor) FindInCtx

func (b OutputExtractVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (OutputExtractVisitor) FindInCtxAnyOf

func (b OutputExtractVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (OutputExtractVisitor) IsEnteringRoot

func (b OutputExtractVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (OutputExtractVisitor) IsLeavingRoot

func (b OutputExtractVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*OutputExtractVisitor) Leave

func (s *OutputExtractVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

func (OutputExtractVisitor) LogCE

func (b OutputExtractVisitor) LogCE(f string, args ...interface{})

compiler error

func (OutputExtractVisitor) LogInfo

func (b OutputExtractVisitor) LogInfo(f string, args ...interface{})

user info

func (OutputExtractVisitor) LogWarn

func (b OutputExtractVisitor) LogWarn(f string, args ...interface{})

user warning

type ParamExtractVisitor

type ParamExtractVisitor struct {
	Params []GoParam
	// contains filtered or unexported fields
}

ParamExtractVisitor - only mysql driver are supported, backend pass. premis: insert stmt has only one value(?, ?...) markers.

func NewParamExtractVisitor

func NewParamExtractVisitor() *ParamExtractVisitor

NewParamExtractVisitor -

func (ParamExtractVisitor) AppendErr

func (b ParamExtractVisitor) AppendErr(err Error)

func (ParamExtractVisitor) DisableLogging added in v0.3.0

func (b ParamExtractVisitor) DisableLogging(y bool)

func (*ParamExtractVisitor) Enter

func (c *ParamExtractVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (ParamExtractVisitor) Errors

func (b ParamExtractVisitor) Errors() []error

func (ParamExtractVisitor) FindInCtx

func (b ParamExtractVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (ParamExtractVisitor) FindInCtxAnyOf

func (b ParamExtractVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (ParamExtractVisitor) IsEnteringRoot

func (b ParamExtractVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (ParamExtractVisitor) IsLeavingRoot

func (b ParamExtractVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*ParamExtractVisitor) Leave

func (c *ParamExtractVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

func (ParamExtractVisitor) LogCE

func (b ParamExtractVisitor) LogCE(f string, args ...interface{})

compiler error

func (ParamExtractVisitor) LogInfo

func (b ParamExtractVisitor) LogInfo(f string, args ...interface{})

user info

func (ParamExtractVisitor) LogWarn

func (b ParamExtractVisitor) LogWarn(f string, args ...interface{})

user warning

type PrintFunc

type PrintFunc = func(format string, a ...interface{})

PrintFunc - print to.

type PrinterVisitor

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

PrinterVisitor -

func NewPrinterVisitor

func NewPrinterVisitor(print PrintFunc, format string) *PrinterVisitor

NewPrinterVisitor -

func (*PrinterVisitor) Enter

func (c *PrinterVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (*PrinterVisitor) Leave

func (c *PrinterVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

type StarElimVisitor

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

StarElimVisitor - eliminate * in select by replacing it with a list of fields.

func NewStarElimVisitor

func NewStarElimVisitor(tb schema.SQLTable) *StarElimVisitor

NewStarElimVisitor -

func (StarElimVisitor) AppendErr

func (b StarElimVisitor) AppendErr(err Error)

func (StarElimVisitor) DisableLogging added in v0.3.0

func (b StarElimVisitor) DisableLogging(y bool)

func (*StarElimVisitor) Enter

func (s *StarElimVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (StarElimVisitor) Errors

func (b StarElimVisitor) Errors() []error

func (StarElimVisitor) FindInCtx

func (b StarElimVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (StarElimVisitor) FindInCtxAnyOf

func (b StarElimVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (StarElimVisitor) IsEnteringRoot

func (b StarElimVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (StarElimVisitor) IsLeavingRoot

func (b StarElimVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*StarElimVisitor) Leave

func (s *StarElimVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

func (StarElimVisitor) LogCE

func (b StarElimVisitor) LogCE(f string, args ...interface{})

compiler error

func (StarElimVisitor) LogInfo

func (b StarElimVisitor) LogInfo(f string, args ...interface{})

user info

func (StarElimVisitor) LogWarn

func (b StarElimVisitor) LogWarn(f string, args ...interface{})

user warning

type TableAsVisitor

type TableAsVisitor struct {
	TableNames map[string]bool
	TableAlias map[string]string
	// contains filtered or unexported fields
}

TableAsVisitor - after apply, contains a mapping from alias to original table names. It will also check table name uniqueness, name shadowing.

func NewTableAsVisitor

func NewTableAsVisitor(tableNames []string) *TableAsVisitor

NewTableAsVisitor - @p tableNames defined tables.

func (TableAsVisitor) AppendErr

func (b TableAsVisitor) AppendErr(err Error)

func (TableAsVisitor) DisableLogging added in v0.3.0

func (b TableAsVisitor) DisableLogging(y bool)

func (*TableAsVisitor) Enter

func (c *TableAsVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (TableAsVisitor) Errors

func (b TableAsVisitor) Errors() []error

func (TableAsVisitor) FindInCtx

func (b TableAsVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (TableAsVisitor) FindInCtxAnyOf

func (b TableAsVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (TableAsVisitor) IsEnteringRoot

func (b TableAsVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (TableAsVisitor) IsLeavingRoot

func (b TableAsVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*TableAsVisitor) Leave

func (c *TableAsVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor

func (TableAsVisitor) LogCE

func (b TableAsVisitor) LogCE(f string, args ...interface{})

compiler error

func (TableAsVisitor) LogInfo

func (b TableAsVisitor) LogInfo(f string, args ...interface{})

user info

func (TableAsVisitor) LogWarn

func (b TableAsVisitor) LogWarn(f string, args ...interface{})

user warning

type TypeInferenceVisitor

type TypeInferenceVisitor struct {
	DBInfo []schema.SQLTable
	// contains filtered or unexported fields
}

TypeInferenceVisitor - assign types to terms. premise: all column names are fully qualified. after: all ColumnNameExpr will have its type field set to be the type defined

in the schema file. ColumnNameExpr in select will have its
type field set to column's type, function call term's type will resolve to
the type of the return value.
Terms as input(driver.ParamMarkerExpr), will have its type,
inferred from binary operations, assignments...

func NewTypeInferenceVisitor

func NewTypeInferenceVisitor(dbs []schema.SQLTable) *TypeInferenceVisitor

NewTypeInferenceVisitor - schema is used for column's type.

func (TypeInferenceVisitor) AppendErr

func (b TypeInferenceVisitor) AppendErr(err Error)

func (TypeInferenceVisitor) DisableLogging added in v0.3.0

func (b TypeInferenceVisitor) DisableLogging(y bool)

func (*TypeInferenceVisitor) Enter

func (t *TypeInferenceVisitor) Enter(n ast.Node) (ast.Node, bool)

Enter - Implements Visitor

func (TypeInferenceVisitor) Errors

func (b TypeInferenceVisitor) Errors() []error

func (TypeInferenceVisitor) FindInCtx

func (b TypeInferenceVisitor) FindInCtx(t ast.Node) (ast.Node, bool)

FindInCtx - Returns the closest node that has @p t.

func (TypeInferenceVisitor) FindInCtxAnyOf

func (b TypeInferenceVisitor) FindInCtxAnyOf(types ...ast.Node) (ast.Node, bool)

FindInCtxAnyOf return closest node with type is any of @p types.

func (TypeInferenceVisitor) IsEnteringRoot

func (b TypeInferenceVisitor) IsEnteringRoot() bool

IsEnteringRoot - enter in root node

func (TypeInferenceVisitor) IsLeavingRoot

func (b TypeInferenceVisitor) IsLeavingRoot() bool

/ IsLeavingRoot - leave root node

func (*TypeInferenceVisitor) Leave

func (t *TypeInferenceVisitor) Leave(n ast.Node) (ast.Node, bool)

Leave - Implements Visitor premise: visitors visit left hand size of binary operation first.

func (TypeInferenceVisitor) LogCE

func (b TypeInferenceVisitor) LogCE(f string, args ...interface{})

compiler error

func (TypeInferenceVisitor) LogInfo

func (b TypeInferenceVisitor) LogInfo(f string, args ...interface{})

user info

func (TypeInferenceVisitor) LogWarn

func (b TypeInferenceVisitor) LogWarn(f string, args ...interface{})

user warning

Jump to

Keyboard shortcuts

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