Skip to content

Commit

Permalink
feat(driver): Replace value.Value with Value() return (#139)
Browse files Browse the repository at this point in the history
* feat(driver): Replace `value.Value` with `Value()` return

* feat(driver): early return if value is Valid type

---------

Co-authored-by: rahul2393 <irahul@google.com>
  • Loading branch information
simamumu and rahul2393 committed Jul 5, 2023
1 parent c6bda23 commit 6f2b96e
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,18 +715,10 @@ func (c *conn) IsValid() bool {
return !c.closed
}

func (c *conn) CheckNamedValue(value *driver.NamedValue) error {
if value == nil {
return nil
}
if valuer, ok := value.Value.(driver.Valuer); ok {
_, err := valuer.Value()
return err
}
switch t := value.Value.(type) {
func checkIsValidType(v driver.Value) bool {
switch v.(type) {
default:
// Default is to fail, unless it is one of the following supported types.
return spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "unsupported value type: %v", t))
return false
case nil:
case sql.NullInt64:
case sql.NullTime:
Expand Down Expand Up @@ -784,7 +776,27 @@ func (c *conn) CheckNamedValue(value *driver.NamedValue) error {
case []spanner.NullJSON:
case spanner.GenericColumnValue:
}
return nil
return true
}

func (c *conn) CheckNamedValue(value *driver.NamedValue) error {
if value == nil {
return nil
}
if checkIsValidType(value.Value) {
return nil
}
if valuer, ok := value.Value.(driver.Valuer); ok {
v, err := valuer.Value()
if err != nil {
return err
}
if checkIsValidType(v) {
value.Value = v
return nil
}
}
return spanner.ToSpannerError(status.Errorf(codes.InvalidArgument, "unsupported value type: %T", value.Value))
}

func (c *conn) Prepare(query string) (driver.Stmt, error) {
Expand Down

0 comments on commit 6f2b96e

Please sign in to comment.