Closed olliemoves closed 11 years ago
For connection pooling use database/sql package and mymysql/godrv as driver. Furthermore, if you use database/sql, your application can work with any database system (Postgress, . SQLite, MongoDB, ...)
Use raw mymysql only if you have specific problem that is difficult to be resolved using database/sql. In this case mymysql/autorc is preferred. Use mymysql/mysql only if you need some functionality that autorc lacks or if you want implement over it your own higher level interface (eg: connection pooling: http://www.ryanday.net/2012/09/12/golang-using-channels-for-a-connection-pool/).
See also: https://github.com/ziutek/mymysql/issues/42
Don't create an issue for simple question! Issue tracker is for issues. You can send such questions to golang-nuts list where are many people that can help you.
Hi,
Firstly thank you for writing such a good library. This is not a bug I am just seeking some advice on using the library. I have currently written my database layer using MyMysql for a big project and I am very happy with how everything is working but I wanted to check that I am using it correctly as I think I might be opening and closing connections every time I connect to the database and I was hoping to use connection pooling type functionality.
I have a getConnection class which is used by all methods and I then use defer to close the connection at the end of the method:
As you can see in the GetCourseById I defer db.Close() so it closes at the end of the method. Does the MyMysql library support connection pooling or should I use the auto reconnect library and never close the connection?