[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

相关推荐
JaguarJack11 分钟前
为什么 PHP 闭包要加 static?
后端·php·服务端
BingoGo21 分钟前
为什么 PHP 闭包要加 static?
后端
是糖糖啊41 分钟前
OpenClaw 从零到一实战指南(飞书接入)
前端·人工智能·后端
百度Geek说1 小时前
基于Spark的配置化离线反作弊系统
后端
Java编程爱好者1 小时前
虚拟线程深度解析:轻量并发编程的未来趋势
后端
苏三说技术1 小时前
Spring AI 和 LangChain4j ,哪个更好?
后端
Soofjan2 小时前
(二)数组和切片
后端
Java不加班2 小时前
Nginx 核心实战指南:反向代理、负载均衡与动静分离
后端
子玖2 小时前
微信扫码注册登录-基于网站应用
后端·微信·go