Skip to content

Add Config, NewConfig, NewConnectorConfig#1240

Merged
arp242 merged 1 commit intomasterfrom
connect
Jan 20, 2026
Merged

Add Config, NewConfig, NewConnectorConfig#1240
arp242 merged 1 commit intomasterfrom
connect

Conversation

@arp242
Copy link
Copy Markdown
Collaborator

@arp242 arp242 commented Jan 20, 2026

This adds a Config struct and NewConfig() to create it from a DSN and environment. With this, you can do something like:

cfg, err := pq.NewConfig(os.Args[1])
if err != nil {
	return err
}
if cfg.Host == "localhost" {
	cfg.Host = "127.0.0.1"
}

c, err := pq.NewConnectorConfig(cfg)
if err != nil {
	t.Fatal(err)
}

db := sql.OpenDB(c)
defer db.Close()

It also gives a nice place to document the options we support.

The actual code still uses a map, because rewriting all of that is a lot of work. "TODO".

Fixes #856
Fixes #879
Fixes #909
Fixes #1202

This adds a Config struct and NewConfig() to create it from a DSN and
environment. With this, you can do something like:

	cfg, err := pq.NewConfig(os.Args[1])
	if err != nil {
		return err
	}
	if cfg.Host == "localhost" {
		cfg.Host = "127.0.0.1"
	}

	c, err := pq.NewConnectorConfig(cfg)
	if err != nil {
		t.Fatal(err)
	}

	db := sql.OpenDB(c)
	defer db.Close()

It also gives a nice place to document the options we support.

The actual code still uses a map, because rewriting all of that is a lot
of work. "TODO".

Fixes #856
Fixes #879
Fixes #909
Fixes #1202
@arp242 arp242 force-pushed the connect branch 2 times, most recently from b5ca876 to 0ab5dec Compare January 20, 2026 15:15
@arp242 arp242 merged commit e5e969c into master Jan 20, 2026
13 checks passed
@arp242 arp242 deleted the connect branch January 21, 2026 12:29
arp242 added a commit that referenced this pull request Jan 21, 2026
The Config struct I added in #1240 wasn't directly used much but
converted to a map, so I didn't need to rewrite all the code.

This works well enough, but when working on multihost support
(host=one,two) I found it's much more convenient to have access to the
struct since it can parse (and validate) things to a slice on startup,
instead of every time it's used.

So just rewrite the lot.
arp242 added a commit that referenced this pull request Jan 21, 2026
The Config struct I added in #1240 wasn't directly used much but
converted to a map, so I didn't need to rewrite all the code.

This works well enough, but when working on multihost support
(host=one,two) I found it's much more convenient to have access to the
struct since it can parse (and validate) things to a slice on startup,
instead of every time it's used.

So just rewrite the lot.
arp242 added a commit that referenced this pull request Jan 21, 2026
The Config struct I added in #1240 wasn't directly used much but
converted to a map, so I didn't need to rewrite all the code.

This works well enough, but when working on multihost support
(host=one,two) I found it's much more convenient to have access to the
struct since it can parse (and validate) things to a slice on startup,
instead of every time it's used.

So just rewrite the lot.
@qustavo
Copy link
Copy Markdown

qustavo commented Jan 24, 2026

this is great, thanks for doing it. Do you think you can cut a new release for this features?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants