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

It can't parse cockroachdb DSN #698

Open
arantesxyz opened this issue Sep 21, 2023 · 2 comments
Open

It can't parse cockroachdb DSN #698

arantesxyz opened this issue Sep 21, 2023 · 2 comments

Comments

@arantesxyz
Copy link

I'm trying to connect to a database with this DSN: cockroachdb://test:test@host:26257/test?sslmode=verify-full. (I changed the password and host for this example)

This is the code:

connURL, err := crdb.ParseURL(os.Getenv("DATABASE_URI"))
if err != nil {
  return nil, err
}

sess, err := crdb.Open(connURL)
if err != nil {
  return nil, err
}

And I'm getting the error bellow:

$ env DATABASE_URI=cockroachdb://test:test@host:26257/test?sslmode=verify-full go run main.go start

failed to connect to `host=127.0.0.1 user=arantes database=`: dial error (dial tcp 127.0.0.1:26257: connect: connection refused)
exit status 1

But if I use postgres schema in the DSN (postgres://test:test@host:26257/test?sslmode=verify-full), it works fine.

@GaMoCh
Copy link

GaMoCh commented Oct 1, 2023

@arantesxyz

The CockroachDB documentation connection-parameters says that the URL scheme used is postgres://, is there any specification in the documentation that shows the use of cockroachdb://?

If the cockroachdb:// URL scheme is valid, you can open a PR by changing the file: cockroachdb/connection.go

The Cockroach CLI has the convert-url command that converts an SQL connection string for use with various client drivers, and the cockroachdb URL scheme is an unrecognized URL scheme.

cockroach convert-url --url "cockroachdb://test:test@host:26257/test?sslmode=verify-full"
ERROR: unrecognized URL scheme: cockroachdb
Failed running "convert-url"
cockroach convert-url --url "postgres://test:test@host:26257/test?sslmode=verify-full"
# Connection URL for libpq (C/C++), psycopg (Python), lib/pq & pgx (Go), node-postgres (JS) and most pq-compatible drivers:
postgresql://test:test@host:26257/test?sslmode=verify-full

# Connection DSN (Data Source Name) for Postgres drivers that accept DSNs - most drivers and also ODBC:
database=test user=test host=host port=26257 password=test sslmode=verify-full

# Connection URL for JDBC (Java and JVM-based languages):
jdbc:postgresql://host:26257/test?password=test&sslmode=verify-full&user=test

@arantesxyz
Copy link
Author

@arantesxyz

The CockroachDB documentation connection-parameters says that the URL scheme used is postgres://, is there any specification in the documentation that shows the use of cockroachdb://?

If the cockroachdb:// URL scheme is valid, you can open a PR by changing the file: cockroachdb/connection.go

The Cockroach CLI has the convert-url command that converts an SQL connection string for use with various client drivers, and the cockroachdb URL scheme is an unrecognized URL scheme.


cockroach convert-url --url "cockroachdb://test:test@host:26257/test?sslmode=verify-full"

ERROR: unrecognized URL scheme: cockroachdb

Failed running "convert-url"


cockroach convert-url --url "postgres://test:test@host:26257/test?sslmode=verify-full"

# Connection URL for libpq (C/C++), psycopg (Python), lib/pq & pgx (Go), node-postgres (JS) and most pq-compatible drivers:

postgresql://test:test@host:26257/test?sslmode=verify-full



# Connection DSN (Data Source Name) for Postgres drivers that accept DSNs - most drivers and also ODBC:

database=test user=test host=host port=26257 password=test sslmode=verify-full



# Connection URL for JDBC (Java and JVM-based languages):

jdbc:postgresql://host:26257/test?password=test&sslmode=verify-full&user=test

The DSN I'm using was generated by the CockroachDB cloud panel, I'm using postgres schema to run the code, it works fine, but i do think upper should implement this directly into their parse logic.

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

No branches or pull requests

3 participants