Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

JSON column validation rejects []interface{} #36

Closed
obataku opened this issue Jun 11, 2021 · 1 comment
Closed

JSON column validation rejects []interface{} #36

obataku opened this issue Jun 11, 2021 · 1 comment

Comments

@obataku
Copy link

obataku commented Jun 11, 2021

TypeJSON columns currently only accept map, []byte, string, and *string values: https://github.com/cloudquery/cq-provider-sdk/blob/main/provider/schema/column.go#L139

	// Maps are jsons
	if reflect2.TypeOf(v).Kind() == reflect.Map {
		return c.Type == TypeJSON
	}

	switch val := v.(type) {
	...
	case []byte:
		...
		return c.Type == TypeByteArray || c.Type == TypeJSON
	...
	case string:
		...
		if c.Type == TypeJSON {
			return true
		}
		...
	case *string:
		if c.Type == TypeJSON {
			return true
		}

... whereas postgres json & jsonb columns support JSON arrays as well as primitives and pgx accepts virtually anything it can marshal: https://github.com/jackc/pgtype/blob/master/json.go#L52-L57

at the very least it would be useful to be store JSON-serializable slices in TypeJSON columns

@roneli
Copy link
Contributor

roneli commented Jul 19, 2021

Supported in #50

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants