3
0

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:
Tomaž Jerman
2022-07-27 15:08:10 +02:00
parent cce11cf19d
commit 702196dafa
+4
View File
@@ -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()