pg表字段自动生成go结构体(配合goland)

select json_agg(a.*) from users a where id = 1;

此时将json复制出来,需要是object形式的。

{"id":1090,"mobile_number":"10516","country_code":"86","status":9,"password":"","created_time":"2010-08-06T18:48:18.343005+08:00","updated_time":"2020-10-30T17:58:46.151487+08:00","wechat":null}

然后将json复制到goland中即可自动生成,生成后逐项检查下,因为有的null值会被转换为interface{}

type T2 struct {
	Id           int         `json:"id"`
	MobileNumber string      `json:"mobile_number"`
	CountryCode  string      `json:"country_code"`
	Status       int         `json:"status"`
	Password     string      `json:"password"`
	CreatedTime  time.Time   `json:"created_time"`
	UpdatedTime  time.Time   `json:"updated_time"`
	Wechat       interface{} `json:"wechat"`
}

最后改下名字即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值