Golang database/sql.DB.SetMaxIdleConns function example
package database/sql
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit
If n <= 0, no idle connections are retained.
Golang database/sql.DB.SetMaxIdleConns function usage example
const concurrencyLevel = 10
db := initDB(b,
"DROP TABLE IF EXISTS foo",
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))",
`INSERT INTO foo VALUES (1, "one")`,
`INSERT INTO foo VALUES (2, "two")`,
)
db.SetMaxIdleConns(concurrencyLevel) // <-- here
defer db.Close()
Reference :
Advertisement
Something interesting
Tutorials
+15.3k Golang : How to get Unix file descriptor for console and file
+9.9k Golang : Check if user agent is a robot or crawler example
+6.6k Golang : How to validate ISBN?
+16.5k Golang : File path independent of Operating System
+8.1k Golang : Append and add item in slice
+29.5k Golang : Saving(serializing) and reading file with GOB
+7.1k Golang : A simple forex opportunities scanner
+30.5k Get client IP Address in Go
+24k Golang : Find biggest/largest number in array
+9.1k Golang : Get curl -I or head data from URL example
+14.5k Golang : How to determine if user agent is a mobile device example