[golang] ent使用

package schema

import (
	"encoding/json"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/field"
)

// Configuration holds the schema definition for the Configuration entity.
type Configuration struct {
	ent.Schema
}

// Annotations of the Configuration.
func (Configuration) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "configurations"},//数据库 明
	}
}

// Fields of the Configuration.
func (Configuration) Fields() []ent.Field {
	return []ent.Field{
		field.Int("id").Unique().Immutable().Positive(),
		field.String("config_key"),
		field.JSON("config_value", json.RawMessage{}),
		field.String("remark"),
		field.Int("version").Default(0),
		field.Time("created_at").Default(time.Now),
	}
}

// Edges of the Configuration.
func (Configuration) Edges() []ent.Edge {
	return []ent.Edge{}
}

go generate ./ent

调用生成 代码

详细可参考 项目创建 | ent

相关推荐
Vitalia几秒前
从零开始学 Rust:基本概念——变量、数据类型、函数、控制流
开发语言·后端·rust
猎人everest3 小时前
SpringBoot应用开发入门
java·spring boot·后端
山猪打不过家猪5 小时前
ASP.NET Core Clean Architecture
java·数据库·asp.net
qwy7152292581635 小时前
13-R数据重塑
服务器·数据库·r语言
Bio Coder5 小时前
R语言安装生物信息数据库包
开发语言·数据库·r语言
钊兵6 小时前
数据库驱动免费下载(Oracle、Mysql、达梦、Postgresql)
数据库·mysql·postgresql·oracle·达梦·驱动
weixin_425878237 小时前
Redis复制性能优化利器:深入解析replica-lazy-flush参数
数据库·redis·性能优化
左灯右行的爱情8 小时前
Redis数据结构总结-listPack
数据结构·数据库·redis
zhoupenghui1688 小时前
golang时间相关函数总结
服务器·前端·golang·time