diff --git a/pkg/pgtypes.go b/pkg/pgtypes.go index 25326a5..6b02fbd 100644 --- a/pkg/pgtypes.go +++ b/pkg/pgtypes.go @@ -7,6 +7,10 @@ import ( "github.com/jackc/pgx/v4" ) +var ( + oidCache = make(map[string]uint32) +) + type CustomerTaxDetails struct { BusinessName string VATIN string @@ -325,8 +329,12 @@ func registerPgTypes(ctx context.Context, conn *pgx.Conn) error { } func registerPgType(ctx context.Context, conn *pgx.Conn, value pgtype.Value, name string) (oid uint32, err error) { - if err = conn.QueryRow(ctx, "select $1::regtype::oid", name).Scan(&oid); err != nil { - return + var found bool + if oid, found = oidCache[name]; !found { + if err = conn.QueryRow(ctx, "select $1::regtype::oid", name).Scan(&oid); err != nil { + return + } + oidCache[name] = oid } conn.ConnInfo().RegisterDataType(pgtype.DataType{Value: value, Name: name, OID: oid}) return