Skip to content

Cross Check/ Advise on a simple implementation that uses an Enum type #1559

Answered by jackc
BigBoulard asked this question in Q&A
Discussion options

You must be logged in to vote

Unless you really need to map the enum string to an integer I would do something like this:

config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
	dt, err := conn.LoadType(ctx, "order_status")
	if err != nil {
		return err
	}

	conn.TypeMap().RegisterType(dt)

	return nil
}

This will maintain an internal registry of enum values. There will only be one copy of any string (per connection).

You can use normal strings or you can still make your own type with a string backing.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@BigBoulard
Comment options

@jackc
Comment options

@BigBoulard
Comment options

@jackc
Comment options

jackc Apr 1, 2023
Maintainer

@BigBoulard
Comment options

Answer selected by BigBoulard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants