Remove visitor.

This commit is contained in:
go-jet 2019-08-12 10:16:08 +02:00
parent 01f43d462a
commit e02e08a6ba
17 changed files with 8 additions and 158 deletions

View file

@ -67,10 +67,6 @@ type castExpression struct {
cast string
}
func (b *castExpression) accept(visitor visitor) {
b.expression.accept(visitor)
}
func (b *castExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
expression := b.expression

View file

@ -20,7 +20,6 @@ type ColumnExpression interface {
// The base type for real materialized columns.
type columnImpl struct {
ExpressionInterfaceImpl
noOpVisitorImpl
name string
tableName string

View file

@ -3,7 +3,6 @@ package jet
type enumValue struct {
ExpressionInterfaceImpl
stringInterfaceImpl
noOpVisitorImpl
name string
}

View file

@ -7,12 +7,6 @@ import (
// Expression is common interface for all expressions.
// Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions.
type Expression interface {
acceptsVisitor
IExpression
}
type IExpression interface {
Serializer
Projection
GroupByClause
@ -101,11 +95,6 @@ func newBinaryExpression(lhs, rhs Expression, operator string) binaryOpExpressio
return binaryExpression
}
func (c *binaryOpExpression) accept(visitor visitor) {
c.lhs.accept(visitor)
c.rhs.accept(visitor)
}
func (c *binaryOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) {
if c == nil {
return errors.New("jet: binary Expression is nil")
@ -162,10 +151,6 @@ func newPrefixExpression(expression Expression, operator string) prefixOpExpress
return prefixExpression
}
func (p *prefixOpExpression) accept(visitor visitor) {
p.expression.accept(visitor)
}
func (p *prefixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
if p == nil {
return errors.New("jet: Prefix Expression is nil")
@ -201,10 +186,6 @@ func newPostfixOpExpression(expression Expression, operator string) postfixOpExp
return postfixOpExpression
}
func (p *postfixOpExpression) accept(visitor visitor) {
p.expression.accept(visitor)
}
func (p *postfixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
if p == nil {
return errors.New("jet: Postifx operator Expression is nil")

View file

@ -500,14 +500,6 @@ func newFunc(name string, expressions []Expression, parent Expression) *funcExpr
return funcExp
}
func (f *funcExpressionImpl) accept(visitor visitor) {
visitor.visit(f)
for _, exp := range f.expressions {
exp.accept(visitor)
}
}
func (f *funcExpressionImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
if f == nil {
return errors.New("jet: Function expressions is nil. ")

View file

@ -16,7 +16,6 @@ type LiteralExpression interface {
type literalExpressionImpl struct {
ExpressionInterfaceImpl
noOpVisitorImpl
value interface{}
constant bool
@ -205,7 +204,6 @@ func DateT(t time.Time) DateExpression {
//--------------------------------------------------//
type nullLiteral struct {
ExpressionInterfaceImpl
noOpVisitorImpl
}
func newNullLiteral() Expression {
@ -224,7 +222,6 @@ func (n *nullLiteral) serialize(statement StatementType, out *SqlBuilder, option
//--------------------------------------------------//
type starLiteral struct {
ExpressionInterfaceImpl
noOpVisitorImpl
}
func newStarLiteral() Expression {
@ -247,12 +244,6 @@ type wrap struct {
expressions []Expression
}
func (n *wrap) accept(visitor visitor) {
for _, exp := range n.expressions {
exp.accept(visitor)
}
}
func (n *wrap) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
out.WriteString("(")
err := serializeExpressionList(statement, n.expressions, ", ", out)
@ -272,7 +263,6 @@ func WRAP(expression ...Expression) Expression {
type rawExpression struct {
ExpressionInterfaceImpl
noOpVisitorImpl
raw string
}

View file

@ -2,6 +2,10 @@ package jet
import "errors"
const (
StringConcatOperator = "||"
)
//----------- Logical operators ---------------//
// NOT returns negation of bool expression result
@ -108,24 +112,6 @@ func (c *caseOperatorImpl) ELSE(els Expression) CaseOperator {
return c
}
func (c *caseOperatorImpl) accept(visitor visitor) {
visitor.visit(c)
c.expression.accept(visitor)
for _, when := range c.when {
when.accept(visitor)
}
for _, then := range c.then {
then.accept(visitor)
}
if c.els != nil {
c.els.accept(visitor)
}
}
func (c *caseOperatorImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
if c == nil {
return errors.New("jet: Case Expression is nil. ")

View file

@ -31,11 +31,6 @@ func (s *SelectTableImpl2) Alias() string {
return s.alias
}
func (s *SelectTableImpl2) accept(visitor visitor) {
visitor.visit(s)
s.selectStmt.accept(visitor)
}
func (s *SelectTableImpl2) AllColumns() ProjectionList {
return s.projections
}

View file

@ -9,7 +9,6 @@ import (
//Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
type Statement interface {
acceptsVisitor
// Sql returns parametrized sql query with list of arguments.
// err is returned if statement is not composed correctly
Sql() (query string, args []interface{}, err error)
@ -47,7 +46,6 @@ type HasProjections interface {
}
type SerializerStatementInterfaceImpl struct {
noOpVisitorImpl
dialect Dialect
statementType StatementType
parent SerializerStatement
@ -144,7 +142,6 @@ func NewStatementImpl(Dialect Dialect, statementType StatementType, parent Seria
type StatementImpl struct {
SerializerStatementInterfaceImpl
acceptsVisitor
Clauses []Clause
}

View file

@ -1,9 +1,5 @@
package jet
const (
StringConcatOperator = "||"
)
// StringExpression interface
type StringExpression interface {
Expression

View file

@ -66,10 +66,6 @@ func (t *TableImpl) Columns() []Column {
return ret
}
func (t *TableImpl) accept(visitor visitor) {
visitor.visit(t)
}
func (t *TableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
if t == nil {
return errors.New("jet: tableImpl is nil. ")
@ -130,12 +126,6 @@ func (t *JoinTableImpl) Columns() []Column {
panic("Unimplemented")
}
func (t *JoinTableImpl) accept(visitor visitor) {
//t.lhs.accept(visitor)
//t.rhs.accept(visitor)
//TODO: remove
}
func (t *JoinTableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) {
if t == nil {
return errors.New("jet: Join table is nil. ")

View file

@ -1,63 +0,0 @@
package jet
type visitor interface {
visit(element acceptsVisitor)
}
type acceptsVisitor interface {
accept(visitor visitor)
}
type noOpVisitorImpl struct {
}
func (n *noOpVisitorImpl) accept(visitor visitor) {
// NO OP
}
// --------------- dialect finder -----------------//
type DialectFinder struct {
dialects map[string]Dialect
}
func newDialectFinder() *DialectFinder {
return &DialectFinder{
dialects: make(map[string]Dialect),
}
}
func (f *DialectFinder) mustGetDialect() Dialect {
if len(f.dialects) == 0 {
panic("jet: can't detect dialect")
}
if len(f.dialects) > 1 {
panic("jet: more than one dialect detected")
}
for _, dialect := range f.dialects {
return dialect
}
panic("jet: internal error")
}
func (f *DialectFinder) visit(element acceptsVisitor) {
//if table, ok := element.(TableBase); ok {
// dialect := table.dialect()
// f.dialects[dialect.Name()] = dialect
//}
}
func detectDialect(element acceptsVisitor, dialectOverride ...Dialect) Dialect {
if len(dialectOverride) > 0 {
return dialectOverride[0]
}
dialectFinder := newDialectFinder()
element.accept(dialectFinder)
return dialectFinder.mustGetDialect()
}