Skip to content

Commit

Permalink
Add DryRunModeUnsupported Error for Row/Rows
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Sep 18, 2020
1 parent d002c70 commit 072f1de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions errors.go
Expand Up @@ -29,4 +29,6 @@ var (
ErrInvalidField = errors.New("invalid field")
// ErrEmptySlice empty slice found
ErrEmptySlice = errors.New("empty slice found")
// ErrDryRunModeUnsupported dry run mode unsupported
ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
)
12 changes: 10 additions & 2 deletions finisher_api.go
Expand Up @@ -334,13 +334,21 @@ func (db *DB) Count(count *int64) (tx *DB) {
func (db *DB) Row() *sql.Row {
tx := db.getInstance().InstanceSet("rows", false)
tx.callbacks.Row().Execute(tx)
return tx.Statement.Dest.(*sql.Row)
row, ok := tx.Statement.Dest.(*sql.Row)
if !ok && tx.DryRun {
db.Logger.Error(tx.Statement.Context, ErrDryRunModeUnsupported.Error())
}
return row
}

func (db *DB) Rows() (*sql.Rows, error) {
tx := db.getInstance().InstanceSet("rows", true)
tx.callbacks.Row().Execute(tx)
return tx.Statement.Dest.(*sql.Rows), tx.Error
rows, ok := tx.Statement.Dest.(*sql.Rows)
if !ok && tx.DryRun && tx.Error == nil {
tx.Error = ErrDryRunModeUnsupported
}
return rows, tx.Error
}

// Scan scan value to a struct
Expand Down

0 comments on commit 072f1de

Please sign in to comment.