Struct field with jsonb and postgres #411

Open
opened 2016-06-14 20:07:00 +00:00 by wrunk · 2 comments
wrunk commented 2016-06-14 20:07:00 +00:00 (Migrated from github.com)

Hello, I am having trouble using a struct as a field with jsonb. Take for example this struct:

type Card struct {
    Addr        Address `xorm:"jsonb notnull 'addr'" json:"addr"`
    ...
}

When I try to insert something into this table, it seems to be trying to treat it as a foreign table not jsonb. I get the error "no primary key for col addr"

Am I doing something wrong, or is there a way to do this? Here is a full example for what I am talking about: https://gist.github.com/wrunk/f5d4d5d648e41292f24be4c9b678edd8

Hello, I am having trouble using a struct as a field with jsonb. Take for example this struct: ``` golang type Card struct { Addr Address `xorm:"jsonb notnull 'addr'" json:"addr"` ... } ``` When I try to insert something into this table, it seems to be trying to treat it as a foreign table not jsonb. I get the error "no primary key for col addr" Am I doing something wrong, or is there a way to do this? Here is a full example for what I am talking about: https://gist.github.com/wrunk/f5d4d5d648e41292f24be4c9b678edd8

JSONB is not supported by xorm now.

JSONB is not supported by xorm now.
wrunk commented 2016-06-24 22:49:38 +00:00 (Migrated from github.com)

Maybe it is worth noting that using a jsonb field as a slice of interface or a slice of struct works fine:

type Card struct {
    // Works fine as a jsonb field in postgres 
    Addrs1        []Address `xorm:"jsonb notnull default '[]' 'addr'" json:"addr"`
    ...
    // Also works fine
    Addrs2        []interface `xorm:"jsonb notnull default '[]' 'addr'" json:"addr"`
    // Also works fine
    Addr        map[string]interface{} `xorm:"jsonb notnull default '{}' 'addr'" json:"addr"`
}
Maybe it is worth noting that using a jsonb field as a slice of interface or a slice of struct works fine: ``` golang type Card struct { // Works fine as a jsonb field in postgres Addrs1 []Address `xorm:"jsonb notnull default '[]' 'addr'" json:"addr"` ... // Also works fine Addrs2 []interface `xorm:"jsonb notnull default '[]' 'addr'" json:"addr"` // Also works fine Addr map[string]interface{} `xorm:"jsonb notnull default '{}' 'addr'" json:"addr"` } ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#411
No description provided.