Jsonb与Beego Orm和Postgres

时间:2018-11-22 10:20:27

标签: postgresql go jsonb beego

我正在使用beego和Postgres作为数据库。我在下面有一个模型定义:

type Dashboards struct {
    Id          string    `json:"id" orm:"pk" valid:"Required"`
    UserId      string    `json:user_id orm:rel(fk);null`
    Title       string    `json:title`
    Widgets     string    `json:widgets orm:"type(jsonb);null"`
    WidgetGrid  string    `json:widget_grid orm:"type(jsonb);null"`
}

func init() {
   base.RegisterModel(new(Dashboards))
}

在查看postgres时,我得到以下模式

   Column    | Type | Collation | Nullable | Default  
-------------+------+-----------+----------+----------
id          | text |           | not null | 
user_id     | text |           | not null | ''::text
title       | text |           | not null | ''::text
widgets     | text |           | not null | ''::text
widget_grid | text |           | not null | ''::text

ie我打算另存为jsonb的两个字段都被另存为文本。 请指导我如何在此处将字段另存为jsonb。谢谢。

0 个答案:

没有答案