33 lines
631 B
Go
33 lines
631 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"omctf.ru/block-game-backend/codegen/ent"
|
|
)
|
|
|
|
var Client *ent.Client
|
|
|
|
func Initialize() {
|
|
ctx := context.Background()
|
|
|
|
var err error
|
|
Client, err = ent.Open("postgres", "host=postgres port=5432 user=postgres dbname=blockgame password=postgres sslmode=disable")
|
|
if err != nil {
|
|
log.Fatalf("failed opening connection to postgres: %v", err)
|
|
}
|
|
|
|
// uncomment to show the queries
|
|
// Client = Client.Debug()
|
|
|
|
// Run the auto migration tool.
|
|
if err := Client.Schema.Create(ctx); err != nil {
|
|
log.Fatalf("failed creating schema resources: %v", err)
|
|
}
|
|
}
|
|
|
|
func Close() {
|
|
Client.Close()
|
|
}
|