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
+23.5k Golang : Check if element exist in map
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+13k Golang : Get terminal width and height example
+16.3k Golang : How to extract links from web page ?
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+14.8k Golang : Get URI segments by number and assign as variable example
+6.9k Golang : Pat multiplexer routing example
+5k Golang : Constant and variable names in native language
+14.9k Golang : Submit web forms without browser by http.PostForm example
+11.5k Golang : Change date format to yyyy-mm-dd
+5.4k Golang : fmt.Println prints out empty data from struct