Documentation ¶
Overview ¶
Package mysql wraps the github.com/go-sql-driver/mysql MySQL driver. See https://upper.io/db.v3/mysql for documentation, particularities and usage examples.
Index ¶
- Constants
- func DecodeJSON(dst interface{}, src interface{}) error
- func EncodeJSON(i interface{}) (driver.Value, error)
- func JSONValue(i interface{}) (driver.Value, error)
- func New(sess *sql.DB) (sqlbuilder.Database, error)
- func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)
- func Open(settings db.ConnectionURL) (sqlbuilder.Database, error)
- func ScanJSON(dst interface{}, src interface{}) error
- type ConnectionURL
- type JSON
- type JSONArray
- type JSONConverter
- type JSONMap
Constants ¶
const Adapter = sqlDriver
Adapter is the public name of the adapter.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func DecodeJSON(dst interface{}, src interface{}) error
DecodeJSON is deprecated and going to be removed. Use JSONValue instead.
func EncodeJSON ¶
EncodeJSON is deprecated and going to be removed. Use ScanJSON instead.
func JSONValue ¶
JSONValue takes an interface and provides a driver.Value that can be stored as a JSON column.
func New ¶
func New(sess *sql.DB) (sqlbuilder.Database, error)
New wraps the given *sql.DB session and creates a new db session.
func NewTx ¶
func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)
NewTx wraps a regular *sql.Tx transaction and returns a new upper-db transaction backed by it.
func Open ¶
func Open(settings db.ConnectionURL) (sqlbuilder.Database, error)
Open stablishes a new connection with the SQL server.
Types ¶
type ConnectionURL ¶
type ConnectionURL struct { User string Password string Database string Host string Socket string Options map[string]string }
ConnectionURL implements a MySQL connection struct.
func ParseURL ¶
func ParseURL(s string) (conn ConnectionURL, err error)
ParseURL parses s into a ConnectionURL struct.
func (ConnectionURL) String ¶
func (c ConnectionURL) String() (s string)
type JSON ¶
type JSON struct {
V interface{}
}
JSON represents a MySQL's JSON value: https://www.mysql.org/docs/9.6/static/datatype-json.html. JSON satisfies sqlbuilder.ScannerValuer.
func (JSON) MarshalJSON ¶
MarshalJSON encodes the wrapper value as JSON.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON decodes the given JSON into the wrapped value.
type JSONArray ¶
type JSONArray []interface{}
JSONArray represents an array of any type (`[]interface{}`) that is compatible with MySQL's JSON type. JSONArray satisfies sqlbuilder.ScannerValuer.
type JSONConverter ¶
type JSONConverter struct { }
JSONConverter provides a helper method WrapValue that satisfies sqlbuilder.ValueWrapper, can be used to encode Go structs into JSON MySQL types and vice versa.
Example:
type MyCustomStruct struct { ID int64 `db:"id" json:"id"` Name string `db:"name" json:"name"` ... mysql.JSONConverter }
func (*JSONConverter) WrapValue ¶
func (obj *JSONConverter) WrapValue(src interface{}) interface{}
WrapValue satisfies sqlbuilder.ValueWrapper