我仍然不是golang 的专家,还在学习.这也是我第一次使用PostgreSQL
import "github.com/jackc/pgx/v5/pgxpool"
const DB = "postgres://postgres:xxx@localhost:5432/mydb?pool_min_conns=1&pool_max_conns=5&pool_max_conn_idle_time=30s"
dbpool, err := pgxpool.New(context.Background(), DB)
if err != nil {
log.Fatal("Unable to create connection pool: "+err.Error())
}
defer dbpool.Close()
1. How to get a connection from the pool and use prepared statements, where you pass the SQL and the SQL values as two separate arguments?个
来自PHP,以前从未使用过数据库池.
2. How to ensure when you pull a connection from the pool is "fresh" and you don't continue on a previous not completed transaction (rollback/commit)?个
3. The same when you release a connection back to the pool. Will it automatically do a rollback if the context is cancelled or the request failed?个
4. How make use of goroutines when requesting the database? Is it possible to make parallel select queries in the same transaction or does all queries have to be serial? I guess all write queries have to be serial?个