Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func isUnsafe(i interface{}) bool {
return v.unsafe
case *DB:
return v.unsafe
case Conn:
return v.unsafe
case *Conn:
return v.unsafe
case Tx:
return v.unsafe
case *Tx:
Expand All @@ -149,6 +153,10 @@ func mapperFor(i interface{}) *reflectx.Mapper {
return i.Mapper
case *DB:
return i.Mapper
case Conn:
return i.Mapper
case *Conn:
return i.Mapper
case Tx:
return i.Mapper
case *Tx:
Expand Down
37 changes: 37 additions & 0 deletions sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,3 +1923,40 @@ func TestSelectReset(t *testing.T) {
}
})
}

func TestMapperForConn(t *testing.T) {
db := &DB{Mapper: mapper()}
conn := &Conn{Mapper: mapper()}

// mapperFor should return the Mapper for Conn and *Conn types
if m := mapperFor(conn); m == nil {
t.Error("mapperFor(*Conn) returned nil Mapper")
}
if m := mapperFor(&Conn{Mapper: mapper()}); m == nil {
t.Error("mapperFor(*Conn) returned nil Mapper for pointer")
}

// mapperFor should also work for DB types (existing behavior)
if m := mapperFor(db); m == nil {
t.Error("mapperFor(*DB) returned nil Mapper")
}

// Verify Mapper is the same instance
customMapper := reflectx.NewMapperFunc("db", strings.ToLower)
conn2 := &Conn{Mapper: customMapper}
if m := mapperFor(conn2); m != customMapper {
t.Error("mapperFor(*Conn) did not return the custom Mapper")
}
}

func TestIsUnsafeConn(t *testing.T) {
conn := &Conn{unsafe: true}
conn2 := &Conn{unsafe: false}

if !isUnsafe(conn) {
t.Error("isUnsafe(*Conn) should return true for unsafe=true")
}
if isUnsafe(conn2) {
t.Error("isUnsafe(*Conn) should return false for unsafe=false")
}
}