diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-04-16 21:18:04 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-04-16 21:18:04 +0200 |
| commit | d964c2be59a73e6b21ce1a8031fe913588bddf66 (patch) | |
| tree | d252f968b9b825591854352a073f1d4f1135269b /oblast.go | |
| parent | a646924f1f474aeb5acd3d753cfcb2379dca5210 (diff) | |
| download | go-oblast-d964c2be59a73e6b21ce1a8031fe913588bddf66.tar.gz | |
add Store.Update()
Diffstat (limited to 'oblast.go')
| -rw-r--r-- | oblast.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -100,6 +100,7 @@ import ( "database/sql/driver" "fmt" "reflect" + "strings" ) var ( @@ -170,3 +171,21 @@ func MustNewStore[R any](dialect Dialect, opts ...PlanOption) Store[R] { } return store } + +// MissingRecordError is returned by [Store.Update] if one of the rows to be updated does not exist in the DB. +type MissingRecordError[R any] struct { + // The record that was provided to [Store.Update], + // but for which no row with the same primary key values could be located. + Record R + plan plan +} + +// Error implements the builtin/error interface. +func (e MissingRecordError[R]) Error() string { + keyDescs := make([]string, len(e.plan.PrimaryKeyColumnNames)) + v := reflect.ValueOf(e.Record) + for idx, columnName := range e.plan.PrimaryKeyColumnNames { + keyDescs[idx] = fmt.Sprintf("%s = %#v", columnName, v.FieldByIndex(e.plan.IndexByColumnName[columnName])) + } + return fmt.Sprintf("could not UPDATE record that does not exist in the database: %s", strings.Join(keyDescs, ", ")) +} |
