Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add uint64 support #272

Merged
merged 1 commit into from
Jul 14, 2024
Merged
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
4 changes: 4 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ func checkIsValidType(v driver.Value) bool {
case []spanner.NullInt64:
case *int64:
case []*int64:
case uint64:
case []uint64:
case *uint64:
case []*uint64:
case bool:
case []bool:
case spanner.NullBool:
Expand Down
5 changes: 5 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ func TestTypeRoundtrip(t *testing.T) {
{in: []spanner.NullInt64{{Valid: true, Int64: 197}}},
{in: pointerTo(int64(197))},
{in: []*int64{pointerTo(int64(197))}, scan: pointerTo([]spanner.NullInt64{})},
// uint64, *uint64 variants
{in: uint64(197)},
{in: []uint64{}, scan: pointerTo([]spanner.NullInt64{})},
{in: pointerTo(uint64(197))},
{in: []*uint64{pointerTo(uint64(197))}, scan: pointerTo([]spanner.NullInt64{})},
// bool variants
{in: true},
{in: []bool{true}, scan: pointerTo([]spanner.NullBool{})},
Expand Down
40 changes: 40 additions & 0 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ func convertParam(v driver.Value) driver.Value {
res[i] = int64(val)
}
return res
case uint64:
return int64(v)
case []uint64:
if v == nil {
return []int64(nil)
}
res := make([]int64, len(v))
for i, val := range v {
res[i] = int64(val)
}
return res
case *uint64:
if v == nil {
return (*int64)(nil)
}
vi := int64(*v)
return &vi
case *int:
if v == nil {
return (*int64)(nil)
Expand Down Expand Up @@ -172,6 +189,29 @@ func convertParam(v driver.Value) driver.Value {
res[i] = int64(val)
}
return res
case []*uint64:
if v == nil {
return []*int64(nil)
}
res := make([]*int64, len(v))
for i, val := range v {
if val == nil {
res[i] = nil
} else {
z := int64(*val)
res[i] = &z
}
}
return res
case *[]uint64:
if v == nil {
return []int64(nil)
}
res := make([]int64, len(*v))
for i, val := range *v {
res[i] = int64(val)
}
return res
}
}

Expand Down
10 changes: 10 additions & 0 deletions stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ func TestConvertParam(t *testing.T) {
check(pointerTo([]int{197}), []int64{197})
check(([]*int)(nil), ([]*int64)(nil))
check((*[]int)(nil), ([]int64)(nil))

check(uint64(197), int64(197))
check(pointerTo(uint64(197)), pointerTo(int64(197)))
check((*uint64)(nil), (*int64)(nil))

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

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