@@ -11,9 +11,9 @@ import (
1111 "github.com/godror/godror"
1212)
1313
14- var DB godror.Execer // set in tests
14+ var DB godror.Execer
1515
16- // EmailList is a Go wrapper for Oracle VARRAY type EMAIL_LIST_ARR.
16+ // StringList is a Go wrapper for Oracle VARRAY type
1717type StringList []string
1818
1919// Scan implements sql.Scanner (Oracle -> Go)
@@ -63,7 +63,7 @@ func (s StringList) Value() (driver.Value, error) {
6363
6464 ctx := context .Background ()
6565
66- // Try to detect Oracle type name dynamically via reflection
66+ // detect Oracle type name dynamically via reflection
6767 typeName , err := detectOracleTypeName (s )
6868 if err != nil {
6969 return nil , err
@@ -91,27 +91,24 @@ func (s StringList) Value() (driver.Value, error) {
9191 return obj , nil
9292}
9393
94- // detectOracleTypeName uses reflection to look up the `gorm:"type:..."` tag.
9594func detectOracleTypeName (value interface {}) (string , error ) {
96- val := reflect .ValueOf (value )
97- if val .Kind () == reflect .Ptr {
98- val = val .Elem ()
95+ rt := reflect .TypeOf (value )
96+ if rt .Kind () != reflect .Struct {
97+ // Not a struct → cannot detect; return a hint instead of panic
98+ return "" , fmt .Errorf ("detectOracleTypeName: not a struct (got %s)" , rt .Kind ())
9999 }
100100
101- // walk up the call stack and look for the struct field tag
102- // (GORM provides the value as part of the struct — this works during model serialization)
103- rt := reflect .TypeOf (value )
104101 for i := 0 ; i < rt .NumField (); i ++ {
105102 field := rt .Field (i )
106- if tag := field .Tag .Get ("gorm" ); strings .Contains (tag , "type:" ) {
103+ tag := field .Tag .Get ("gorm" )
104+ if strings .Contains (tag , "type:" ) {
107105 re := regexp .MustCompile (`type:"?([a-zA-Z0-9_]+)"?` )
108106 match := re .FindStringSubmatch (tag )
109107 if len (match ) > 1 {
110- return strings . ToUpper ( match [1 ]) , nil
108+ return match [1 ], nil
111109 }
112110 }
113111 }
114112
115- // fallback
116- return "" , fmt .Errorf ("cannot detect Oracle type name for %T" , value )
113+ return "" , fmt .Errorf ("no type tag found for %T" , value )
117114}
0 commit comments