Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got error pq: syntax error at the end of ... when doing custom dialer #1165

Open
QuangTung97 opened this issue Jul 29, 2024 · 0 comments
Open

Comments

@QuangTung97
Copy link

QuangTung97 commented Jul 29, 2024

I tried to do custom dialing using this example:
#470 (comment)

type drvWrapper struct{}

type customDialer struct{}

func (d *drvWrapper) Open(name string) (driver.Conn, error) {
	return pq.DialOpen(customDialer{}, name)
}

func (customDialer) Dial(network, address string) (net.Conn, error) {
	return net.Dial(network, address)
}

func (customDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
	return net.DialTimeout(network, address, timeout)
}

func init() {
	sql.Register("mypq", &drvWrapper{})
}

And then create a DB through sqlx:

	db := sqlx.MustOpen("mypq", "postgres://"+cfg.Postgres.DSN())

I encountered this error: "pq: syntax error at end of input"

But when I switched back the default driver name:

	db := sqlx.MustOpen("postgres", "postgres://"+cfg.Postgres.DSN())

The error immediately went away.
Could anyone help me point out the problem? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant