使用 ent ORM 和 MySQL 的 Fiber 示例
一个如何连接 ent ORM 的示例程序
如何开始(如果 ent 目录不存在)
首先执行命令
go run -mod=mod entgo.io/ent/cmd/ent new Book
进入 ./ent/schema/book.go
并添加你想要的字段到 Book Schema
// Fields of the Book.
func (Book) Fields() []ent.Field {
return []ent.Field{
field.String("title").NotEmpty(),
field.String("author").NotEmpty(),
}
}
执行命令
go generate ./ent
端点
方法 | URL | 描述 |
---|---|---|
GET | /book | 所有书籍信息 |
GET | /book:id | 单本书籍信息 |
POST | /create | 添加一本书 |
PUT | /update/:id | 更新一本书 |
DELETE | /delete/:id | 删除一本书 |