[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

相关推荐
荒川之神4 分钟前
Oracle 数据仓库星座模型(Galaxy Model)设计原则
数据库·数据仓库·oracle
杰克尼5 分钟前
redis(day03-商户查询缓存)
数据库·redis·缓存
枕布响丸辣6 分钟前
Python 操作 MySQL 数据库从入门到精通
数据库·python·mysql
zxrhhm26 分钟前
SQLServer限制特定数据库的CPU使用率,确保关键业务系统有足够的资源
数据库·sqlserver
小村儿42 分钟前
连载04-最重要的Skill---一起吃透 Claude Code,告别 AI coding 迷茫
前端·后端·ai编程
刘~浪地球1 小时前
Redis 从入门到精通(十三):哨兵与集群
数据库·redis·缓存
GDAL1 小时前
Go Channel `close()` 深入全面讲解
golang·通道·close
dyyshb1 小时前
PostgreSQL 终极兜底方案
数据库·postgresql
IT_陈寒2 小时前
Vite的alias配置把我整不会了,原来是这个坑
前端·人工智能·后端
他们叫我技术总监2 小时前
零依赖!FineReport11 快速对接 TDengine 数据库:从驱动部署到报表实现
大数据·数据库·ai·tdengine