Created
January 27, 2023 10:03
-
-
Save arriqaaq/a2432a61984b750ee0398c3a92d6f314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"sync" | |
) | |
var connectionPool = sync.Pool{ | |
New: func() interface{} { | |
db, _ := sql.Open("postgres", "user=postgres dbname=mydb sslmode=disable") | |
return db | |
}, | |
} | |
func main() { | |
// Get a connection from the pool | |
db := connectionPool.Get().(*sql.DB) | |
defer connectionPool.Put(db) | |
// Use the connection | |
_, _ = db.Exec("SELECT 1") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment