[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

相关推荐
fengxin_rou1 分钟前
一文读懂 Redis 集群:从哈希槽到透明访问
java·数据库·redis·算法·spring·缓存
m0_635647484 分钟前
Qt开发与MySQL数据库教程(二)——MySQL常用命令以及示例
java·开发语言·数据库·mysql
顶点多余6 分钟前
数据库——对表的操作
数据库
程序员榴莲8 分钟前
MySQL (一):MySQL的安装与启动
数据库·mysql
咖啡の猫16 分钟前
Redis 通用命令
数据库·redis·bootstrap
IT界的老黄牛24 分钟前
【IT老齐230 笔记 + 思考】金融业容灾方案“两地三中心“是什么意思?
数据库·笔记·架构
aiAIman25 分钟前
OpenClaw 用户必修课:(三)Claude Code 单一聊天原则、Hooks 与 LSP
数据库·人工智能·开源·aigc
steel808825 分钟前
SSM与Springboot是什么关系? -----区别与联系
java·spring boot·后端
ZHOUPUYU26 分钟前
PHP 8.6的底层革命。那些看不见的优化,才是真正的惊喜
开发语言·后端·php
oradh31 分钟前
Oracle单库环境下计划内启停数据库的步骤
数据库·oracle