getting the driver.Conn from sql

40 views
Skip to first unread message

Daniel Theophanes

unread,
Mar 19, 2019, 12:14:27 PM3/19/19
to golang-sql
There was a recent proposal to get a driver.Conn from the database/sql package:


I closed it, not being convinced by the arguments for it. However, I would love to here specific use cases where this would be a good thing to have. If there is interest I can re-open and discuss on the issue. Let me know. -Daniel

Tamás Gulácsi

unread,
Mar 31, 2019, 1:12:43 AM3/31/19
to golang-sql
gopkg.in/goracle.v2 needs the dirver.Conn for several things: object- and subscription creation, startup and shutdown.
It uses a hack now: a special query string is treated special, returning the connection.
I don't know whether this is safe or not, whether the returned driver connection is put back to the pool or not...

Daniel Theophanes

unread,
Mar 31, 2019, 3:01:49 AM3/31/19
to Tamás Gulácsi, golang-sql
For your purposes, would the following API be able to fully replace your hack?

conn, err := db.Conn(ctx)

// At the end of Raw, if nil is returned, the driver connection is returned to the connection pool.
err = conn.Raw(func(dconn driver.Conn) error{
   // Returning an error will mark connection as bad and not return it to the pool.
   // It will also return the error to the result of Raw.
    return nil
})


--
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/87dc46c6-090b-4c29-bcb9-b9dffa8dbc6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tamás Gulácsi

unread,
Mar 31, 2019, 5:31:24 AM3/31/19
to golang-sql


2019. március 31., vasárnap 9:01:49 UTC+2 időpontban Daniel Theophanes a következőt írta:
For your purposes, would the following API be able to fully replace your hack?

conn, err := db.Conn(ctx)

// At the end of Raw, if nil is returned, the driver connection is returned to the connection pool.
err = conn.Raw(func(dconn driver.Conn) error{
   // Returning an error will mark connection as bad and not return it to the pool.
   // It will also return the error to the result of Raw.
    return nil
})


On Sat, Mar 30, 2019 at 10:12 PM Tamás Gulácsi <tgula...@gmail.com> wrote:

2019. március 19., kedd 17:14:27 UTC+1 időpontban Daniel Theophanes a következőt írta:
There was a recent proposal to get a driver.Conn from the database/sql package:


I closed it, not being convinced by the arguments for it. However, I would love to here specific use cases where this would be a good thing to have. If there is interest I can re-open and discuss on the issue. Let me know. -Daniel

gopkg.in/goracle.v2 needs the dirver.Conn for several things: object- and subscription creation, startup and shutdown.
It uses a hack now: a special query string is treated special, returning the connection.
I don't know whether this is safe or not, whether the returned driver connection is put back to the pool or not...

--
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 golan...@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/87dc46c6-090b-4c29-bcb9-b9dffa8dbc6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


For startup and shutdown: yes.
For object an subscription: not enough. But these are unused and hard interfaces, so I don't really know what would be good for them yet.

As the supposed "Raw" interface is simple, safe and sufficient, I'd be glad to have it!

 
Reply all
Reply to author
Forward
0 new messages