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
+12.1k Golang : Pagination with go-paginator configuration example
+16.5k Golang : Execute terminal command to remote machine example
+4.6k Linux : sudo yum updates not working
+21.8k SSL : How to check if current certificate is sha1 or sha2
+19.1k Golang : Clearing slice
+9k Golang : Get SPF and DMARC from email headers to fight spam
+7.7k Golang : Generate human readable password
+6k Golang : Function as an argument type example
+5.1k Linux : How to set root password in Linux Mint
+30k Golang : Get time.Duration in year, month, week or day
+16.6k Golang : Delete files by extension
+13.4k Golang : Generate Code128 barcode