forked from mirror/gorm
Specify database dialect when open database, fixes #169
This commit is contained in:
parent
943a873051
commit
4d98c8c0bc
23
main.go
23
main.go
|
@ -23,11 +23,26 @@ type DB struct {
|
||||||
source string
|
source string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(driver, source string) (DB, error) {
|
func Open(dialect string, drivesources ...string) (DB, error) {
|
||||||
|
var db DB
|
||||||
var err error
|
var err error
|
||||||
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback, source: source}
|
var driver = dialect
|
||||||
db.db, err = sql.Open(driver, source)
|
var source string
|
||||||
db.parent = &db
|
|
||||||
|
if len(drivesources) == 0 {
|
||||||
|
err = errors.New("invalid database source")
|
||||||
|
} else {
|
||||||
|
if len(drivesources) == 1 {
|
||||||
|
source = drivesources[0]
|
||||||
|
} else if len(drivesources) >= 2 {
|
||||||
|
driver = drivesources[0]
|
||||||
|
source = drivesources[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
db = DB{dialect: NewDialect(dialect), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback, source: source}
|
||||||
|
db.db, err = sql.Open(driver, source)
|
||||||
|
db.parent = &db
|
||||||
|
}
|
||||||
return db, err
|
return db, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue