Skip to content

Commit a5680bc

Browse files
authored
Merge pull request #2531 from dolmen-go/godoc-add-links
doc: add godoc links
2 parents 08c9bb1 + e34e452 commit a5680bc

10 files changed

Lines changed: 178 additions & 172 deletions

File tree

batch.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/jackc/pgx/v5/pgconn"
99
)
1010

11-
// QueuedQuery is a query that has been queued for execution via a Batch.
11+
// QueuedQuery is a query that has been queued for execution via a [Batch].
1212
type QueuedQuery struct {
1313
SQL string
1414
Arguments []any
@@ -46,7 +46,7 @@ func (qq *QueuedQuery) QueryRow(fn func(row Row) error) {
4646
//
4747
// Note: for simple batch insert uses where it is not required to handle
4848
// each potential error individually, it's sufficient to not set any callbacks,
49-
// and just handle the return value of BatchResults.Close.
49+
// and just handle the return value of [BatchResults.Close].
5050
func (qq *QueuedQuery) Exec(fn func(ct pgconn.CommandTag) error) {
5151
qq.Fn = func(br BatchResults) error {
5252
ct, err := br.Exec()
@@ -65,12 +65,13 @@ type Batch struct {
6565
}
6666

6767
// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement. The only pgx option
68-
// argument that is supported is QueryRewriter. Queries are executed using the connection's DefaultQueryExecMode.
68+
// argument that is supported is [QueryRewriter]. Queries are executed using the connection's DefaultQueryExecMode
69+
// (see [ConnConfig.DefaultQueryExecMode]).
6970
//
70-
// While query can contain multiple statements if the connection's DefaultQueryExecMode is QueryModeSimple, this should
71-
// be avoided. QueuedQuery.Fn must not be set as it will only be called for the first query. That is, QueuedQuery.Query,
72-
// QueuedQuery.QueryRow, and QueuedQuery.Exec must not be called. In addition, any error messages or tracing that
73-
// include the current query may reference the wrong query.
71+
// While query can contain multiple statements if the connection's DefaultQueryExecMode is [QueryExecModeSimpleProtocol],
72+
// this should be avoided. QueuedQuery.Fn must not be set as it will only be called for the first query. That is,
73+
// [QueuedQuery.Query], [QueuedQuery.QueryRow], and [QueuedQuery.Exec] must not be called. In addition, any error
74+
// messages or tracing that include the current query may reference the wrong query.
7475
func (b *Batch) Queue(query string, arguments ...any) *QueuedQuery {
7576
qq := &QueuedQuery{
7677
SQL: query,
@@ -86,20 +87,20 @@ func (b *Batch) Len() int {
8687
}
8788

8889
type BatchResults interface {
89-
// Exec reads the results from the next query in the batch as if the query has been sent with Conn.Exec. Prefer
90+
// Exec reads the results from the next query in the batch as if the query has been sent with [Conn.Exec]. Prefer
9091
// calling Exec on the QueuedQuery, or just calling Close.
9192
Exec() (pgconn.CommandTag, error)
9293

93-
// Query reads the results from the next query in the batch as if the query has been sent with Conn.Query. Prefer
94-
// calling Query on the QueuedQuery.
94+
// Query reads the results from the next query in the batch as if the query has been sent with [Conn.Query]. Prefer
95+
// calling [QueuedQuery.Query].
9596
Query() (Rows, error)
9697

97-
// QueryRow reads the results from the next query in the batch as if the query has been sent with Conn.QueryRow.
98-
// Prefer calling QueryRow on the QueuedQuery.
98+
// QueryRow reads the results from the next query in the batch as if the query has been sent with [Conn.QueryRow].
99+
// Prefer calling [QueuedQuery.QueryRow].
99100
QueryRow() Row
100101

101102
// Close closes the batch operation. All unread results are read and any callback functions registered with
102-
// QueuedQuery.Query, QueuedQuery.QueryRow, or QueuedQuery.Exec will be called. If a callback function returns an
103+
// [QueuedQuery.Query], [QueuedQuery.QueryRow], or [QueuedQuery.Exec] will be called. If a callback function returns an
103104
// error or the batch encounters an error subsequent callback functions will not be called.
104105
//
105106
// For simple batch inserts inside a transaction or similar queries, it's sufficient to not set any callbacks,

conn.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/jackc/pgx/v5/pgtype"
1818
)
1919

20-
// ConnConfig contains all the options used to establish a connection. It must be created by ParseConfig and
21-
// then it can be modified. A manually initialized ConnConfig will cause ConnectConfig to panic.
20+
// ConnConfig contains all the options used to establish a connection. It must be created by [ParseConfig] and
21+
// then it can be modified. A manually initialized ConnConfig will cause [ConnectConfig] to panic.
2222
type ConnConfig struct {
2323
pgconn.Config
2424

@@ -37,8 +37,8 @@ type ConnConfig struct {
3737

3838
// DefaultQueryExecMode controls the default mode for executing queries. By default pgx uses the extended protocol
3939
// and automatically prepares and caches prepared statements. However, this may be incompatible with proxies such as
40-
// PGBouncer. In this case it may be preferable to use QueryExecModeExec or QueryExecModeSimpleProtocol. The same
41-
// functionality can be controlled on a per query basis by passing a QueryExecMode as the first query argument.
40+
// PGBouncer. In this case it may be preferable to use [QueryExecModeExec] or [QueryExecModeSimpleProtocol]. The same
41+
// functionality can be controlled on a per query basis by passing a [QueryExecMode] as the first query argument.
4242
DefaultQueryExecMode QueryExecMode
4343

4444
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
@@ -131,7 +131,7 @@ var (
131131
)
132132

133133
// Connect establishes a connection with a PostgreSQL server with a connection string. See
134-
// pgconn.Connect for details.
134+
// [pgconn.Connect] for details.
135135
func Connect(ctx context.Context, connString string) (*Conn, error) {
136136
connConfig, err := ParseConfig(connString)
137137
if err != nil {
@@ -141,7 +141,7 @@ func Connect(ctx context.Context, connString string) (*Conn, error) {
141141
}
142142

143143
// ConnectWithOptions behaves exactly like Connect with the addition of options. At the present options is only used to
144-
// provide a GetSSLPassword function.
144+
// provide a [pgconn.GetSSLPasswordFunc] function.
145145
func ConnectWithOptions(ctx context.Context, connString string, options ParseConfigOptions) (*Conn, error) {
146146
connConfig, err := ParseConfigWithOptions(connString, options)
147147
if err != nil {
@@ -151,7 +151,7 @@ func ConnectWithOptions(ctx context.Context, connString string, options ParseCon
151151
}
152152

153153
// ConnectConfig establishes a connection with a PostgreSQL server with a configuration struct.
154-
// connConfig must have been created by ParseConfig.
154+
// connConfig must have been created by [ParseConfig].
155155
func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
156156
// In general this improves safety. In particular avoid the config.Config.OnNotification mutation from affecting other
157157
// connections with the same config. See https://github.com/jackc/pgx/issues/618.
@@ -160,8 +160,8 @@ func ConnectConfig(ctx context.Context, connConfig *ConnConfig) (*Conn, error) {
160160
return connect(ctx, connConfig)
161161
}
162162

163-
// ParseConfigWithOptions behaves exactly as ParseConfig does with the addition of options. At the present options is
164-
// only used to provide a GetSSLPassword function.
163+
// ParseConfigWithOptions behaves exactly as [ParseConfig] does with the addition of options. At the present options is
164+
// only used to provide a [pgconn.GetSSLPasswordFunc] function.
165165
func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*ConnConfig, error) {
166166
config, err := pgconn.ParseConfigWithOptions(connString, options.ParseConfigOptions)
167167
if err != nil {
@@ -308,8 +308,8 @@ func (c *Conn) Close(ctx context.Context) error {
308308
}
309309

310310
// Prepare creates a prepared statement with name and sql. sql can contain placeholders for bound parameters. These
311-
// placeholders are referenced positionally as $1, $2, etc. name can be used instead of sql with Query, QueryRow, and
312-
// Exec to execute the statement. It can also be used with Batch.Queue.
311+
// placeholders are referenced positionally as $1, $2, etc. name can be used instead of sql with [Conn.Query],
312+
// [Conn.QueryRow], and [Conn.Exec] to execute the statement. It can also be used with [Batch.Queue].
313313
//
314314
// The underlying PostgreSQL identifier for the prepared statement will be name if name != sql or a digest of sql if
315315
// name == sql.
@@ -933,7 +933,7 @@ func (c *Conn) QueryRow(ctx context.Context, sql string, args ...any) Row {
933933
}
934934

935935
// SendBatch sends all queued queries to the server at once. All queries are run in an implicit transaction unless
936-
// explicit transaction control statements are executed. The returned BatchResults must be closed before the connection
936+
// explicit transaction control statements are executed. The returned [BatchResults] must be closed before the connection
937937
// is used again.
938938
//
939939
// Depending on the QueryExecMode, all queries may be prepared before any are executed. This means that creating a table
@@ -1277,7 +1277,7 @@ func (c *Conn) sanitizeForSimpleQuery(sql string, args ...any) (string, error) {
12771277
return sanitize.SanitizeSQL(sql, valueArgs...)
12781278
}
12791279

1280-
// LoadType inspects the database for typeName and produces a pgtype.Type suitable for registration. typeName must be
1280+
// LoadType inspects the database for typeName and produces a [pgtype.Type] suitable for registration. typeName must be
12811281
// the name of a type where the underlying type(s) is already understood by pgx. It is for derived types. In particular,
12821282
// typeName must be one of the following:
12831283
// - An array type name of a type that is already registered. e.g. "_foo" when "foo" is registered.

copy_from.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/jackc/pgx/v5/pgconn"
1111
)
1212

13-
// CopyFromRows returns a CopyFromSource interface over the provided rows slice
14-
// making it usable by *Conn.CopyFrom.
13+
// CopyFromRows returns a [CopyFromSource] interface over the provided rows slice
14+
// making it usable by [Conn.CopyFrom].
1515
func CopyFromRows(rows [][]any) CopyFromSource {
1616
return &copyFromRows{rows: rows, idx: -1}
1717
}
@@ -34,8 +34,8 @@ func (ctr *copyFromRows) Err() error {
3434
return nil
3535
}
3636

37-
// CopyFromSlice returns a CopyFromSource interface over a dynamic func
38-
// making it usable by *Conn.CopyFrom.
37+
// CopyFromSlice returns a [CopyFromSource] interface over a dynamic func
38+
// making it usable by [Conn.CopyFrom].
3939
func CopyFromSlice(length int, next func(int) ([]any, error)) CopyFromSource {
4040
return &copyFromSlice{next: next, idx: -1, len: length}
4141
}
@@ -64,7 +64,7 @@ func (cts *copyFromSlice) Err() error {
6464
return cts.err
6565
}
6666

67-
// CopyFromFunc returns a CopyFromSource interface that relies on nxtf for values.
67+
// CopyFromFunc returns a [CopyFromSource] interface that relies on nxtf for values.
6868
// nxtf returns rows until it either signals an 'end of data' by returning row=nil and err=nil,
6969
// or it returns an error. If nxtf returns an error, the copy is aborted.
7070
func CopyFromFunc(nxtf func() (row []any, err error)) CopyFromSource {
@@ -91,7 +91,7 @@ func (g *copyFromFunc) Err() error {
9191
return g.err
9292
}
9393

94-
// CopyFromSource is the interface used by *Conn.CopyFrom as the source for copy data.
94+
// CopyFromSource is the interface used by [Conn.CopyFrom] as the source for copy data.
9595
type CopyFromSource interface {
9696
// Next returns true if there is another row and makes the next row data
9797
// available to Values(). When there are no more rows available or an error
@@ -260,8 +260,8 @@ func (ct *copyFrom) buildCopyBuf(buf []byte, sd *pgconn.StatementDescription) (b
260260
// CopyFrom requires all values use the binary format. A pgtype.Type that supports the binary format must be registered
261261
// for the type of each column. Almost all types implemented by pgx support the binary format.
262262
//
263-
// Even though enum types appear to be strings they still must be registered to use with CopyFrom. This can be done with
264-
// Conn.LoadType and pgtype.Map.RegisterType.
263+
// Even though enum types appear to be strings they still must be registered to use with [Conn.CopyFrom]. This can be done with
264+
// [Conn.LoadType] and [pgtype.Map.RegisterType].
265265
func (c *Conn) CopyFrom(ctx context.Context, tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int64, error) {
266266
ct := &copyFrom{
267267
conn: c,

0 commit comments

Comments
 (0)