Skip to content

Commit edd7b2b

Browse files
fix(dashboard-api): sqlc UUID array encoding (#2316)
fix(db): register uuid[] mapping for pgx exec mode Made-with: Cursor
1 parent 8f7060f commit edd7b2b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

packages/db/pkg/pool/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"fmt"
66

77
"github.com/exaring/otelpgx"
8+
"github.com/google/uuid"
89
"github.com/jackc/pgx/v5"
10+
"github.com/jackc/pgx/v5/pgtype"
911
"github.com/jackc/pgx/v5/pgxpool"
1012
"go.opentelemetry.io/otel/attribute"
1113

@@ -32,6 +34,31 @@ func New(ctx context.Context, databaseURL string, poolName string, options ...Op
3234
// Disable statement caching to avoid issues with prepared statements in transactions
3335
config.ConnConfig.DefaultQueryExecMode = pgx.QueryExecModeExec
3436

37+
previousAfterConnect := config.AfterConnect
38+
config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
39+
if previousAfterConnect != nil {
40+
if err := previousAfterConnect(ctx, conn); err != nil {
41+
return err
42+
}
43+
}
44+
45+
typeMap := conn.TypeMap()
46+
typeMap.RegisterType(&pgtype.Type{
47+
Name: "uuid[]",
48+
OID: pgtype.UUIDArrayOID,
49+
Codec: &pgtype.ArrayCodec{
50+
ElementType: &pgtype.Type{
51+
Name: "uuid",
52+
OID: pgtype.UUIDOID,
53+
Codec: pgtype.UUIDCodec{},
54+
},
55+
},
56+
})
57+
typeMap.RegisterDefaultPgType([]uuid.UUID{}, "uuid[]")
58+
59+
return nil
60+
}
61+
3562
// Create the connection pool
3663
pool, err := pgxpool.NewWithConfig(ctx, config)
3764
if err != nil {

0 commit comments

Comments
 (0)