From 702196dafa653d0b466af02acb55d8120c4a882c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 27 Jul 2022 15:08:10 +0200 Subject: [PATCH] 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"}`). --- store/adapters/rdbms/drivers/types.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/store/adapters/rdbms/drivers/types.go b/store/adapters/rdbms/drivers/types.go index 9934e92ae..2f7be072c 100644 --- a/store/adapters/rdbms/drivers/types.go +++ b/store/adapters/rdbms/drivers/types.go @@ -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()