sql

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDB

func CreateDB(db *sql.DB, dbName string) error

CreateDB creates a database with the given name. Note 1: When the DataSourceName already contained a database name but it doesn't exist yet (error 1049 occurred during Ping()), the same error will occur when trying to create the database. So this method is only useful when the DataSourceName did NOT contain a database name. Note 2: Prepared statements cannot be used for creating and using databases, so you must make sure that dbName doesn't contain SQL injections.

Types

type Client

type Client struct {
	C          *sql.DB
	UpsertStmt *sql.Stmt
	GetStmt    *sql.Stmt
	DeleteStmt *sql.Stmt
	Codec      encoding.Codec
}

Client is a gokv.Store implementation for SQL databases.

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 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 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 key must not be "" and the value must not be nil.

Jump to

Keyboard shortcuts

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