-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elton Minetto
committed
Sep 29, 2021
1 parent
3f486ba
commit d891154
Showing
53 changed files
with
15,073 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
data/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Ent | ||
|
||
## Install | ||
|
||
go get entgo.io/ent/cmd/ent | ||
|
||
## Creating entities | ||
|
||
go run entgo.io/ent/cmd/ent init Student Course Lesson Teacher | ||
|
||
## Configure entities | ||
|
||
- [x] Add fields | ||
|
||
- [x] Add relationships | ||
|
||
Execute: | ||
|
||
go mod tidy | ||
go generate ./ent | ||
|
||
to generate the schema files | ||
|
||
Let's create an main.go just to test the tabel generation. | ||
|
||
|
||
Install PostgreSQL lib: | ||
|
||
go get github.com/lib/pq | ||
|
||
main.go content: | ||
|
||
```go | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/eminetto/go-with-frameworks/ent" | ||
_ "github.com/lib/pq" | ||
) | ||
|
||
func main() { | ||
client, err := ent.Open("postgres", "host=localhost port=5432 user=prest password=prest dbname=prest sslmode=disable") | ||
if err != nil { | ||
log.Fatalf("failed opening connection to db: %v", err) | ||
} | ||
defer client.Close() | ||
// Run the auto migration tool. | ||
if err := client.Schema.Create(context.Background()); err != nil { | ||
log.Fatalf("failed creating schema resources: %v", err) | ||
} | ||
} | ||
|
||
``` | ||
|
||
Execute: | ||
|
||
go run main.go | ||
|
||
And check the tables created in the database | ||
|
||
|
||
# UseCases | ||
|
||
Create directory: | ||
|
||
mkdir -p usecase/student | ||
|
||
Create the interface in `usecase/student/interface.go`: | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: "3" | ||
services: | ||
postgres: | ||
image: postgres | ||
volumes: | ||
- "./data/postgres:/var/lib/postgresql/data" | ||
environment: | ||
- POSTGRES_USER=prest | ||
- POSTGRES_DB=prest | ||
- POSTGRES_PASSWORD=prest | ||
ports: | ||
- "5432:5432" | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready", "-U", "prest"] | ||
interval: 30s | ||
retries: 3 |
Oops, something went wrong.