[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

相关推荐
PythonFun2 分钟前
如何在WPS实现平行语料库简易检索
数据库·wps
ruxshui3 分钟前
Inceptor/hive中整数类型分桶键数据倾斜问题及优化方案
大数据·数据库·sql
OnYoung4 分钟前
Python生成器(Generator)与Yield关键字:惰性求值之美
jvm·数据库·python
Albert Tan17 分钟前
Oracle EBS 12.2.14双应用节点应用补丁-ADOP
数据库·oracle
觉醒大王20 分钟前
简单说说参考文献引用
java·前端·数据库·学习·自然语言处理·学习方法·迁移学习
what丶k32 分钟前
MySQL读写分离部署配置全解析(从原理到落地)
数据库·分布式·mysql
shengli72235 分钟前
Python Lambda(匿名函数):简洁之道
jvm·数据库·python
我爱娃哈哈40 分钟前
SpringBoot 实现 RSA+AES 自动接口解密
java·spring boot·后端
崎岖Qiu41 分钟前
SpringBoot:基于注解 @PostConstruct 和 ApplicationRunner 进行初始化的区别
java·spring boot·后端·spring·javaee
沈雅馨41 分钟前
SQL语言的云计算
开发语言·后端·golang