diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-09-17 16:21:40 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-09-17 16:21:40 +0200 |
| commit | 63df99f2e1c742069464d219a9f340c1f8f5bd90 (patch) | |
| tree | b64e6742c78e0d7e4bac1d6f3ed8a2c03f2f9c9b /oblast/errors.go | |
| parent | fe37a82d0495a8b59b80677dd42d0d94ffafdfb4 (diff) | |
| download | go-gg-63df99f2e1c742069464d219a9f340c1f8f5bd90.tar.gz | |
oblast: import from go.xyrillian.de/oblast
- type RuntimeIndex is left behind for now because I don't want to
commit to the method names yet
- the "OrNone" methods are removed in favor of gsql.NoneIfNoRows()
Diffstat (limited to 'oblast/errors.go')
| -rw-r--r-- | oblast/errors.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/oblast/errors.go b/oblast/errors.go new file mode 100644 index 0000000..0a58340 --- /dev/null +++ b/oblast/errors.go @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net> +// SPDX-License-Identifier: Apache-2.0 + +package oblast + +import ( + "fmt" + "reflect" + "strings" +) + +// 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 "could not UPDATE record that does not exist in the database: " + strings.Join(keyDescs, ", ") +} |
