to-go-struct-intellij-plugin icon indicating copy to clipboard operation
to-go-struct-intellij-plugin copied to clipboard

功能建议:可空类型字段使用sql.NullXXX类型

Open daviyang35 opened this issue 4 years ago • 0 comments

首先感谢作者,插件很方便。

希望能够在后续开发过程中,实现一个可选的增强功能。 对于 可为 null 类型的字段,可以映射为 sql.NullXXX 类型。

假设输入为

create table demo
(
	id bigint not null comment '主键'
		primary key,
	name varchar(255) null comment '姓名',
	sex varchar(255) null comment '性别',
	created datetime null comment '创建时间',
	creator bigint null comment '创建人ID',
	updated datetime not null comment '更新时间'
);

期望的输出

type Demo struct {
	ID      int64          `json:"id" gorm:"column:id"`           // 主键
	Name    sql.NullString `json:"name" gorm:"column:name"`       // 姓名
	Sex     sql.NullString `json:"sex" gorm:"column:sex"`         // 性别
	Created sql.NullTime   `json:"created" gorm:"column:created"` // 创建时间
	Creator sql.NullInt64  `json:"creator" gorm:"column:creator"` // 创建人ID
	Updated time.Time      `json:"updated" gorm:"column:updated"` // 更新时间
}

func (m *Demo) TableName() string {
	return "demo"
}

daviyang35 avatar Sep 16 '20 07:09 daviyang35