sql: parser for DSN

844 views
Skip to first unread message

Archos

unread,
Mar 18, 2013, 5:27:06 AM3/18/13
to golan...@googlegroups.com
The SQL drivers have different schemes to parse the Data Source Name, even in drivers for the same SQL engine, i.e. in
"github.com/Go-SQL-Driver/MySQL" and "github.com/serbaut/go-mysql".

So I think that "database/sql/driver" could have an interface for that all drivers use the same kind of parser, i.e. using RFC 3986 net/url strings as DSN.

Julien Schmidt

unread,
Mar 18, 2013, 6:52:01 AM3/18/13
to golan...@googlegroups.com
I think thats a design which would require an API change (assuming we don't want to confuse the user with a second Open function). So it won't change until Go 2.
But I would appreciate such a uniform DSN.

serbaut

unread,
Mar 18, 2013, 7:27:28 AM3/18/13
to golan...@googlegroups.com
We could use regular urls and let the scheme select driver. For example:

sql.RegisterScheme("foo", &driver{})

sql.RegisterScheme("oracle", &driver{})

db.OpenURL("foo://user:pass@host?foo-specific-params")

db.OpenURL("oracle://user:pass@host?oracle-specific-params")

Having a url makes it easier to handle db config in settings and flags. Like

./myapp --db=oracle://server1

[database]
db = postgresql://localhost

Andy Balholm

unread,
Mar 18, 2013, 12:44:07 PM3/18/13
to golan...@googlegroups.com
I appreciate the drivers that use their database's standard DSN format, like github.com/lib/pq, which uses the same format at the C libpq, and github.com/mattn/go-adodb, which uses the standard ADO format.

I can't comment on MySQL, since I have no idea if there's a standard format for MySQL connection strings.
Reply all
Reply to author
Forward
0 new messages