feat(backend): pg-connector use Temeout context
This commit is contained in:
parent
7f14269671
commit
ca870106e2
1 changed files with 8 additions and 3 deletions
|
|
@ -8,6 +8,11 @@ import (
|
|||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
func getTimeoutContext() context.Context {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(time.Second*10))
|
||||
return ctx
|
||||
}
|
||||
|
||||
type Conn struct {
|
||||
c *pgxpool.Pool // TODO: conditional usage of Pool/Conn (use interface?)
|
||||
}
|
||||
|
|
@ -26,15 +31,15 @@ func (conn *Conn) Close() error {
|
|||
}
|
||||
|
||||
func (conn *Conn) query(sql string, args ...interface{}) (pgx.Rows, error) {
|
||||
return conn.c.Query(context.Background(), sql, args...)
|
||||
return conn.c.Query(getTimeoutContext(), sql, args...)
|
||||
}
|
||||
|
||||
func (conn *Conn) queryRow(sql string, args ...interface{}) pgx.Row {
|
||||
return conn.c.QueryRow(context.Background(), sql, args...)
|
||||
return conn.c.QueryRow(getTimeoutContext(), sql, args...)
|
||||
}
|
||||
|
||||
func (conn *Conn) exec(sql string, args ...interface{}) error {
|
||||
_, err := conn.c.Exec(context.Background(), sql, args...)
|
||||
_, err := conn.c.Exec(getTimeoutContext(), sql, args...)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue