Skip to content

Commit

Permalink
feat: add *int support
Browse files Browse the repository at this point in the history
Fixes #257
  • Loading branch information
egonelbre committed Jun 17, 2024
1 parent 1a72e9f commit 04f7628
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ func checkIsValidType(v driver.Value) bool {
case *[]uint:
case int:
case []int:
case *int:
case *[]int:
case int64:
case []int64:
case spanner.NullInt64:
Expand Down
23 changes: 23 additions & 0 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ func convertParam(v driver.Value) driver.Value {
switch v := v.(type) {
default:
return v
case int:
return int64(v)
case []int:
res := make([]int64, len(v))
for i, val := range v {
res[i] = int64(val)
}
return res
case uint:
return int64(v)
case []uint:
Expand All @@ -103,6 +111,21 @@ func convertParam(v driver.Value) driver.Value {
res[i] = int64(val)
}
return res
case *int:
if v == nil {
return (*int64)(nil)
}
vi := int64(*v)
return &vi
case *[]int:
if v == nil {
return (*[]int64)(nil)
}
res := make([]int64, len(*v))
for i, val := range *v {
res[i] = int64(val)
}
return &res
case *uint:
if v == nil {
return (*int64)(nil)
Expand Down
9 changes: 7 additions & 2 deletions stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ func TestConvertParam(t *testing.T) {
}

check(uint(197), int64(197))
check([]uint{197}, []int64{197})
check(pointerTo[uint](197), pointerTo[int64](197))
check(pointerTo[[]uint]([]uint{197}), pointerTo[[]int64]([]int64{197}))
check((*uint)(nil), (*int64)(nil))

check([]uint{197}, []int64{197})
check(pointerTo[[]uint]([]uint{197}), pointerTo[[]int64]([]int64{197}))
check((*[]uint)(nil), (*[]int64)(nil))

check([]int{197}, []int64{197})
check(pointerTo[[]int]([]int{197}), pointerTo[[]int64]([]int64{197}))
check((*[]int)(nil), (*[]int64)(nil))
}

func pointerTo[T any](v T) *T { return &v }

0 comments on commit 04f7628

Please sign in to comment.