mysql

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2019 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package mysql contains an implementation of the `gokv.Store` interface for MySQL.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	DataSourceName:     "root@/" + defaultDBname,
	TableName:          "Item",
	MaxOpenConnections: 100,
	Codec:              encoding.JSON,
}

DefaultOptions is an Options object with default values. DataSourceName: "root@/gokv", TableName: "Item", MaxOpenConnections: 100, Codec: encoding.JSON

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a gokv.Store implementation for MySQL.

func NewClient

func NewClient(options Options) (Client, error)

NewClient creates a new MySQL client.

You must call the Close() method on the client when you're done working with it.

func (Client) Close

func (c Client) Close() error

Close closes the client. It must be called to return all open connections to the connection pool and to release any open resources.

func (Client) Delete

func (c Client) Delete(k string) error

Delete deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The length of the key must not exceed 255 characters. The key must not be "".

func (Client) Get

func (c Client) Get(k string, v interface{}) (found bool, err error)

Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The length of the key must not exceed 255 characters. The key must not be "" and the pointer must not be nil.

func (Client) Set

func (c Client) Set(k string, v interface{}) error

Set stores the given value for the given key. Values are automatically marshalled to JSON or gob (depending on the configuration). The length of the key must not exceed 255 characters. The key must not be "" and the value must not be nil.

type Options

type Options struct {
	// Connection string.
	// Format: [username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN].
	// Full example: "username:password@protocol(address)/dbname?param=value".
	// Minimal example: "/dbname".
	// If you leave the dbname out of the connection string,
	// an attempt will be made to create a database named "gokv".
	// If you passed a name of a database that doesn't exist yet,
	// an attempt will be made to create it.
	// If the user doesn't have the permission to create databases, an error is returned.
	// Optional ("root@/gokv" by default, which will connect to "127.0.0.1:3306"
	// and requires the server to be configured with MYSQL_ALLOW_EMPTY_PASSWORD=true,
	// which should only be done in local test environments, if at all).
	DataSourceName string
	// Name of the table in which the key-value pairs are stored.
	// Optional ("Item" by default).
	TableName string
	// Limits the number of open connections to the MySQL server.
	// -1 for no limit. 0 will lead to the default value (100) being set.
	// Optional (100 by default).
	MaxOpenConnections int
	// Encoding format.
	// Optional (encoding.JSON by default).
	Codec encoding.Codec
}

Options are the options for the MySQL client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL