recipes/ent-mysql
Entgo ORM (MySQL)
Using Entgo ORM with MySQL
Example ent ORM for fiber with MySQL
A sample program how to connect ent ORM
How to start (If no ent dir)
Execute command first
go run -mod=mod entgo.io/ent/cmd/ent new Bookgo to ./ent/schema/book.go and add fields(you want) to Book Schema
// Fields of the Book.
func (Book) Fields() []ent.Field {
return []ent.Field{
field.String("title").NotEmpty(),
field.String("author").NotEmpty(),
}
}Execute command
go generate ./entEndpoints
| Method | URL | Description |
|---|---|---|
| GET | /book | All Books Info |
| GET | /book/:id | One Book Info |
| POST | /create | One Book Add |
| PUT | /update/:id | One Book Update (reads fields from query params) |
| DELETE | /delete/:id | One Book Delete |