README

MySQL adapter for upper/db

Please read the full docs, acknowledgements and examples at https://upper.io/v4/adapter/mysql/.

Expand ▾ Collapse ▴

Documentation

Overview

Package mysql wraps the github.com/go-sql-driver/mysql MySQL driver. See https://github.com/upper/db/adapter/mysql for documentation, particularities and usage examples.

Index

Constants

const Adapter = `mysql`

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

func EncodeJSON(i interface{}) (driver.Value, error)

EncodeJSON is deprecated and going to be removed. Use ScanJSON instead.

func JSONValue

func JSONValue(i interface{}) (driver.Value, error)

JSONValue takes an interface and provides a driver.Value that can be stored as a JSON column.

func New

func New(sqlDB *sql.DB) (db.Session, error)

New creates a sqlbuilder.Sesion instance by wrapping a *sql.DB value.

func NewTx

func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)

NewTx creates a sqlbuilder.Tx instance by wrapping a *sql.Tx value.

func Open

func Open(connURL db.ConnectionURL) (db.Session, error)

Open establishes a connection to the database server and returns a db.Session instance (which is compatible with db.Session).

func ScanJSON

func ScanJSON(dst interface{}, src interface{}) error

ScanJSON decodes a JSON byte stream into the passed dst value.

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

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON encodes the wrapper value as JSON.

func (*JSON) Scan

func (j *JSON) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the given JSON into the wrapped value.

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

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.

func (*JSONArray) Scan

func (a *JSONArray) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (JSONArray) Value

func (a JSONArray) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

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

type JSONMap

type JSONMap map[string]interface{}

JSONMap represents a map of interfaces with string keys (`map[string]interface{}`) that is compatible with MySQL's JSON type. JSONMap satisfies sqlbuilder.ScannerValuer.

func (*JSONMap) Scan

func (m *JSONMap) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (JSONMap) Value

func (m JSONMap) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.