Skip to content

Commit

Permalink
Fix hyperbunTableForType for pointer types (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-rai authored Jul 4, 2024
1 parent 657f1e1 commit af996f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hyperbun.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ func annotate(err error, op string, kvs ...interface{}) error {
func hyperbunTableForType[T any]() string {
var t T
typ := reflect.TypeOf(t)
if typ.Kind() == reflect.Pointer {
typ = typ.Elem()
}

for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
val, ok := f.Tag.Lookup("bun")
Expand Down
4 changes: 4 additions & 0 deletions hyperbun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestHyperbunTableForType(t *testing.T) {
assert.Equal(t, "test_struct", hyperbunTableForType[testStruct]())
}

func TestHyperbunTableForPtrType(t *testing.T) {
assert.Equal(t, "test_struct", hyperbunTableForType[*testStruct]())
}

func TestAnnotateEven(t *testing.T) {
assert.Equal(t,
"performing TestAnnotate hello='world' id='0': test_error",
Expand Down

0 comments on commit af996f7

Please sign in to comment.