Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35db8be

Browse files
authoredJan 19, 2025··
client: Update docs (#970)
* client: Update docs * CI: don't lint the examples
1 parent c8c056b commit 35db8be

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed
 

‎.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ linters-settings:
3030
- fieldalignment
3131
- lostcancel
3232
- shadow
33+
issues:
34+
exclude-files:
35+
- client/examples_test.go

‎client/conn.go

+7-16
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,15 @@ func (c *Conn) GetDB() string {
265265
return c.db
266266
}
267267

268+
// GetServerVersion returns the version of the server as reported by the server
269+
// in the initial server greeting.
268270
func (c *Conn) GetServerVersion() string {
269271
return c.serverVersion
270272
}
271273

274+
// CompareServerVersion is comparing version v against the version
275+
// of the server and returns 0 if they are equal, and 1 if the server version
276+
// is higher and -1 if the server version is lower.
272277
func (c *Conn) CompareServerVersion(v string) (int, error) {
273278
return CompareServerVersions(c.serverVersion, v)
274279
}
@@ -294,13 +299,6 @@ func (c *Conn) Execute(command string, args ...interface{}) (*Result, error) {
294299
// When ExecuteMultiple is used, the connection should have the SERVER_MORE_RESULTS_EXISTS
295300
// flag set to signal the server multiple queries are executed. Handling the responses
296301
// is up to the implementation of perResultCallback.
297-
//
298-
// Example:
299-
//
300-
// queries := "SELECT 1; SELECT NOW();"
301-
// conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) {
302-
// // Use the result as you want
303-
// })
304302
func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCallback) (*Result, error) {
305303
if err := c.writeCommandStr(COM_QUERY, query); err != nil {
306304
return nil, errors.Trace(err)
@@ -354,15 +352,6 @@ func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCall
354352
// When given, perResultCallback will be called once per result
355353
//
356354
// ExecuteSelectStreaming should be used only for SELECT queries with a large response resultset for memory preserving.
357-
//
358-
// Example:
359-
//
360-
// var result mysql.Result
361-
// conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error {
362-
// // Use the row as you want.
363-
// // You must not save FieldValue.AsString() value after this callback is done. Copy it if you need.
364-
// return nil
365-
// }, nil)
366355
func (c *Conn) ExecuteSelectStreaming(command string, result *Result, perRowCallback SelectPerRowCallback, perResultCallback SelectPerResultCallback) error {
367356
if err := c.writeCommandStr(COM_QUERY, command); err != nil {
368357
return errors.Trace(err)
@@ -494,6 +483,8 @@ func (c *Conn) exec(query string) (*Result, error) {
494483
return c.readResult(false)
495484
}
496485

486+
// CapabilityString is returning a string with the names of capability flags
487+
// separated by "|". Examples of capability names are CLIENT_DEPRECATE_EOF and CLIENT_PROTOCOL_41.
497488
func (c *Conn) CapabilityString() string {
498489
var caps []string
499490
capability := c.capability

‎client/examples_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package client_test
2+
3+
import (
4+
"github.com/go-mysql-org/go-mysql/client"
5+
"github.com/go-mysql-org/go-mysql/mysql"
6+
)
7+
8+
var (
9+
conn *client.Conn
10+
)
11+
12+
func ExampleConn_ExecuteMultiple() {
13+
queries := "SELECT 1; SELECT NOW();"
14+
conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) {
15+
// Use the result as you want
16+
})
17+
}
18+
19+
func ExampleConn_ExecuteSelectStreaming() {
20+
var result mysql.Result
21+
conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error {
22+
// Use the row as you want.
23+
// You must not save FieldValue.AsString() value after this callback is done. Copy it if you need.
24+
return nil
25+
}, nil)
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.