Closed alingse closed 1 year ago
2023/03/16 04:34:18 /home/runner/work/datatypes/datatypes/json_type_test.go:142 ERROR: cached plan must not change result type (SQLSTATE 0A000)
[0.293ms] [rows:0] SELECT * FROM "user_with_jsons" WHERE "user_with_jsons"."id" = 2 AND "user_with_jsons"."deleted_at" IS NULL ORDER BY "user_with_jsons"."id" LIMIT 1
--- FAIL: TestJSONSlice (0.01s)
json_type_test.go:143: failed to find user with json key, got error ERROR: cached plan must not change result type (SQLSTATE 0A000)
cc @jinzhu
Thanks for adding this! Are there plans to include this in a new release?
Thanks for releasing https://github.com/go-gorm/datatypes/releases/tag/v1.2.0 !
What did this pull request do?
type JSONSlice[T any] []T
for generic type slice data.why not use
JSONType[[]T]
?because
JSONSlice
is good for reflection, butJSONType
is not.for example
when we use json to marshal the value we can got
but we use other decode/encode/reflect method to process data (like https://github.com/mitchellh/mapstructure)
it will got an extra
data
level, causeJSONType
with an extraData
Fieldgolang do not support the generic type alias like
type JSONType[T any] T
to auto bind theValue
/Scan
method.so, add a
JSONSlice
can solve this problem just for the slice value.User Case Description
see the json_type_test.go