add uuid support

This commit is contained in:
2025-05-15 16:01:07 -04:00
parent 922ba98f6b
commit af4b0190d0
4 changed files with 36 additions and 4 deletions

View File

@@ -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