Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit dc156be

Browse files
committed
also support sql scan with array, not just slice
1 parent 85f8901 commit dc156be

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

sql.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func (r *ID) Scan(src interface{}) error {
5757
return r.UnmarshalBinary(src)
5858
}
5959
return r.UnmarshalText(src)
60+
case [16]byte:
61+
return r.UnmarshalBinary(src[:])
6062
case string:
6163
switch len(src) {
6264
case 26, 32, 22:

sql_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ var (
4040
func TestSQL(t *testing.T) {
4141
t.Run("Value", testSQLValue)
4242
t.Run("Scan", func(t *testing.T) {
43-
t.Run("Binary", testSQLScanBinary)
43+
t.Run("BinarySlice", testSQLScanBinarySlice)
44+
t.Run("BinaryArray", testSQLScanBinaryArray)
4445
t.Run("String", testSQLScanString)
4546
t.Run("Text", testSQLScanText)
4647
t.Run("Unsupported", testSQLScanUnsupported)
@@ -65,7 +66,7 @@ func testSQLValue(t *testing.T) {
6566
)
6667
}
6768

68-
func testSQLScanBinary(t *testing.T) {
69+
func testSQLScanBinarySlice(t *testing.T) {
6970
got := ID{}
7071
err := got.Scan(codecTestData)
7172
if err != nil {
@@ -76,6 +77,17 @@ func testSQLScanBinary(t *testing.T) {
7677
}
7778
}
7879

80+
func testSQLScanBinaryArray(t *testing.T) {
81+
got := ID{}
82+
err := got.Scan([16]byte(codecTestData))
83+
if err != nil {
84+
t.Fatal(err)
85+
}
86+
if !got.Equal(codecTestID) {
87+
t.Errorf("Scan(%x): got %v, want %v", codecTestData, got, codecTestID)
88+
}
89+
}
90+
7991
func testSQLScanString(t *testing.T) {
8092
s := "0r32b0yermw00sbjedjxe4yaz0"
8193
got := ID{}

0 commit comments

Comments
 (0)