[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

相关推荐
lixora42 分钟前
Oracle 11g Active Data Guard Go 自动化部署工具 v1.0
数据库·oracle
Nturmoils42 分钟前
自增主键别只会 auto_increment,先把值从哪来讲清楚
数据库·后端
叶小鸡1 小时前
Java 篇-项目实战-AI 天机学堂(从 0 到 1)-day5
数据库·redis·缓存
Slice_cy1 小时前
基于node实现服务端内核引擎
前端·后端
mN9B2uk171 小时前
大数据量高并发的数据库优化
服务器·数据库·oracle
神奇小汤圆1 小时前
什么是面向切面编程AOP?
后端
Database_Cool_1 小时前
PolarSearch AutoETL:让数据库内置搜索不再需要搬运工
数据库
倾颜1 小时前
从手写 Runner 到 LangGraph:受控 Agent 接入 LangGraph
前端·后端·langchain
谁在黄金彼岸2 小时前
Lance模型解读
后端
神奇小汤圆2 小时前
深入理解MySQL事务隔离级别:MVCC机制与Next-Key Lock如何解决幻读问题?
后端