Initalize dialects

This commit is contained in:
Jinzhu 2013-11-14 17:35:17 +08:00
parent 84646b8db9
commit ac4b2e2a42
5 changed files with 29 additions and 2 deletions

23
dialect/dialect.go Normal file
View File

@ -0,0 +1,23 @@
package dialect
type Dialect interface {
}
func NewDialect(driver string) *Dialect {
var d Dialect
switch driver {
case "postgres":
d = postgres{}
case "mysql":
d = mysql{}
case "sqlite3":
d = sqlite3{}
}
return &d
}
type mysql struct{}
type postgres struct{}
type sqlite3 struct{}

1
dialect/mysql.go Normal file
View File

@ -0,0 +1 @@
package dialect

1
dialect/postgres.go Normal file
View File

@ -0,0 +1 @@
package dialect

1
dialect/sqlite3.go Normal file
View File

@ -0,0 +1 @@
package dialect

View File

@ -1,6 +1,7 @@
package gorm package gorm
import "database/sql" import "database/sql"
import "github.com/jinzhu/gorm/dialect"
var singularTableName bool var singularTableName bool
var tagIdentifier string var tagIdentifier string
@ -11,14 +12,14 @@ func init() {
type DB struct { type DB struct {
db sql_common db sql_common
driver string dialect *dialect.Dialect
logger Logger logger Logger
log_mode bool log_mode bool
} }
func Open(driver, source string) (db DB, err error) { func Open(driver, source string) (db DB, err error) {
db.db, err = sql.Open(driver, source) db.db, err = sql.Open(driver, source)
db.driver = driver db.dialect = dialect.NewDialect(driver)
return return
} }