db: github.com/upper/db/adapter/mysql Index | Files

package mysql

import "github.com/upper/db/adapter/mysql"

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

Package Files

collection.go connection.go custom_types.go database.go mysql.go template.go

Constants

const Adapter = `mysql`

Adapter is the public name of the adapter.

func DecodeJSON Uses

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

DecodeJSON is deprecated and going to be removed. Use JSONValue instead.

func EncodeJSON Uses

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

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

func JSONValue Uses

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 Uses

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

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

func NewTx Uses

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

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

func Open Uses

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 Uses

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

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

type ConnectionURL Uses

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 Uses

func ParseURL(s string) (conn ConnectionURL, err error)

ParseURL parses s into a ConnectionURL struct.

func (ConnectionURL) String Uses

func (c ConnectionURL) String() (s string)

type JSON Uses

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 Uses

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

MarshalJSON encodes the wrapper value as JSON.

func (*JSON) Scan Uses

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

Scan satisfies the sql.Scanner interface.

func (*JSON) UnmarshalJSON Uses

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

UnmarshalJSON decodes the given JSON into the wrapped value.

func (JSON) Value Uses

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

Value satisfies the driver.Valuer interface.

type JSONArray Uses

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 Uses

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

Scan satisfies the sql.Scanner interface.

func (JSONArray) Value Uses

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

Value satisfies the driver.Valuer interface.

type JSONConverter Uses

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 Uses

func (obj *JSONConverter) WrapValue(src interface{}) interface{}

WrapValue satisfies sqlbuilder.ValueWrapper

type JSONMap Uses

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 Uses

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

Scan satisfies the sql.Scanner interface.

func (JSONMap) Value Uses

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

Value satisfies the driver.Valuer interface.

Package mysql imports 16 packages (graph). Updated 2021-01-01. Refresh now. Tools for package owners.