Improve Query docs

This commit is contained in:
Jack Christensen 2022-07-23 07:53:02 -05:00
parent cb48716c67
commit 178a84261f

14
conn.go
View File

@ -603,12 +603,16 @@ type QueryRewriter interface {
RewriteQuery(ctx context.Context, conn *Conn, sql string, args []any) (newSQL string, newArgs []any) RewriteQuery(ctx context.Context, conn *Conn, sql string, args []any) (newSQL string, newArgs []any)
} }
// Query executes sql with args. It is safe to attempt to read from the returned Rows even if an error is returned. The // Query sends a query to the server and returns a Rows to read the results. Only errors encountered sending the query
// error will be the available in rows.Err() after rows are closed. So it is allowed to ignore the error returned from // and initializing Rows will be returned. Err() on the returned Rows must be checked after the Rows is closed to
// Query and handle it in Rows. // determine if the query executed successfully.
// //
// Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully // The returned Rows must be closed before the connection can be used again. It is safe to attempt to read from the
// as some errors can only be detected by reading the entire response. e.g. A divide by zero error on the last row. // returned Rows even if an error is returned. The error will be the available in rows.Err() after rows are closed. It
// is allowed to ignore the error returned from Query and handle it in Rows.
//
// An implementor of QueryRewriter may be passed as the first element of args. It can rewrite the sql and change or
// replace args. For example, NamedArgs is QueryRewriter that implements named arguments.
// //
// For extra control over how the query is executed, the types QueryExecMode, QueryResultFormats, and // For extra control over how the query is executed, the types QueryExecMode, QueryResultFormats, and
// QueryResultFormatsByOID may be used as the first args to control exactly how the query is executed. This is rarely // QueryResultFormatsByOID may be used as the first args to control exactly how the query is executed. This is rarely