mysql

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 19 Imported by: 0

README

MySQL adapter for upper.io/db

See the full docs, acknowledgements and examples at https://upper.io/db.v3/mysql

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

View Source
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

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(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.

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.

Jump to

Keyboard shortcuts

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