xo / dburl Goto Github PK
View Code? Open in Web Editor NEWPackage dburl provides a standard, URL style mechanism for parsing and opening SQL database connection strings
License: MIT License
Package dburl provides a standard, URL style mechanism for parsing and opening SQL database connection strings
License: MIT License
Hello, the Microsoft go-mssqldb module supports lpc:
and np:
DSNs. Could we get support for that here please? I'd like to use with sql_exporter and have raised this issue there as well.
$ git describe --always --dirty
cd61869
$ go test
--- FAIL: TestParse (0.00s)
dburl_test.go:157: test 3 expected DSN `host=/var/run/postgresql`, got: `dbname=postgresql host=/var/run`
dburl_test.go:157: test 4 expected DSN `dbname=mydb host=/var/run/postgresql port=6666`, got: `dbname=postgresql:6666/mydb host=/var/run`
dburl_test.go:157: test 5 expected DSN `dbname=mydb host=/var/run/postgresql`, got: `dbname=postgresql/mydb host=/var/run`
dburl_test.go:157: test 6 expected DSN `host=/var/run/postgresql port=7777`, got: `dbname=postgresql:7777 host=/var/run`
dburl_test.go:157: test 7 expected DSN `dbname=booktest host=/var/run/postgresql port=4444`, got: `dbname=postgresql:4444/booktest host=/var/run`
dburl_test.go:157: test 8 expected DSN `dbname=mydb host=/var/run/postgresql password=pass user=user`, got: `dbname=postgresql/mydb host=/var/run password=pass user=user`
dburl_test.go:157: test 13 expected DSN `unix(/var/run/mysqld/mysqld.sock)/mydb?timeout=90`, got: `unix(/var/run/mysqld/mysqld.sock/mydb)/?timeout=90`
dburl_test.go:157: test 14 expected DSN `unix(/var/run/mysqld/mysqld.sock)/mydb?timeout=90`, got: `unix(/var/run/mysqld/mysqld.sock/mydb)/?timeout=90`
dburl_test.go:157: test 21 expected DSN `unix:/var/run/mysqld/mysqld.sock,test,timeout=90*mydb`, got: `unix:/var/run/mysqld/mysqld.sock/mydb,test,timeout=90*//`
dburl_test.go:157: test 22 expected DSN `unix:/var/run/mysqld/mysqld.sock,timeout=90*mydb`, got: `unix:/var/run/mysqld/mysqld.sock/mydb,timeout=90*//`
FAIL
exit status 1
FAIL github.com/xo/dburl 0.008s
This package only imports package from stdlib (according to go list -json
), so this doesn't seem to be a version dependency issue.
This result is inconsistent with the build success on Travis, so I don't understand what's happening.
goroutine 1 [running]:
github.com/knq/dburl.mssqlProcess(0xc8200c4000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/apps/go/src/github.com/knq/dburl/dburl.go:113 +0x886
github.com/knq/dburl.Parse(0x7ffc30de1e01, 0x35, 0xe0f1c0, 0x0, 0x0)
/apps/go/src/github.com/knq/dburl/dburl.go:79 +0x56a
main.openDB(0xc8201c2000, 0x0, 0x0)
/apps/go/src/github.com/knq/xo/xo.go:191 +0x63
main.main()
/apps/go/src/github.com/knq/xo/xo.go:43 +0x249
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1
I think this happens because my password needs to be escaped???
my password is "!234#$";
if I pass an invalid password it says it cant connect which the expected result, however when I try the actual one it has this message.
I have tried it on a another DB (postgres) without any fancy password and it worked great, so I am guessing it has to do with the password?
Thanks.
I tried with the following command
usql -c "SELECT username from login;" couchbase://pass:[email protected]/master_erp
I got the following error:
error: n1ql: Connection failed Post "http://user:[email protected]:9000/master_erp/query/service": dial tcp 213.255.246.203:9000: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
N1QL: Unable to connect to cluster endpoint http://user:[email protected]:9000/master_erp. Error Get "http://213.255.246.203:9000/pools": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Anyone can help me to fix the issue?
I would like to contribute a scheme for my driver called mylogin
(see package github.com/dolmen-go/mylogin-driver/register
.
I've started to code the integration, but I'm blocked by the following error:
panic: scheme my already registered
goroutine 1 [running]:
github.com/xo/dburl.registerAlias(0x1142ef4, 0x7, 0x1142ef4, 0x2, 0xc420089b00)
.../src/github.com/xo/dburl/scheme.go:119 +0x3b7
github.com/xo/dburl.Register(0x1142ef4, 0x7, 0x114ca10, 0x0, 0x1, 0x0, 0x0, 0x0, 0x11425b0, 0x0)
.../src/github.com/xo/dburl/scheme.go:167 +0x422
github.com/xo/dburl.init.0()
.../src/github.com/xo/dburl/scheme.go:100 +0xee
FAIL github.com/xo/dburl 0.010s
Error: Tests failed.
It appears that I can't register a second scheme that starts with the same 2 first letters as an existing scheme (scheme mysql
is also automatically registered as my
).
I think that this restriction should be removed: if a scheme has not defined a short name and a short name with the 2 letter prefix already exists, just skip registration of that auto-generated short name.
If not, I can see myself building an external library that builds upon this.
This project looks great!
DSN: mysql://root:secret@tcp(localhost:3306)/mysql
Error: parse "mysql://root:secret@tcp(mysql:3306)/mysql": invalid port ":3306)" after host
I was wondering if there's anyway to add query parameters with dburl
other than parsing twice?
My use case is always adding some pragmas to the SQLite path.
// Parse the dbPath, in this case sqlite::memory:
url, err := dburl.Parse(dbPath)
if err != nil {
return nil, err
}
// Add _foreign_keys pragma
values := url.Query()
values.Set("_foreign_keys", "on")
url.RawQuery = values.Encode()
// url.DSN wasn't updated
db, err := sql.Open("sqlite3", url.DSN)
if err != nil {
return nil, err
}
In the .usqlpass
format, If there are colon characters or pound characters in the password, the parsing module will get the wrong password, and then it will fail to connect.
Tried with usql:
usql "ms://user:pw#[email protected]/base"
error: invalid port
This happens only with mssql. For postgres and mysql '#' doesn't cause any errors.
Parsing of Postgres and MySQL schemes with a file path have different behavior depending if an element of the path exists on the filesystem and has specific properties. See functions resolveDir
and resolveSocket
in util.go
.
This inconsistent behavior of Parse
makes connection failures harder to debug. Worse: this behavior is not documented.
In general, it is very bad that a function called Parse
has different results depending on the filesystem state, as it is not expected by a developer using this API.
Related to #6.
New Relic database integrations rely on custom drivers (eg. nrpostgres
, nrmysql
, etc) to monitor database queries.
Since the list of drivers is predefined in scheme.go
, supporting New Relic drivers require a manual overwrite after the URL is parsed.
I was thinking in opening a PR adding New Relic drivers as aliases for each supported driver, but I'm not sure if that's under the scope of the project. Another option could be use the sql.Drivers()
to retrieve a list of registered drivers - but I'm not sure if we could get all the information from there.
Any thoughts on that?
dburl.Parse
returns an error on MySQL urls with a hostname format like tcp(host:port)
(as seen in the examples for the mysql driver).
package main
import (
"github.com/xo/dburl"
)
func main() {
_, err := dburl.Parse("mysql://user:password@tcp(localhost:3306)/db")
if err != nil {
panic(err)
}
}
bash-5.0$ go1.12.7 run main.go
bash-5.0$ go1.12.8 run main.go
panic: parse mysql://user:password@tcp(mysql:3306)/db: invalid port ":3306)" after host
goroutine 1 [running]:
main.main()
/Users/will.gorman/main.go:10 +0x63
exit status 2
There appears to have been a recent change to the standard library to more closely follow RFC 3986 that caused this.
Should dburl handle that case or is that not a style of URL that dburl was intended to support either?
redis://[pass@][ip\|host\|socket[:port]][/db-index]
duckdb is embedded sqlite-like database - https://duckdb.org/
golang driver - https://github.com/marcboeker/go-duckdb
Since 0.19.1 dburl.Parse
has been returning the postgres
scheme when provided with a file:
scheme path.
This only appears to occur when the path contains a directory that exists on the local filesystem.
u, _ := dburl.Parse("file:file.db")
fmt.Println(u) // prints: sqlite3:file.db
u, _ = dburl.Parse("file:/unknown/file.db")
fmt.Println(u) // prints: sqlite3:/unknown/file.db
u, _ = dburl.Parse("file:/etc/file.db")
fmt.Println(u) // prints: postgres:///etc/file.db
It would be great to be able to support arbitrary protocols. My use case is having different backend drivers for a given scheme.
34fab66 added a second string return parameter to Gen functions, but there doesn't appear to be any documentation on the meaning of the new value. I had to read the code to find out that it's the driver name.
A simple fix is to use named return parameters so that the meanings appear in the signature. I will send a PR soon.
I use this to run local MySQL servers, and I'd like to be able to send the Unix sockets one would use with it (db/mysql.sock
, for instance) into xo. It seems the code explicitly rejects +unix
protocols; is there some other way I can specify a Unix socket? If not, could it be added? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.