[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

相关推荐
遨翔在知识的海洋里20 分钟前
nest(5)-文件上传和静态资源
后端
遨翔在知识的海洋里30 分钟前
nest(3)-jwt和RBAC
后端
遨翔在知识的海洋里33 分钟前
nest(5)-Middleware
后端
我不是程序员三三1 小时前
如何监控电脑|企业终端行为监控概念科普与落地方法论
数据库·电脑·php
程序员梅雨1 小时前
Linux & Shell 实用干货
linux·运维·服务器·后端·面试·php
大牧师1 小时前
TypeORM 入门教程
后端·sql·mysql·orm·nest·typeorm
IT_陈寒1 小时前
Vite静态资源路径这个大坑害我调了一下午
前端·人工智能·后端
oliver_sys_log1 小时前
绕过 Yearning 查询体验限制:我做了一个 DataGrip 只读 SQL 代理
后端·mysql
水深火乐1 小时前
golang-jwt v5 入门
后端
carson9551 小时前
基于springboot和vue的文本文件上传下载在线编辑功能
后端