Skip to content

Commit

Permalink
remove package dialect for easier contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Apr 24, 2014
1 parent fd3ce3b commit a46d149
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dialect/dialect.go → dialect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dialect
package gorm

import (
"reflect"
Expand All @@ -16,7 +16,7 @@ type Dialect interface {
Quote(key string) string
}

func New(driver string) Dialect {
func NewDialect(driver string) Dialect {
var d Dialect
switch driver {
case "postgres":
Expand Down
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package gorm

import (
"database/sql"

"github.com/jinzhu/gorm/dialect"
)

type DB struct {
Expand All @@ -15,14 +13,14 @@ type DB struct {
search *search
logMode int
logger logger
dialect dialect.Dialect
dialect Dialect
tagIdentifier string
singularTable bool
}

func Open(driver, source string) (DB, error) {
var err error
db := DB{dialect: dialect.New(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback}
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback}
db.db, err = sql.Open(driver, source)
db.parent = &db
return db, err
Expand Down
17 changes: 13 additions & 4 deletions dialect/mysql.go → mysql.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dialect
package gorm

import (
"fmt"

"reflect"
)

Expand Down Expand Up @@ -59,10 +60,18 @@ func (s *mysql) PrimaryKeyTag(value reflect.Value, size int) string {
}
}

func (s *mysql) ReturningStr(key string) (str string) {
return
func (s *mysql) ReturningStr(key string) string {
return ""
}

func (s *mysql) Quote(key string) (str string) {
func (s *mysql) Quote(key string) string {
return fmt.Sprintf("`%s`", key)
}

func (s *mysql) HasTable(tableName string) bool {
return true
}

func (s *mysql) HasColumn(tableName string, columnName string) bool {
return true
}
6 changes: 3 additions & 3 deletions dialect/postgres.go → postgres.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dialect
package gorm

import (
"fmt"
Expand Down Expand Up @@ -54,10 +54,10 @@ func (s *postgres) PrimaryKeyTag(value reflect.Value, size int) string {
}
}

func (s *postgres) ReturningStr(key string) (str string) {
func (s *postgres) ReturningStr(key string) string {
return fmt.Sprintf("RETURNING \"%v\"", key)
}

func (s *postgres) Quote(key string) (str string) {
func (s *postgres) Quote(key string) string {
return fmt.Sprintf("\"%s\"", key)
}
3 changes: 1 addition & 2 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gorm
import (
"errors"
"fmt"
"github.com/jinzhu/gorm/dialect"
"go/ast"
"strings"
"time"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (scope *Scope) Quote(str string) string {
}

// Dialect get dialect
func (scope *Scope) Dialect() dialect.Dialect {
func (scope *Scope) Dialect() Dialect {
return scope.db.parent.dialect
}

Expand Down
2 changes: 1 addition & 1 deletion dialect/sqlite3.go → sqlite3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dialect
package gorm

import (
"fmt"
Expand Down

0 comments on commit a46d149

Please sign in to comment.