Go-sql-driver JSON field type

Hi,

recently I notice that was added a new field type JSON to structs.

https://github.com/go-sql-driver/mysql/blob/master/const.go#L110

If not mistaken this was added to because of recent versions of MySQL having the support for JSON field types.
This is actually good, because I’m currently using JSON field types in MySQL 5.7.14.

My question is… how do we define it in the struct?

type Note struct {
	ID         int        `json:"id" db:"id"`
	Content    string    `json:"content,omitempty" db:"content"`
	Params     json      `json:"params,omitempty" db:"params"`
}

Is this correct?, for me it gives me an error.

Also this json field is not yet updated in the documentation: https://golang.org/pkg/database/sql/#Rows.Scan

Any ideas? thanks

Looks like the has been given just recently in issue #414 (emphasis added by me):

Also, how do we define it?

It’s job of ORM or other higher level libraries. The mysql driver just returns string.

yes I know it was me. Also I created an issue on the sqlx github https://github.com/jmoiron/sqlx/issues/244 but I’m not to keen that is going to get and answer… but let’s see.

thanks

Just out of curiosity: Does the suggestion from issue #414 work?

I mean, does your code work if you replace json by string:

type Note struct {
	ID         int       `json:"id" db:"id"`
	Content    string    `json:"content,omitempty" db:"content"`
	Params     string    `json:"params,omitempty" db:"params"`
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.