How load JSON column as an unmarshalled struct? #1058
-
Hello everyone, First of all congratulations for the awesome library and many thanks for supporting it. We've been using SQLBoiler in our project for more than a year now and it has been a treat! I have a JSON column in my DB table and I want to generate the SQLBoiler model but instead of the usual For example, let's say we have the following table: CREATE TABLE configs (
id character varying NOT NULL,
display_config jsonb DEFAULT '{}'::jsonb NOT NULL
); And the following struct for the display configs: type DisplayConfig struct {
DisplayHeader bool `json:"display_header"`
Padding int `json:"padding"`
...
} I would like my generated type Config struct {
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
DisplayConfig DisplayConfig `boil:"display_config" json:"display_config" toml:"display_config" yaml:"display_config"`
} Is there any way to achieve this in SQLBoiler? Many thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can do this using in the [[types]]
[types.match]
tables = ['users'] # Leave empty to affect all columns with this name
name = "metadata" # Name of column to override the type
nullable = false # Is it nullable?
[types.replace]
type = "customTypes.UserMeta" # The name of the type to replace with
[types.imports]
third_party = ['customTypes "github.com/path/to/custom/types"'] # The package containing your custom type |
Beta Was this translation helpful? Give feedback.
You can do this using in the
configuration file
. For example: