[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

相关推荐
程序员爱钓鱼几秒前
Python编程实战 - 函数与模块化编程 - 导入与使用模块
后端·python·ipython
程序员爱钓鱼4 分钟前
Python编程实战 - 函数与模块化编程 - 匿名函数(lambda)
后端·python·ipython
Moment4 分钟前
记录一次修改 PNPM 版本,部署 NextJs 服务时导致服务器崩溃的问题 😡😡😡
前端·javascript·后端
l1t7 分钟前
用Lua访问DuckDB数据库
数据库·junit·lua·duckdb
星空露珠8 分钟前
数独生成题目lua脚本
数据结构·数据库·算法·游戏·lua
IT_陈寒19 分钟前
我用这5个JavaScript性能优化技巧,让页面加载速度提升了60%
前端·人工智能·后端
清空mega20 分钟前
Flask入门学习指南
后端·python·flask
deephub21 分钟前
构建有记忆的 AI Agent:SQLite 存储 + 向量检索完整方案示例
数据库·人工智能·sqlite·大语言模型·向量检索·智能体
无敌最俊朗@25 分钟前
SQlite:列级,表级约束
数据库
风象南31 分钟前
SpringBoot 时间轮实现延时任务
后端