mysql

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSelectLimit = 200
)

Variables

View Source
var (
	ErrNotFound           = dbr.ErrNotFound
	ErrNotSupported       = dbr.ErrNotSupported
	ErrTableNotSpecified  = dbr.ErrTableNotSpecified
	ErrColumnNotSpecified = dbr.ErrColumnNotSpecified
	ErrInvalidPointer     = dbr.ErrInvalidPointer
	ErrPlaceholderCount   = dbr.ErrPlaceholderCount
	ErrInvalidSliceLength = dbr.ErrInvalidSliceLength
	ErrCantConvertToTime  = dbr.ErrCantConvertToTime
	ErrInvalidTimestring  = dbr.ErrInvalidTimestring
)

package errors

Functions

func And

func And(cond ...dbr.Builder) dbr.Builder

And creates AND from a list of conditions

func Eq

func Eq(column string, value interface{}) dbr.Builder

Eq is `=`. When value is nil, it will be translated to `IS NULL`. When value is a slice, it will be translated to `IN`. Otherwise it will be translated to `=`.

func GetLimit

func GetLimit(n uint64) uint64

func GetOffset

func GetOffset(n uint64) uint64

func Gt

func Gt(column string, value interface{}) dbr.Builder

Gt is `>`.

func Gte

func Gte(column string, value interface{}) dbr.Builder

Gte is '>='.

func Like

func Like(column string, value string) dbr.Builder

func Lt

func Lt(column string, value interface{}) dbr.Builder

Lt is '<'.

func Lte

func Lte(column string, value interface{}) dbr.Builder

Lte is `<=`.

func Neq

func Neq(column string, value interface{}) dbr.Builder

Neq is `!=`. When value is nil, it will be translated to `IS NOT NULL`. When value is a slice, it will be translated to `NOT IN`. Otherwise it will be translated to `!=`.

func Or

func Or(cond ...dbr.Builder) dbr.Builder

Or creates OR from a list of conditions

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewMySQLClient

func NewMySQLClient(options *Options, stopCh <-chan struct{}) (*Client, error)

func NewMySQLClientOrDie

func NewMySQLClientOrDie(options *Options, stopCh <-chan struct{}) *Client

func (*Client) Database

func (m *Client) Database() *Database

type Database

type Database struct {
	*dbr.Session
	InsertHook InsertHook
	UpdateHook UpdateHook
	DeleteHook DeleteHook
}

func (*Database) DeleteFrom

func (db *Database) DeleteFrom(table string) *DeleteQuery

func (*Database) InsertInto

func (db *Database) InsertInto(table string) *InsertQuery

func (*Database) Select

func (db *Database) Select(columns ...string) *SelectQuery

func (*Database) SelectAll

func (db *Database) SelectAll(columns ...string) *SelectQuery

func (*Database) SelectBySql

func (db *Database) SelectBySql(query string, value ...interface{}) *SelectQuery

func (*Database) Update

func (db *Database) Update(table string) *UpdateQuery

type DeleteHook

type DeleteHook func(query *DeleteQuery)

type DeleteQuery

type DeleteQuery struct {
	*dbr.DeleteBuilder
	Hook DeleteHook
}

func (*DeleteQuery) Exec

func (b *DeleteQuery) Exec() (sql.Result, error)

func (*DeleteQuery) Limit

func (b *DeleteQuery) Limit(n uint64) *DeleteQuery

func (*DeleteQuery) Where

func (b *DeleteQuery) Where(query interface{}, value ...interface{}) *DeleteQuery

type EqCondition

type EqCondition struct {
	dbr.Builder
	Column string
	Value  interface{}
}

type EventReceiver

type EventReceiver struct{}

EventReceiver is a sentinel EventReceiver; use it if the caller doesn't supply one

func (*EventReceiver) Event

func (n *EventReceiver) Event(eventName string)

Event receives a simple notification when various events occur

func (*EventReceiver) EventErr

func (n *EventReceiver) EventErr(eventName string, err error) error

EventErr receives a notification of an error if one occurs

func (*EventReceiver) EventErrKv

func (n *EventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error

EventErrKv receives a notification of an error if one occurs along with optional key/value data

func (*EventReceiver) EventKv

func (n *EventReceiver) EventKv(eventName string, kvs map[string]string)

EventKv receives a notification when various events occur along with optional key/value data

func (*EventReceiver) Timing

func (n *EventReceiver) Timing(eventName string, nanoseconds int64)

Timing receives the time an event took to happen

func (*EventReceiver) TimingKv

func (n *EventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string)

TimingKv receives the time an event took to happen along with optional key/value data

type InsertHook

type InsertHook func(query *InsertQuery)

type InsertQuery

type InsertQuery struct {
	*dbr.InsertBuilder
	Hook InsertHook
}

func (*InsertQuery) Columns

func (b *InsertQuery) Columns(columns ...string) *InsertQuery

func (*InsertQuery) Exec

func (b *InsertQuery) Exec() (sql.Result, error)

func (*InsertQuery) Record

func (b *InsertQuery) Record(structValue interface{}) *InsertQuery

type Options

type Options struct {
	Host                  string        `json:"host,omitempty" yaml:"host" description:"MySQL service host address"`
	Username              string        `json:"username,omitempty" yaml:"username"`
	Password              string        `json:"-" yaml:"password"`
	MaxIdleConnections    int           `json:"maxIdleConnections,omitempty" yaml:"maxIdleConnections"`
	MaxOpenConnections    int           `json:"maxOpenConnections,omitempty" yaml:"maxOpenConnections"`
	MaxConnectionLifeTime time.Duration `json:"maxConnectionLifeTime,omitempty" yaml:"maxConnectionLifeTime"`
}

func NewMySQLOptions

func NewMySQLOptions() *Options

NewMySQLOptions create a `zero` value instance

func (*Options) AddFlags

func (m *Options) AddFlags(fs *pflag.FlagSet, c *Options)

func (*Options) ApplyTo

func (m *Options) ApplyTo(options *Options)

func (*Options) Validate

func (m *Options) Validate() []error

type SelectQuery

type SelectQuery struct {
	*dbr.SelectBuilder
	JoinCount int // for join filter
}

func (*SelectQuery) Count

func (b *SelectQuery) Count() (count uint32, err error)

func (*SelectQuery) Distinct

func (b *SelectQuery) Distinct() *SelectQuery

func (*SelectQuery) From

func (b *SelectQuery) From(table string) *SelectQuery

func (*SelectQuery) GroupBy

func (b *SelectQuery) GroupBy(col ...string) *SelectQuery

func (*SelectQuery) Join

func (b *SelectQuery) Join(table, on interface{}) *SelectQuery

func (*SelectQuery) JoinAs

func (b *SelectQuery) JoinAs(table string, alias string, on interface{}) *SelectQuery

func (*SelectQuery) Limit

func (b *SelectQuery) Limit(n uint64) *SelectQuery

func (*SelectQuery) Load

func (b *SelectQuery) Load(value interface{}) (int, error)

func (*SelectQuery) LoadOne

func (b *SelectQuery) LoadOne(value interface{}) error

func (*SelectQuery) Offset

func (b *SelectQuery) Offset(n uint64) *SelectQuery

func (*SelectQuery) OrderDir

func (b *SelectQuery) OrderDir(col string, isAsc bool) *SelectQuery

func (*SelectQuery) Where

func (b *SelectQuery) Where(query interface{}, value ...interface{}) *SelectQuery

type UpdateHook

type UpdateHook func(query *UpdateQuery)

type UpdateQuery

type UpdateQuery struct {
	*dbr.UpdateBuilder
	Hook UpdateHook
}

func (*UpdateQuery) Exec

func (b *UpdateQuery) Exec() (sql.Result, error)

func (*UpdateQuery) Limit

func (b *UpdateQuery) Limit(n uint64) *UpdateQuery

func (*UpdateQuery) Set

func (b *UpdateQuery) Set(column string, value interface{}) *UpdateQuery

func (*UpdateQuery) SetMap

func (b *UpdateQuery) SetMap(m map[string]interface{}) *UpdateQuery

func (*UpdateQuery) Where

func (b *UpdateQuery) Where(query interface{}, value ...interface{}) *UpdateQuery

type UpsertQuery

type UpsertQuery struct {
	*dbr.Session
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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