summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgx/v4/conn.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/jackc/pgx/v4/conn.go')
-rw-r--r--vendor/github.com/jackc/pgx/v4/conn.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/vendor/github.com/jackc/pgx/v4/conn.go b/vendor/github.com/jackc/pgx/v4/conn.go
index 9636f2fd6..102158ab5 100644
--- a/vendor/github.com/jackc/pgx/v4/conn.go
+++ b/vendor/github.com/jackc/pgx/v4/conn.go
@@ -50,6 +50,7 @@ func (cc *ConnConfig) Copy() *ConnConfig {
return newConfig
}
+// ConnString returns the connection string as parsed by pgx.ParseConfig into pgx.ConnConfig.
func (cc *ConnConfig) ConnString() string { return cc.connString }
// BuildStatementCacheFunc is a function that can be used to create a stmtcache.Cache implementation for connection.
@@ -107,8 +108,8 @@ func Connect(ctx context.Context, connString string) (*Conn, error) {
return connect(ctx, connConfig)
}
-// Connect establishes a connection with a PostgreSQL server with a configuration struct. connConfig must have been
-// created by ParseConfig.
+// ConnectConfig establishes a connection with a PostgreSQL server with a configuration struct.
+// connConfig must have been created by ParseConfig.
func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
return connect(ctx, connConfig)
}
@@ -324,6 +325,7 @@ func (c *Conn) WaitForNotification(ctx context.Context) (*pgconn.Notification, e
return n, err
}
+// IsClosed reports if the connection has been closed.
func (c *Conn) IsClosed() bool {
return c.pgConn.IsClosed()
}
@@ -357,6 +359,8 @@ func quoteIdentifier(s string) string {
return `"` + strings.ReplaceAll(s, `"`, `""`) + `"`
}
+// Ping executes an empty sql statement against the *Conn
+// If the sql returns without error, the database Ping is considered successful, otherwise, the error is returned.
func (c *Conn) Ping(ctx context.Context) error {
_, err := c.Exec(ctx, ";")
return err
@@ -517,6 +521,7 @@ func (c *Conn) execParams(ctx context.Context, sd *pgconn.StatementDescription,
}
result := c.pgConn.ExecParams(ctx, sd.SQL, c.eqb.paramValues, sd.ParamOIDs, c.eqb.paramFormats, c.eqb.resultFormats).Read()
+ c.eqb.Reset() // Allow c.eqb internal memory to be GC'ed as soon as possible.
return result.CommandTag, result.Err
}
@@ -527,6 +532,7 @@ func (c *Conn) execPrepared(ctx context.Context, sd *pgconn.StatementDescription
}
result := c.pgConn.ExecPrepared(ctx, sd.Name, c.eqb.paramValues, c.eqb.paramFormats, c.eqb.resultFormats).Read()
+ c.eqb.Reset() // Allow c.eqb internal memory to be GC'ed as soon as possible.
return result.CommandTag, result.Err
}
@@ -558,8 +564,12 @@ type QueryResultFormats []int16
// QueryResultFormatsByOID controls the result format (text=0, binary=1) of a query by the result column OID.
type QueryResultFormatsByOID map[uint32]int16
-// Query executes sql with args. If there is an error the returned Rows will be returned in an error state. So it is
-// allowed to ignore the error returned from Query and handle it in Rows.
+// Query executes sql with args. It is safe to attempt to read from the returned Rows even if an error is returned. The
+// error will be the available in rows.Err() after rows are closed. So it is allowed to ignore the error returned from
+// Query and handle it in Rows.
+//
+// Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully
+// as some errors can only be detected by reading the entire response. e.g. A divide by zero error on the last row.
//
// For extra control over how the query is executed, the types QuerySimpleProtocol, QueryResultFormats, and
// QueryResultFormatsByOID may be used as the first args to control exactly how the query is executed. This is rarely
@@ -670,6 +680,8 @@ optionLoop:
rows.resultReader = c.pgConn.ExecPrepared(ctx, sd.Name, c.eqb.paramValues, c.eqb.paramFormats, resultFormats)
}
+ c.eqb.Reset() // Allow c.eqb internal memory to be GC'ed as soon as possible.
+
return rows, rows.err
}
@@ -817,6 +829,8 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) BatchResults {
}
}
+ c.eqb.Reset() // Allow c.eqb internal memory to be GC'ed as soon as possible.
+
mrr := c.pgConn.ExecBatch(ctx, batch)
return &batchResults{