row.go 581 B

1234567891011121314151617181920212223
  1. package callbacks
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. func RowQuery(db *gorm.DB) {
  6. if db.Error == nil {
  7. BuildQuerySQL(db)
  8. if db.DryRun || db.Error != nil {
  9. return
  10. }
  11. if isRows, ok := db.Get("rows"); ok && isRows.(bool) {
  12. db.Statement.Settings.Delete("rows")
  13. db.Statement.Dest, db.Error = db.Statement.ConnPool.QueryContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
  14. } else {
  15. db.Statement.Dest = db.Statement.ConnPool.QueryRowContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
  16. }
  17. db.RowsAffected = -1
  18. }
  19. }