Skip to content

Commit

Permalink
client: Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Jan 15, 2025
1 parent d02e79a commit 8662d59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
23 changes: 7 additions & 16 deletions client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,15 @@ func (c *Conn) GetDB() string {
return c.db
}

// GetServerVersion returns the version of the server as reported by the server
// in the initial server greeting.
func (c *Conn) GetServerVersion() string {
return c.serverVersion
}

// CompareServerVersion is comparing version v against the version
// of the server and returns 0 if they are equal, and 1 if the server version
// is higher and -1 if the server version is lower.
func (c *Conn) CompareServerVersion(v string) (int, error) {
return CompareServerVersions(c.serverVersion, v)
}
Expand All @@ -294,13 +299,6 @@ func (c *Conn) Execute(command string, args ...interface{}) (*Result, error) {
// When ExecuteMultiple is used, the connection should have the SERVER_MORE_RESULTS_EXISTS
// flag set to signal the server multiple queries are executed. Handling the responses
// is up to the implementation of perResultCallback.
//
// Example:
//
// queries := "SELECT 1; SELECT NOW();"
// conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) {
// // Use the result as you want
// })
func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCallback) (*Result, error) {
if err := c.writeCommandStr(COM_QUERY, query); err != nil {
return nil, errors.Trace(err)
Expand Down Expand Up @@ -354,15 +352,6 @@ func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCall
// When given, perResultCallback will be called once per result
//
// ExecuteSelectStreaming should be used only for SELECT queries with a large response resultset for memory preserving.
//
// Example:
//
// var result mysql.Result
// conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error {
// // Use the row as you want.
// // You must not save FieldValue.AsString() value after this callback is done. Copy it if you need.
// return nil
// }, nil)
func (c *Conn) ExecuteSelectStreaming(command string, result *Result, perRowCallback SelectPerRowCallback, perResultCallback SelectPerResultCallback) error {
if err := c.writeCommandStr(COM_QUERY, command); err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -494,6 +483,8 @@ func (c *Conn) exec(query string) (*Result, error) {
return c.readResult(false)
}

// CapabilityString is returning a string with the names of capability flags
// separated by "|". Examples of capability names are CLIENT_DEPRECATE_EOF and CLIENT_PROTOCOL_41.
func (c *Conn) CapabilityString() string {
var caps []string
capability := c.capability
Expand Down
26 changes: 26 additions & 0 deletions client/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package client_test

import (
"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
)

var (
conn *client.Conn
)

func ExampleConn_ExecuteMultiple() {
queries := "SELECT 1; SELECT NOW();"
conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) {
// Use the result as you want
})
}

func ExampleConn_ExecuteSelectStreaming() {
var result mysql.Result
conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error {
// Use the row as you want.
// You must not save FieldValue.AsString() value after this callback is done. Copy it if you need.
return nil
}, nil)
}

0 comments on commit 8662d59

Please sign in to comment.