Skip to content

Commit 1e75963

Browse files
Fix: hasura table names for bun
1 parent 14f31d2 commit 1e75963

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

hasura/hasura.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,10 @@ func formatSelectPermissions(limit uint64, allowAggs bool, role string, columns
292292

293293
func getTableName(value reflect.Value, typ reflect.Type) string {
294294
if _, ok := typ.MethodByName("TableName"); !ok {
295-
if field, exists := typ.FieldByName("tableName"); exists {
296-
if tag := field.Tag.Get("pg"); tag != "" {
297-
if values := strings.Split(tag, ","); len(values) > 0 {
298-
return values[0]
299-
}
300-
}
295+
if field, exists := typ.FieldByName("BaseModel"); exists {
301296
if tag := field.Tag.Get("bun"); tag != "" {
302297
if values := strings.Split(tag, ","); len(values) > 0 {
303-
return values[0]
298+
return strings.TrimPrefix(values[0], "table:")
304299
}
305300
}
306301
}

hasura/hasura_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/dipdup-net/go-lib/config"
88
"github.com/stretchr/testify/assert"
9+
"github.com/uptrace/bun"
910
)
1011

1112
type testTable struct {
@@ -45,6 +46,10 @@ func (testTable4) TableName() int64 {
4546
return 0
4647
}
4748

49+
type testTable5 struct {
50+
bun.BaseModel `bun:"table:test_name"`
51+
}
52+
4853
func Test_getTableName(t *testing.T) {
4954
tests := []struct {
5055
name string
@@ -67,6 +72,10 @@ func Test_getTableName(t *testing.T) {
6772
name: "Test 4",
6873
model: &testTable4{},
6974
want: "test_table4",
75+
}, {
76+
name: "Test 5",
77+
model: &testTable5{},
78+
want: "test_name",
7079
},
7180
}
7281
for _, tt := range tests {

0 commit comments

Comments
 (0)