Skip to content

Commit

Permalink
add case for time.Time and decimal in bindvars (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor committed Mar 29, 2024
1 parent 6bca3c1 commit ba711b1
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 136 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/dolthub/vitess
go 1.22

require (
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.4.0
golang.org/x/tools v0.1.9
google.golang.org/grpc v1.24.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
13 changes: 13 additions & 0 deletions go/sqltypes/bind_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"errors"
"fmt"
"strconv"
"time"

"github.com/shopspring/decimal"
"google.golang.org/protobuf/proto"

querypb "github.com/dolthub/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -120,6 +122,17 @@ func BuildBindVariable(v interface{}) (*querypb.BindVariable, error) {
return Uint64BindVariable(v), nil
case float64:
return Float64BindVariable(v), nil
case decimal.Decimal:
return &querypb.BindVariable{
Type: querypb.Type_DECIMAL,
Value: []byte(v.String()),
}, nil
case time.Time:
return &querypb.BindVariable{
Type: querypb.Type_TIMESTAMP,
Value: []byte(v.String()),
}, nil
// TODO: somehow support types.Timespan
case nil:
return NullBindVariable, nil
case Value:
Expand Down

0 comments on commit ba711b1

Please sign in to comment.