Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 27, 2023 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/a2432a61984b750ee0398c3a92d6f314 to your computer and use it in GitHub Desktop.
Save arriqaaq/a2432a61984b750ee0398c3a92d6f314 to your computer and use it in GitHub Desktop.
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