[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

相关推荐
czhc11400756631 天前
c# 1213
开发语言·数据库·c#
voltina1 天前
【SQL】【事务】
数据库·sql
文心快码BaiduComate1 天前
我用文心快码Spec 模式搓了个“pre作弊器”,妈妈再也不用担心我开会忘词了(附源码)
前端·后端·程序员
古渡蓝按1 天前
PostgreSQL数据库在Windows上实现异地自动备份指南-喂饭图文教程
数据库
aiopencode1 天前
iOS 性能监控 运行时指标与系统行为的多工具协同方案
后端
她说..1 天前
MySQL数据处理(增删改)
java·开发语言·数据库·mysql·java-ee
E***U9451 天前
从新手到入门:如何判断自己是否真的学会了 Spring Boot
数据库·spring boot·后端
古城小栈1 天前
Golang 中 return 与 defer 的 长幼尊卑
golang
招风的黑耳1 天前
智慧养老项目:当SpringBoot遇到硬件,如何优雅地处理异常与状态管理?
java·spring boot·后端
Alex Gram1 天前
MySQL实时同步到SQL Server:技术方案与实现路径
数据库·mysql