2014-02-05 17:21:07 +03:00
|
|
|
package sqlmock
|
|
|
|
|
2014-02-07 09:58:27 +03:00
|
|
|
// a structure which implements database/sql/driver.Result
|
|
|
|
// holds last insert id and rows affected
|
|
|
|
// should be returned by Exec queries
|
2014-02-05 17:21:07 +03:00
|
|
|
type Result struct {
|
|
|
|
lastInsertId int64
|
|
|
|
rowsAffected int64
|
|
|
|
}
|
|
|
|
|
2014-02-07 09:58:27 +03:00
|
|
|
// creates a new result for Exec based query mocks
|
2014-02-05 17:21:07 +03:00
|
|
|
func NewResult(lastInsertId int64, rowsAffected int64) *Result {
|
|
|
|
return &Result{
|
|
|
|
lastInsertId,
|
|
|
|
rowsAffected,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 09:58:27 +03:00
|
|
|
// get last insert id
|
2014-02-05 17:21:07 +03:00
|
|
|
func (res *Result) LastInsertId() (int64, error) {
|
|
|
|
return res.lastInsertId, nil
|
|
|
|
}
|
|
|
|
|
2014-02-07 09:58:27 +03:00
|
|
|
// get rows affected
|
2014-02-05 17:21:07 +03:00
|
|
|
func (res *Result) RowsAffected() (int64, error) {
|
|
|
|
return res.rowsAffected, nil
|
|
|
|
}
|