add uuid support
This commit is contained in:
18
cmd/main.go
18
cmd/main.go
@@ -12,7 +12,9 @@ import (
|
||||
todohandler "gitea.michaelthomson.dev/mthomson/habits/internal/todo/handler"
|
||||
todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository"
|
||||
todoservice "gitea.michaelthomson.dev/mthomson/habits/internal/todo/service"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
pgxuuid "github.com/jackc/pgx-gofrs-uuid"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -30,11 +32,21 @@ func main() {
|
||||
|
||||
// create db pool
|
||||
postgresUrl := "postgres://todo:password@localhost:5432/todo"
|
||||
// db, err := sql.Open("pgx", postgresUrl)
|
||||
db, err := pgxpool.New(context.Background(), postgresUrl)
|
||||
dbconfig, err := pgxpool.ParseConfig(postgresUrl)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
os.Exit(1);
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbconfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
|
||||
pgxuuid.Register(conn.TypeMap())
|
||||
return nil
|
||||
}
|
||||
|
||||
db, err := pgxpool.NewWithConfig(context.Background(), dbconfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// run migrations
|
||||
|
||||
Reference in New Issue
Block a user