2020-02-22 14:41:01 +03:00
|
|
|
package callbacks
|
|
|
|
|
|
|
|
import (
|
2020-06-02 04:16:07 +03:00
|
|
|
"gorm.io/gorm"
|
2020-02-22 14:41:01 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func RowQuery(db *gorm.DB) {
|
2020-05-31 18:55:56 +03:00
|
|
|
if db.Error == nil {
|
2020-11-04 06:03:22 +03:00
|
|
|
BuildQuerySQL(db)
|
2021-11-29 04:33:20 +03:00
|
|
|
if db.DryRun {
|
|
|
|
return
|
|
|
|
}
|
2020-02-22 14:41:01 +03:00
|
|
|
|
2021-11-29 04:33:20 +03:00
|
|
|
if isRows, ok := db.Get("rows"); ok && isRows.(bool) {
|
|
|
|
db.Statement.Settings.Delete("rows")
|
|
|
|
db.Statement.Dest, db.Error = db.Statement.ConnPool.QueryContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
|
|
|
} else {
|
|
|
|
db.Statement.Dest = db.Statement.ConnPool.QueryRowContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
2020-05-31 18:55:56 +03:00
|
|
|
}
|
2021-11-29 04:33:20 +03:00
|
|
|
|
|
|
|
db.RowsAffected = -1
|
2020-02-22 14:41:01 +03:00
|
|
|
}
|
|
|
|
}
|