FAQ
I have been looking at the code but I cannot work out if
the go-mysql-driver supports connection pooling, is there anything that
specifically needs to be implemented for it to support connection pooling
or is this carried out by default in go?

db, err := sql.Open("mysql",
fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8&keepalive=1", DB_USER,
DB_PASS, DB_HOST, DB_NAME))
if err != nil {
panic(err)
}
defer db.Close()
row := db.QueryRow("SELECT `Id`, `UserName`, `EmailAddress`, `Password`,
`IsActive`, `DateJoined`, `LastLoggedOn`, `IsAdministrator` FROM `Person`
WHERE Id=?;", id)
var person Person
row.Scan(&person.Id, &person.UserName, &person.EmailAddress,
&person.Password, &person.IsActive, &person.DateJoined,
&person.LastLoggedOn, &person.IsAdministrator)

--

Search Discussions

  • Minux at Dec 18, 2012 at 5:47 pm

    On Wed, Dec 19, 2012 at 1:38 AM, Ollie Castle wrote:

    I have been looking at the code but I cannot work out if
    the go-mysql-driver supports connection pooling, is there anything that
    specifically needs to be implemented for it to support connection pooling
    or is this carried out by default in go?
    with proper database/sql/driver compatible driver support, Go's
    database/sql package handles
    a limited form of connection pooling, see
    http://golang.org/pkg/database/sql/#DB for details.

    --
  • Julien Schmidt at Dec 18, 2012 at 9:09 pm
    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays. Since
    you aren't the first one confused about connection pooling, i put it on
    my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround for
    a bug in the database/sql package which was fixed in Go 1.0.3

    --
  • Steve wang at Jan 19, 2013 at 1:36 pm
    Can I launch another query before the previous query is closed in a
    goroutine?
    The code looks like this:
    rows, err := db.Query("SELECT ...")
    go func() {
    for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    ...
    }
    }()
    rows2, err := db.Query("SELECT ...")
    ...

    On Wednesday, December 19, 2012 5:09:34 AM UTC+8, Julien Schmidt wrote:

    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays. Since
    you aren't the first one confused about connection pooling, i put it on
    my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround
    for a bug in the database/sql package which was fixed in Go 1.0.3
    --
  • Julien Schmidt at Jan 22, 2013 at 12:48 pm
    Yes, the new Query runs on a different Connection. This should work fine.
    On Saturday, January 19, 2013 2:35:37 PM UTC+1, steve wang wrote:

    Can I launch another query before the previous query is closed in a
    goroutine?
    The code looks like this:
    rows, err := db.Query("SELECT ...")
    go func() {
    for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    ...
    }
    }()
    rows2, err := db.Query("SELECT ...")
    ...

    On Wednesday, December 19, 2012 5:09:34 AM UTC+8, Julien Schmidt wrote:

    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays. Since
    you aren't the first one confused about connection pooling, i put it on
    my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround
    for a bug in the database/sql package which was fixed in Go 1.0.3
    --
  • Steve wang at Jan 22, 2013 at 1:23 pm
    Thanks for your response.
    And this means that this feature is guaranteed by the driver implementation
    instead of the database/sql framework?
    On Tuesday, January 22, 2013 8:48:16 PM UTC+8, Julien Schmidt wrote:

    Yes, the new Query runs on a different Connection. This should work fine.
    On Saturday, January 19, 2013 2:35:37 PM UTC+1, steve wang wrote:

    Can I launch another query before the previous query is closed in a
    goroutine?
    The code looks like this:
    rows, err := db.Query("SELECT ...")
    go func() {
    for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    ...
    }
    }()
    rows2, err := db.Query("SELECT ...")
    ...

    On Wednesday, December 19, 2012 5:09:34 AM UTC+8, Julien Schmidt wrote:

    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays. Since
    you aren't the first one confused about connection pooling, i put it on
    my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround
    for a bug in the database/sql package which was fixed in Go 1.0.3
    --
  • Steve wang at Jan 22, 2013 at 1:23 pm
    Thanks for your response.
    And this means that this feature is guaranteed by the driver implementation
    instead of the database/sql framework?
    On Tuesday, January 22, 2013 8:48:16 PM UTC+8, Julien Schmidt wrote:

    Yes, the new Query runs on a different Connection. This should work fine.
    On Saturday, January 19, 2013 2:35:37 PM UTC+1, steve wang wrote:

    Can I launch another query before the previous query is closed in a
    goroutine?
    The code looks like this:
    rows, err := db.Query("SELECT ...")
    go func() {
    for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    ...
    }
    }()
    rows2, err := db.Query("SELECT ...")
    ...

    On Wednesday, December 19, 2012 5:09:34 AM UTC+8, Julien Schmidt wrote:

    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays. Since
    you aren't the first one confused about connection pooling, i put it on
    my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround
    for a bug in the database/sql package which was fixed in Go 1.0.3
    --
  • Julien Schmidt at Jan 22, 2013 at 10:07 pm
    No, the specs of the database/sql package guarantee that to you :)
    While it might be possible to implement a driver that breaks this spec,
    Go-MySQL-Driver sticks to the specs there.
    For transactions, this is not guaranteed (and technically not even
    possible).
    On Tuesday, January 22, 2013 2:23:07 PM UTC+1, steve wang wrote:

    Thanks for your response.
    And this means that this feature is guaranteed by the driver
    implementation instead of the database/sql framework?
    On Tuesday, January 22, 2013 8:48:16 PM UTC+8, Julien Schmidt wrote:

    Yes, the new Query runs on a different Connection. This should work fine.
    On Saturday, January 19, 2013 2:35:37 PM UTC+1, steve wang wrote:

    Can I launch another query before the previous query is closed in a
    goroutine?
    The code looks like this:
    rows, err := db.Query("SELECT ...")
    go func() {
    for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    ...
    }
    }()
    rows2, err := db.Query("SELECT ...")
    ...

    On Wednesday, December 19, 2012 5:09:34 AM UTC+8, Julien Schmidt wrote:

    The database/sql package does all the connection pooling magic for you.

    I'm going to make a small rewrite of the driver over the holidays.
    Since you aren't the first one confused about connection pooling, i put it
    on my to-do-list for the documentation ;)

    P.S.: the keepalive parameter is deprecated. This was just a workaround
    for a bug in the database/sql package which was fixed in Go 1.0.3
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 18, '12 at 5:38p
activeJan 22, '13 at 10:07p
posts8
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase