recipes/ent-mysql

Entgo ORM (MySQL)

Using Entgo ORM with MySQL

Example ent ORM for fiber with MySQL

Github StackBlitz

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 Book

go 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 ./ent

Endpoints

MethodURLDescription
GET/bookAll Books Info
GET/book/:idOne Book Info
POST/createOne Book Add
PUT/update/:idOne Book Update (reads fields from query params)
DELETE/delete/:idOne Book Delete