Skip to content

How do I deal with JSONB types while code generation? #215

Discussion options

You must be logged in to vote

Hi @vamshiaruru-virgodesigns ,

I could spot a couple of mistakes:

  1. You're missing SchemaName in DBConnection. That's probably why no tables are found.
  2. You're using the wrong code example. You're code tries to customize sql builder types, not model types. Example of model type customization - https://github.com/go-jet/jet/wiki/Generator#generator-customization.
  3. map[string]interface{} does not implement Scanner and Valuer interface, so scan would not work for this type. You need to define a new type:
// for any JSON types
type JsonType map[string]interface{}

func (m *JsonType) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), m)
}

func (m JsonType) Value() (driver.Value

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vamshiaruru-virgodesigns
Comment options

Answer selected by vamshiaruru-virgodesigns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants