Select all fields in SQL queries avoiding the SELECT * FROM
This commit is contained in:
parent
85e9f66d26
commit
4bbbb6f242
@ -72,18 +72,9 @@ func BuildQuerySQL(db *gorm.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if db.Statement.Schema != nil && db.Statement.ReflectValue.IsValid() {
|
} else if db.Statement.Schema != nil && db.Statement.ReflectValue.IsValid() {
|
||||||
smallerStruct := false
|
|
||||||
switch db.Statement.ReflectValue.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
smallerStruct = db.Statement.ReflectValue.Type() != db.Statement.Schema.ModelType
|
|
||||||
case reflect.Slice:
|
|
||||||
smallerStruct = db.Statement.ReflectValue.Type().Elem() != db.Statement.Schema.ModelType
|
|
||||||
}
|
|
||||||
|
|
||||||
if smallerStruct {
|
|
||||||
stmt := gorm.Statement{DB: db}
|
stmt := gorm.Statement{DB: db}
|
||||||
// smaller struct
|
// smaller struct
|
||||||
if err := stmt.Parse(db.Statement.Dest); err == nil && stmt.Schema.ModelType != db.Statement.Schema.ModelType {
|
if err := stmt.Parse(db.Statement.Dest); err == nil {
|
||||||
clauseSelect.Columns = make([]clause.Column, len(stmt.Schema.DBNames))
|
clauseSelect.Columns = make([]clause.Column, len(stmt.Schema.DBNames))
|
||||||
|
|
||||||
for idx, dbName := range stmt.Schema.DBNames {
|
for idx, dbName := range stmt.Schema.DBNames {
|
||||||
@ -91,7 +82,6 @@ func BuildQuerySQL(db *gorm.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// inline joins
|
// inline joins
|
||||||
if len(db.Statement.Joins) != 0 {
|
if len(db.Statement.Joins) != 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user