[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

相关推荐
猿小喵7 分钟前
浅谈MySQL的redo日志
数据库·mysql
武子康9 分钟前
大数据-159 Apache Kylin Cube 实战:Hive 装载与预计算加速(含 Cuboid/实时 OLAP,Kylin 4.x)
大数据·后端·apache kylin
疯狂的程序猴24 分钟前
Mac 抓包软件怎么选?从 HTTPS 调试、TCP 数据流分析到多工具协同的完整抓包方案
后端
BingoGo35 分钟前
使用 PHP 和 Raylib 也可以开发贪吃蛇游戏
后端·php
陳陈陳39 分钟前
AIGC 时代,用自然语言操作数据库:SQLite + LLM 的轻量级实践
前端·数据库·python
爱分享的鱼鱼39 分钟前
Spring Boot如何整合Redis
后端
知其然亦知其所以然40 分钟前
别再被问住!Redis Cluster 一文彻底讲透(Java 面试必背)
redis·后端·面试
codercwh1 小时前
3 分钟上手 Claude Code!API 中转站让 AI 编程效率翻倍
后端
SimonKing1 小时前
OCR告别付费!分享两款可部署的开源工具
后端
爱叫啥叫啥1 小时前
STM32从零实战:深入理解RCC时钟与按键控制LED的底层原理
后端