WIP: Insert sets PK
This commit is contained in:
+10
-4
@@ -113,8 +113,9 @@ func (s Select[T]) Execute(conn *simpleorm.DBConnection) ([]T, error) {
|
||||
}
|
||||
|
||||
type Insert[T any] struct {
|
||||
target schema.Table
|
||||
toInsert []T
|
||||
target schema.Table
|
||||
toInsert []T
|
||||
lastInsertId int64
|
||||
}
|
||||
|
||||
func NewInsert[T any](orm *simpleorm.ORM, toInsert ...T) (Insert[T], error) {
|
||||
@@ -156,12 +157,16 @@ func (ins Insert[T]) Execute(conn *simpleorm.DBConnection) ([]T, error) {
|
||||
} else {
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
log.LogInfo("Inserted %s row", rowsAffected)
|
||||
lastInsertId, _ := result.LastInsertId()
|
||||
log.LogInfo("Last ID: %s", lastInsertId)
|
||||
ins.lastInsertId, _ = result.LastInsertId()
|
||||
log.LogInfo("Last ID: %s", ins.lastInsertId)
|
||||
}
|
||||
return []T{}, nil
|
||||
}
|
||||
|
||||
func (ins Insert[T]) LastInsertId() int64 {
|
||||
return ins.lastInsertId
|
||||
}
|
||||
|
||||
type Update[T any] struct {
|
||||
target schema.Table
|
||||
toUpdate T
|
||||
@@ -207,6 +212,7 @@ func (u Update[T]) Execute(conn *simpleorm.DBConnection) ([]T, error) {
|
||||
} else {
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
log.LogInfo("Updated %s row", rowsAffected)
|
||||
result.LastInsertId()
|
||||
}
|
||||
return []T{u.toUpdate}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user