upper/db

It can't parse cockroachdb DSN

arantesxyz opened this issue · 2 comments

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.

@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

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.