[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

相关推荐
杜子不疼.2 分钟前
【C++ AI 大模型接入 SDK】 - 环境搭建
开发语言·数据库·c++
神奇小汤圆3 分钟前
背了那么久的慢 SQL 八股,不如动手跑一遍 EXPLAIN
后端
qq_283720054 分钟前
Milvus 向量数据库全链路优化实战教程
数据库·milvus
m0_702036534 分钟前
CSS如何兼容新旧方案结合响应式容器查询
jvm·数据库·python
ClouGence10 分钟前
我们做了个疯狂的决定,把 CloudDM 全部开源了
数据库·后端·mysql
努力努力再努力wz18 分钟前
【Qt入门系列】深入理解信号与槽:从事件响应到自定义信号机制
c语言·开发语言·数据结构·数据库·c++·qt·mysql
神奇小汤圆21 分钟前
MySQL慢查询优化案例:真实案例+EXPLAIN分析——性能提升10倍!
后端
还没学会摸鱼的钓鱼仔37 分钟前
手撕 LangChain Deep Agents 源码 (一):create_deep_agent 是如何"组装"出一个 AI 操作系统的
后端
2501_9219392638 分钟前
Redis
数据库·redis·缓存
用户2986985301439 分钟前
Java 操作 Word 文档:数学公式与符号的插入方法
java·后端