diff --git a/main.go b/main.go index 52a536d0..4210a76b 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ type DB struct { Value interface{} Error error RowsAffected int64 + LastInsertId int64 callbacks *Callback db sqlCommon parent *DB diff --git a/scope.go b/scope.go index c00cd0a1..f0e736b4 100644 --- a/scope.go +++ b/scope.go @@ -348,6 +348,9 @@ func (scope *Scope) Exec() *Scope { if count, err := result.RowsAffected(); scope.Err(err) == nil { scope.db.RowsAffected = count } + if lastInsertId, err := result.LastInsertId(); scope.Err(err) == nil { + scope.db.LastInsertId = lastInsertId + } } } return scope