mirror of https://github.com/go-gorm/gorm.git
commit
288c8e37af
3
main.go
3
main.go
|
@ -16,11 +16,12 @@ type DB struct {
|
||||||
dialect Dialect
|
dialect Dialect
|
||||||
tagIdentifier string
|
tagIdentifier string
|
||||||
singularTable bool
|
singularTable bool
|
||||||
|
source string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(driver, source string) (DB, error) {
|
func Open(driver, source string) (DB, error) {
|
||||||
var err error
|
var err error
|
||||||
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback}
|
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback, source: source}
|
||||||
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
|
||||||
|
|
|
@ -448,7 +448,8 @@ func (scope *Scope) removeIndex(indexName string) {
|
||||||
|
|
||||||
func (scope *Scope) autoMigrate() *Scope {
|
func (scope *Scope) autoMigrate() *Scope {
|
||||||
var tableName string
|
var tableName string
|
||||||
scope.Raw(fmt.Sprintf("SELECT table_name FROM INFORMATION_SCHEMA.tables where table_name = %v", scope.AddToVars(scope.TableName())))
|
scope.Raw(fmt.Sprintf("SELECT table_name FROM INFORMATION_SCHEMA.tables where table_name = %v",
|
||||||
|
scope.AddToVars(scope.TableName())))
|
||||||
scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&tableName)
|
scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&tableName)
|
||||||
scope.SqlVars = []interface{}{}
|
scope.SqlVars = []interface{}{}
|
||||||
|
|
||||||
|
@ -458,7 +459,7 @@ func (scope *Scope) autoMigrate() *Scope {
|
||||||
} else {
|
} else {
|
||||||
for _, field := range scope.Fields() {
|
for _, field := range scope.Fields() {
|
||||||
var column, data string
|
var column, data string
|
||||||
scope.Raw(fmt.Sprintf("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = %v and column_name = %v",
|
scope.Raw(fmt.Sprintf("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = %v AND column_name = %v",
|
||||||
scope.AddToVars(scope.TableName()),
|
scope.AddToVars(scope.TableName()),
|
||||||
scope.AddToVars(field.DBName),
|
scope.AddToVars(field.DBName),
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue