[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

相关推荐
你的人类朋友5 小时前
说说签名与验签
后端
databook5 小时前
Manim实现脉冲闪烁特效
后端·python·动效
canonical_entropy9 小时前
AI时代,我们还需要低代码吗?—— 一场关于模型、演化与软件未来的深度问答
后端·低代码·aigc
颜如玉10 小时前
HikariCP:Dead code elimination优化
后端·性能优化·源码
考虑考虑10 小时前
Jpa使用union all
java·spring boot·后端
RestCloud11 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
bobz96511 小时前
virtio vs vfio
后端
RestCloud11 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
Rexi12 小时前
“Controller→Service→DAO”三层架构
后端
bobz96512 小时前
计算虚拟化的设计
后端