Skip to content

Commit fa799a6

Browse files
committed
comments
1 parent d2cd8d7 commit fa799a6

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

coderd/database/awsiamrds/awsiamrds.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (d *awsIamRdsDriver) Open(name string) (driver.Conn, error) {
6969
return conn, nil
7070
}
7171

72+
// Connector returns a driver.Connector that fetches a new authentication token for each connection.
7273
func (d *awsIamRdsDriver) Connector(name string) (driver.Connector, error) {
7374
connector := &connector{
7475
url: name,
@@ -122,7 +123,7 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
122123
return nc.Connect(ctx)
123124
}
124125

125-
func (c *connector) Driver() driver.Driver {
126+
func (*connector) Driver() driver.Driver {
126127
return &pq.Driver{}
127128
}
128129

coderd/database/connector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"github.com/lib/pq"
88
)
99

10+
// ConnectorCreator can create a driver.Connector.
1011
type ConnectorCreator interface {
1112
Connector(name string) (driver.Connector, error)
1213
}
1314

15+
// DialerConnector can create a driver.Connector and set a pq.Dialer.
1416
type DialerConnector interface {
1517
Connect(context.Context) (driver.Conn, error)
1618
Dialer(dialer pq.Dialer)

coderd/database/pubsub/pubsub.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,16 @@ func (p *PGPubsub) startListener(ctx context.Context, connectURL string) error {
441441

442442
// Create a custom connector if the database driver supports it.
443443
connectorCreator, ok := p.db.Driver().(database.ConnectorCreator)
444-
if !ok {
445-
connector, err = pq.NewConnector(connectURL)
444+
if ok {
445+
connector, err = connectorCreator.Connector(connectURL)
446446
if err != nil {
447-
return xerrors.Errorf("create pq connector: %w", err)
447+
return xerrors.Errorf("create custom connector: %w", err)
448448
}
449449
} else {
450-
connector, err = connectorCreator.Connector(connectURL)
450+
// use the default pq connector otherwise
451+
connector, err = pq.NewConnector(connectURL)
451452
if err != nil {
452-
return xerrors.Errorf("create custom connector: %w", err)
453+
return xerrors.Errorf("create pq connector: %w", err)
453454
}
454455
}
455456

0 commit comments

Comments
 (0)