[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

相关推荐
程序员一诺几秒前
【Flask开发】嘿马文学web完整flask项目第3篇:2.用户认证,2.用户认证【附代码文档】
后端·python·flask·框架
mumu-hn3 分钟前
Flask使用MySQL数据库通过Flask-SQLAlchemy 迁移数据库,实际更新文件,但是提示没有检测到数据更新。
数据库·mysql·flask
潇凝子潇3 分钟前
Mac OS 禁用 SIP 系统完整性保护
数据库·mysql
喻师傅12 分钟前
横扫SQL面试——PV、UV问题
大数据·数据库·sql·面试·数据分析·uv
m0_5846245015 分钟前
Spring+hibernate项目碰见了死锁以及锁表的问题--真实线上老项目+sqlserver云数据库没有权限以及个人解决过程
数据库·spring·hibernate
爱的叹息1 小时前
Redis 除了数据类型外的核心功能 的详细说明,包含事务、流水线、发布/订阅、Lua 脚本的完整代码示例和表格总结
数据库·redis·lua
快来卷java4 小时前
MySQL篇(六)MySQL 分库分表:应对数据增长挑战的有效策略
数据库·mysql·oracle
LuckyLay4 小时前
LeetCode算法题(Go语言实现)_32
算法·leetcode·golang
IT认证通关6 小时前
金仓数据库KCM认证考试介绍【2025年4月更新】
数据库
程序猿阿伟6 小时前
《SQL赋能人工智能:解锁特征工程的隐秘力量》
数据库·人工智能·sql