mirror of https://github.com/go-gorm/gorm.git
remove package dialect for easier contribution
This commit is contained in:
parent
fd3ce3b39a
commit
a46d149579
|
@ -1,4 +1,4 @@
|
||||||
package dialect
|
package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -16,7 +16,7 @@ type Dialect interface {
|
||||||
Quote(key string) string
|
Quote(key string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(driver string) Dialect {
|
func NewDialect(driver string) Dialect {
|
||||||
var d Dialect
|
var d Dialect
|
||||||
switch driver {
|
switch driver {
|
||||||
case "postgres":
|
case "postgres":
|
6
main.go
6
main.go
|
@ -2,8 +2,6 @@ package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm/dialect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
|
@ -15,14 +13,14 @@ type DB struct {
|
||||||
search *search
|
search *search
|
||||||
logMode int
|
logMode int
|
||||||
logger logger
|
logger logger
|
||||||
dialect dialect.Dialect
|
dialect Dialect
|
||||||
tagIdentifier string
|
tagIdentifier string
|
||||||
singularTable bool
|
singularTable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(driver, source string) (DB, error) {
|
func Open(driver, source string) (DB, error) {
|
||||||
var err 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.db, err = sql.Open(driver, source)
|
||||||
db.parent = &db
|
db.parent = &db
|
||||||
return db, err
|
return db, err
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package dialect
|
package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,10 +60,18 @@ func (s *mysql) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mysql) ReturningStr(key string) (str string) {
|
func (s *mysql) ReturningStr(key string) string {
|
||||||
return
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mysql) Quote(key string) (str string) {
|
func (s *mysql) Quote(key string) string {
|
||||||
return fmt.Sprintf("`%s`", key)
|
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
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package dialect
|
package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -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)
|
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)
|
return fmt.Sprintf("\"%s\"", key)
|
||||||
}
|
}
|
3
scope.go
3
scope.go
|
@ -3,7 +3,6 @@ package gorm
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/gorm/dialect"
|
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -55,7 +54,7 @@ func (scope *Scope) Quote(str string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dialect get dialect
|
// Dialect get dialect
|
||||||
func (scope *Scope) Dialect() dialect.Dialect {
|
func (scope *Scope) Dialect() Dialect {
|
||||||
return scope.db.parent.dialect
|
return scope.db.parent.dialect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package dialect
|
package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue