diff --git a/main.go b/main.go index 7ba904be..368e4e81 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 45f7185f..0930d5fe 100644 --- a/scope.go +++ b/scope.go @@ -353,6 +353,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