Improve native type support for JSON rdbms columns
Allow driver.Value types to be used as is.
This avoids cases where valid values would be encoded into
strange, invalid JSON strings (such as passing `{"k": "v"}`).
This commit is contained in:
@@ -249,6 +249,10 @@ func (t *TypeJSON) Encode(val any) (driver.Value, error) {
|
||||
// does the value type know how to encode itself for the DB?
|
||||
return c.Value()
|
||||
|
||||
// These types are native to driver.Value
|
||||
case int64, float64, bool, []byte, string, time.Time:
|
||||
return c, nil
|
||||
|
||||
case json.Marshaler:
|
||||
// does the value type know how to encode itself as JSON?
|
||||
return c.MarshalJSON()
|
||||
|
||||
Reference in New Issue
Block a user