Skip to content

mysql

import "github.com/go-rel/mysql"

Overview

Package mysql wraps mysql driver as an adapter for REL.

Usage:

// open mysql connection.
// note: `clientFoundRows=true` is required for update and delete to works correctly.
adapter, err := mysql.Open("root@(127.0.0.1:3306)/rel_test?clientFoundRows=true&charset=utf8&parseTime=True&loc=Local")
if err != nil {
    panic(err)
}
defer adapter.Close()

// initialize REL's repo.
repo := rel.New(adapter)

Constants

const Name string = "mysql"
Name of database type this adapter implements.

func MustOpen

func MustOpen(dsn string) rel.Adapter
MustOpen mysql connection using dsn.

func New

func New(database *db.DB) rel.Adapter
New mysql adapter using existing connection. Existing connection needs to be created with clientFoundRows=true options for update and delete to works correctly.

func Open

func Open(dsn string) (rel.Adapter, error)
Open mysql connection using dsn.

type MySQL

type MySQL struct {
    sql.SQL
}
MySQL adapter.

func (MySQL) Name

func (MySQL) Name() string
Name of database adapter.

type Quote

type Quote struct{}
Quote MySQL identifiers and literals.

func (Quote) ID

func (q Quote) ID(name string) string

func (Quote) Value

func (q Quote) Value(v interface{}) string

type ValueConvert

type ValueConvert struct{}
ValueConvert converts values to MySQL literals.

func (ValueConvert) ConvertValue

func (c ValueConvert) ConvertValue(v interface{}) (driver.Value, error)

Last update: 2024-12-19