Remove visitor.
This commit is contained in:
parent
01f43d462a
commit
e02e08a6ba
17 changed files with 8 additions and 158 deletions
|
|
@ -67,10 +67,6 @@ type castExpression struct {
|
||||||
cast string
|
cast string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *castExpression) accept(visitor visitor) {
|
|
||||||
b.expression.accept(visitor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *castExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
func (b *castExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
|
|
||||||
expression := b.expression
|
expression := b.expression
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ type ColumnExpression interface {
|
||||||
// The base type for real materialized columns.
|
// The base type for real materialized columns.
|
||||||
type columnImpl struct {
|
type columnImpl struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
|
|
||||||
name string
|
name string
|
||||||
tableName string
|
tableName string
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package jet
|
||||||
type enumValue struct {
|
type enumValue struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
stringInterfaceImpl
|
stringInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
|
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ import (
|
||||||
// Expression is common interface for all expressions.
|
// Expression is common interface for all expressions.
|
||||||
// Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions.
|
// Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions.
|
||||||
type Expression interface {
|
type Expression interface {
|
||||||
acceptsVisitor
|
|
||||||
|
|
||||||
IExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
type IExpression interface {
|
|
||||||
Serializer
|
Serializer
|
||||||
Projection
|
Projection
|
||||||
GroupByClause
|
GroupByClause
|
||||||
|
|
@ -101,11 +95,6 @@ func newBinaryExpression(lhs, rhs Expression, operator string) binaryOpExpressio
|
||||||
return binaryExpression
|
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) {
|
func (c *binaryOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return errors.New("jet: binary Expression is nil")
|
return errors.New("jet: binary Expression is nil")
|
||||||
|
|
@ -162,10 +151,6 @@ func newPrefixExpression(expression Expression, operator string) prefixOpExpress
|
||||||
return prefixExpression
|
return prefixExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prefixOpExpression) accept(visitor visitor) {
|
|
||||||
p.expression.accept(visitor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *prefixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
func (p *prefixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return errors.New("jet: Prefix Expression is nil")
|
return errors.New("jet: Prefix Expression is nil")
|
||||||
|
|
@ -201,10 +186,6 @@ func newPostfixOpExpression(expression Expression, operator string) postfixOpExp
|
||||||
return postfixOpExpression
|
return postfixOpExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postfixOpExpression) accept(visitor visitor) {
|
|
||||||
p.expression.accept(visitor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *postfixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
func (p *postfixOpExpression) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return errors.New("jet: Postifx operator Expression is nil")
|
return errors.New("jet: Postifx operator Expression is nil")
|
||||||
|
|
|
||||||
|
|
@ -500,14 +500,6 @@ func newFunc(name string, expressions []Expression, parent Expression) *funcExpr
|
||||||
return funcExp
|
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 {
|
func (f *funcExpressionImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return errors.New("jet: Function expressions is nil. ")
|
return errors.New("jet: Function expressions is nil. ")
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ type LiteralExpression interface {
|
||||||
|
|
||||||
type literalExpressionImpl struct {
|
type literalExpressionImpl struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
|
|
||||||
value interface{}
|
value interface{}
|
||||||
constant bool
|
constant bool
|
||||||
|
|
@ -205,7 +204,6 @@ func DateT(t time.Time) DateExpression {
|
||||||
//--------------------------------------------------//
|
//--------------------------------------------------//
|
||||||
type nullLiteral struct {
|
type nullLiteral struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNullLiteral() Expression {
|
func newNullLiteral() Expression {
|
||||||
|
|
@ -224,7 +222,6 @@ func (n *nullLiteral) serialize(statement StatementType, out *SqlBuilder, option
|
||||||
//--------------------------------------------------//
|
//--------------------------------------------------//
|
||||||
type starLiteral struct {
|
type starLiteral struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStarLiteral() Expression {
|
func newStarLiteral() Expression {
|
||||||
|
|
@ -247,12 +244,6 @@ type wrap struct {
|
||||||
expressions []Expression
|
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 {
|
func (n *wrap) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
out.WriteString("(")
|
out.WriteString("(")
|
||||||
err := serializeExpressionList(statement, n.expressions, ", ", out)
|
err := serializeExpressionList(statement, n.expressions, ", ", out)
|
||||||
|
|
@ -272,7 +263,6 @@ func WRAP(expression ...Expression) Expression {
|
||||||
|
|
||||||
type rawExpression struct {
|
type rawExpression struct {
|
||||||
ExpressionInterfaceImpl
|
ExpressionInterfaceImpl
|
||||||
noOpVisitorImpl
|
|
||||||
|
|
||||||
raw string
|
raw string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ package jet
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
|
const (
|
||||||
|
StringConcatOperator = "||"
|
||||||
|
)
|
||||||
|
|
||||||
//----------- Logical operators ---------------//
|
//----------- Logical operators ---------------//
|
||||||
|
|
||||||
// NOT returns negation of bool expression result
|
// NOT returns negation of bool expression result
|
||||||
|
|
@ -108,24 +112,6 @@ func (c *caseOperatorImpl) ELSE(els Expression) CaseOperator {
|
||||||
return c
|
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 {
|
func (c *caseOperatorImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return errors.New("jet: Case Expression is nil. ")
|
return errors.New("jet: Case Expression is nil. ")
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,6 @@ func (s *SelectTableImpl2) Alias() string {
|
||||||
return s.alias
|
return s.alias
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SelectTableImpl2) accept(visitor visitor) {
|
|
||||||
visitor.visit(s)
|
|
||||||
s.selectStmt.accept(visitor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SelectTableImpl2) AllColumns() ProjectionList {
|
func (s *SelectTableImpl2) AllColumns() ProjectionList {
|
||||||
return s.projections
|
return s.projections
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
//Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
|
//Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)
|
||||||
type Statement interface {
|
type Statement interface {
|
||||||
acceptsVisitor
|
|
||||||
// Sql returns parametrized sql query with list of arguments.
|
// Sql returns parametrized sql query with list of arguments.
|
||||||
// err is returned if statement is not composed correctly
|
// err is returned if statement is not composed correctly
|
||||||
Sql() (query string, args []interface{}, err error)
|
Sql() (query string, args []interface{}, err error)
|
||||||
|
|
@ -47,7 +46,6 @@ type HasProjections interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SerializerStatementInterfaceImpl struct {
|
type SerializerStatementInterfaceImpl struct {
|
||||||
noOpVisitorImpl
|
|
||||||
dialect Dialect
|
dialect Dialect
|
||||||
statementType StatementType
|
statementType StatementType
|
||||||
parent SerializerStatement
|
parent SerializerStatement
|
||||||
|
|
@ -144,7 +142,6 @@ func NewStatementImpl(Dialect Dialect, statementType StatementType, parent Seria
|
||||||
|
|
||||||
type StatementImpl struct {
|
type StatementImpl struct {
|
||||||
SerializerStatementInterfaceImpl
|
SerializerStatementInterfaceImpl
|
||||||
acceptsVisitor
|
|
||||||
|
|
||||||
Clauses []Clause
|
Clauses []Clause
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
package jet
|
package jet
|
||||||
|
|
||||||
const (
|
|
||||||
StringConcatOperator = "||"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StringExpression interface
|
// StringExpression interface
|
||||||
type StringExpression interface {
|
type StringExpression interface {
|
||||||
Expression
|
Expression
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,6 @@ func (t *TableImpl) Columns() []Column {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableImpl) accept(visitor visitor) {
|
|
||||||
visitor.visit(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
func (t *TableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return errors.New("jet: tableImpl is nil. ")
|
return errors.New("jet: tableImpl is nil. ")
|
||||||
|
|
@ -130,12 +126,6 @@ func (t *JoinTableImpl) Columns() []Column {
|
||||||
panic("Unimplemented")
|
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) {
|
func (t *JoinTableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return errors.New("jet: Join table is nil. ")
|
return errors.New("jet: Join table is nil. ")
|
||||||
|
|
|
||||||
|
|
@ -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()
|
|
||||||
}
|
|
||||||
|
|
@ -12,7 +12,7 @@ var (
|
||||||
type SelectStatement interface {
|
type SelectStatement interface {
|
||||||
jet.Statement
|
jet.Statement
|
||||||
jet.HasProjections
|
jet.HasProjections
|
||||||
jet.IExpression
|
jet.Expression
|
||||||
|
|
||||||
DISTINCT() SelectStatement
|
DISTINCT() SelectStatement
|
||||||
FROM(table ReadableTable) SelectStatement
|
FROM(table ReadableTable) SelectStatement
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type SetStatementFinal interface {
|
||||||
type SetOperators interface {
|
type SetOperators interface {
|
||||||
jet.Statement
|
jet.Statement
|
||||||
jet.HasProjections
|
jet.HasProjections
|
||||||
jet.IExpression
|
jet.Expression
|
||||||
|
|
||||||
UNION(rhs SelectStatement) SetStatement
|
UNION(rhs SelectStatement) SetStatement
|
||||||
UNION_ALL(rhs SelectStatement) SetStatement
|
UNION_ALL(rhs SelectStatement) SetStatement
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ var (
|
||||||
type SelectStatement interface {
|
type SelectStatement interface {
|
||||||
jet.Statement
|
jet.Statement
|
||||||
jet.HasProjections
|
jet.HasProjections
|
||||||
jet.IExpression
|
jet.Expression
|
||||||
|
|
||||||
DISTINCT() SelectStatement
|
DISTINCT() SelectStatement
|
||||||
FROM(table ReadableTable) SelectStatement
|
FROM(table ReadableTable) SelectStatement
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ type SetStatement interface {
|
||||||
type SetOperators interface {
|
type SetOperators interface {
|
||||||
jet.Statement
|
jet.Statement
|
||||||
jet.HasProjections
|
jet.HasProjections
|
||||||
jet.IExpression
|
jet.Expression
|
||||||
|
|
||||||
UNION(rhs SelectStatement) SetStatement
|
UNION(rhs SelectStatement) SetStatement
|
||||||
UNION_ALL(rhs SelectStatement) SetStatement
|
UNION_ALL(rhs SelectStatement) SetStatement
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ type writableTable interface {
|
||||||
|
|
||||||
// ReadableTable interface
|
// ReadableTable interface
|
||||||
type ReadableTable interface {
|
type ReadableTable interface {
|
||||||
//table
|
|
||||||
readableTable
|
readableTable
|
||||||
jet.Serializer
|
jet.Serializer
|
||||||
//acceptsVisitor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WritableTable interface {
|
type WritableTable interface {
|
||||||
|
|
@ -44,15 +42,9 @@ type WritableTable interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Table interface {
|
type Table interface {
|
||||||
//table
|
|
||||||
readableTable
|
readableTable
|
||||||
writableTable
|
writableTable
|
||||||
jet.SerializerTable
|
jet.SerializerTable
|
||||||
//acceptsVisitor
|
|
||||||
|
|
||||||
//SchemaName() string
|
|
||||||
//TableName() string
|
|
||||||
//As(alias string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type readableTableInterfaceImpl struct {
|
type readableTableInterfaceImpl struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue