[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

相关推荐
GottdesKrieges16 小时前
OceanBase系统日志管理
数据库·oracle·oceanbase
福大大架构师每日一题16 小时前
go 1.25.1发布:重点修复net/http跨域保护安全漏洞(CVE-2025-47910)
开发语言·http·golang
Dear.爬虫17 小时前
Golang中逃逸现象, 变量“何时栈?何时堆?”
开发语言·后端·golang
参.商.17 小时前
【Day21】146.LRU缓存 (Least Recently Used)
leetcode·缓存·golang
小嵌同学17 小时前
Linux:malloc背后的实现细节
大数据·linux·数据库
努力的小郑17 小时前
MySQL索引(三):字符串索引优化之前缀索引
后端·mysql·性能优化
R瑾安17 小时前
mysql安装(压缩包方式8.0及以上)
数据库·mysql
代码的余温18 小时前
MySQL Cluster核心优缺点
数据库·mysql
IT_陈寒18 小时前
🔥3分钟掌握JavaScript性能优化:从V8引擎原理到5个实战提速技巧
前端·人工智能·后端
程序员清风18 小时前
贝壳一面:年轻代回收频率太高,如何定位?
java·后端·面试