Skip to content

Commit

Permalink
Use a constructor to initialize SQLCompiler
Browse files Browse the repository at this point in the history
When dialects are in separate packages, they better not use unkeyed initialization
of SQLCompiler.
  • Loading branch information
cdevienne committed Dec 20, 2016
1 parent 9a31a5e commit 7fbe2ae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions compiler.go
Expand Up @@ -55,6 +55,11 @@ type Compiler interface {
VisitWhere(*CompilerContext, WhereClause) string
}

// NewSQLCompiler returns a new SQLCompiler
func NewSQLCompiler(dialect Dialect) SQLCompiler {
return SQLCompiler{Dialect: dialect}
}

// SQLCompiler aims to provide a SQL ANSI-92 implementation of Compiler
type SQLCompiler struct {
Dialect Dialect
Expand Down
2 changes: 1 addition & 1 deletion dialect_mysql.go
Expand Up @@ -70,7 +70,7 @@ func (d *MysqlDialect) Driver() string {

// GetCompiler returns a MysqlCompiler
func (d *MysqlDialect) GetCompiler() Compiler {
return MysqlCompiler{SQLCompiler{d}}
return MysqlCompiler{NewSQLCompiler(d)}
}

// MysqlCompiler is a SQLCompiler specialised for Mysql
Expand Down
2 changes: 1 addition & 1 deletion dialect_postgres.go
Expand Up @@ -77,7 +77,7 @@ func (d *PostgresDialect) Driver() string {

// GetCompiler returns a PostgresCompiler
func (d *PostgresDialect) GetCompiler() Compiler {
return PostgresCompiler{SQLCompiler{d}}
return PostgresCompiler{NewSQLCompiler(d)}
}

// PostgresCompiler is a SQLCompiler specialised for PostgreSQL
Expand Down
2 changes: 1 addition & 1 deletion dialect_sqlite.go
Expand Up @@ -69,7 +69,7 @@ func (d *SqliteDialect) Driver() string {

// GetCompiler returns a SqliteCompiler
func (d *SqliteDialect) GetCompiler() Compiler {
return SqliteCompiler{SQLCompiler{d}}
return SqliteCompiler{NewSQLCompiler(d)}
}

// SqliteCompiler is a SQLCompiler specialised for Sqlite
Expand Down

0 comments on commit 7fbe2ae

Please sign in to comment.