go1.10, sql.OpenDB, Connector and DSNs.

56 views
Skip to first unread message

Ren Thraysk

unread,
Dec 24, 2017, 11:40:36 AM12/24/17
to golang-sql
Hi,

Just want to query why there is Driver() method in the Connector interface?
I thought the Connector was to be able to do away with using inflexible DSNs, and also to avoid having to globally sql.Register drivers?

But current interface methods Connector.Driver(), and Driver.Open(name string) kind of forces an implementation to use DSNs, rather unnecessarily I think.

func main() {
    connector, err := mysqlx.New("tcp", "127.0.0.1:33060",
        mysqlx.WithDatabase("test"),
        mysqlx.WithUserPassword("testuser", "password"),
        mysqlx.WithCharset("utf8mb4"),
        mysqlx.WithIsolationLevel(sql.LevelReadCommitted),
    )
    if err != nil {
        log.Fatalf("creating connector failed: %s", err)
    }
    db := sql.OpenDB(connector)

    err = db.Ping()
    if err != nil {
        log.Fatalf("ping failed: %s", err)
    }

    db.Close()
}

Ren

Daniel Theophanes

unread,
Jan 1, 2018, 1:52:11 PM1/1/18
to Ren Thraysk, golang-sql
Hi Ren,

Sorry for the delay in responding.

You're concerns are ligament, but until Go2, we can't break API compatibility. Thus Driver must stay. However, the call to Driver.Open could choose to panic for a given implementation with an appropriate error message.

See https://github.com/golang/go/issues/22697#issuecomment-344095510 for my comments on what changes I would like to see for Go2.

Thanks, -Daniel


--
You received this message because you are subscribed to the Google Groups "golang-sql" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-sql+...@googlegroups.com.
To post to this group, send email to golan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-sql/81c29781-d0c5-418a-bce4-e02403c15323%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages