mirror of https://github.com/go-gorm/gorm.git
Initalize dialects
This commit is contained in:
parent
84646b8db9
commit
ac4b2e2a42
|
@ -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{}
|
|
@ -0,0 +1 @@
|
||||||
|
package dialect
|
|
@ -0,0 +1 @@
|
||||||
|
package dialect
|
|
@ -0,0 +1 @@
|
||||||
|
package dialect
|
5
main.go
5
main.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue