Documentation ¶
Index ¶
- Constants
- Variables
- func And(cond ...dbr.Builder) dbr.Builder
- func Eq(column string, value interface{}) dbr.Builder
- func GetColumnsFromStruct(s interface{}) []string
- func GetColumnsFromStructWithPrefix(prefix string, s interface{}) []string
- func GetLimit(n uint64) uint64
- func GetOffset(n uint64) uint64
- func Gt(column string, value interface{}) dbr.Builder
- func Gte(column string, value interface{}) dbr.Builder
- func Like(column string, value string) dbr.Builder
- func Lt(column string, value interface{}) dbr.Builder
- func Lte(column string, value interface{}) dbr.Builder
- func Neq(column string, value interface{}) dbr.Builder
- func Or(cond ...dbr.Builder) dbr.Builder
- func Prefix(column string, value string) dbr.Builder
- func WithPrefix(prefix, str string) string
- type Conn
- func (conn *Conn) DeleteFrom(table string) *DeleteQuery
- func (conn *Conn) InsertInto(table string) *InsertQuery
- func (conn *Conn) Select(columns ...string) *SelectQuery
- func (conn *Conn) SelectAll(columns ...string) *SelectQuery
- func (conn *Conn) SelectBySql(query string, value ...interface{}) *SelectQuery
- func (conn *Conn) Update(table string) *UpdateQuery
- type Database
- type DeleteHook
- type DeleteQuery
- type EqCondition
- type EventReceiver
- func (n *EventReceiver) Event(eventName string)
- func (n *EventReceiver) EventErr(eventName string, err error) error
- func (n *EventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error
- func (n *EventReceiver) EventKv(eventName string, kvs map[string]string)
- func (n *EventReceiver) Timing(eventName string, nanoseconds int64)
- func (n *EventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string)
- type InsertHook
- type InsertQuery
- type SelectQuery
- func (b *SelectQuery) Count() (count uint32, err error)
- func (b *SelectQuery) Distinct() *SelectQuery
- func (b *SelectQuery) From(table string) *SelectQuery
- func (b *SelectQuery) GroupBy(col ...string) *SelectQuery
- func (b *SelectQuery) Join(table, on interface{}) *SelectQuery
- func (b *SelectQuery) JoinAs(table string, alias string, on interface{}) *SelectQuery
- func (b *SelectQuery) Limit(n uint64) *SelectQuery
- func (b *SelectQuery) Load(value interface{}) (int, error)
- func (b *SelectQuery) LoadOne(value interface{}) error
- func (b *SelectQuery) Offset(n uint64) *SelectQuery
- func (b *SelectQuery) OrderDir(col string, isAsc bool) *SelectQuery
- func (b *SelectQuery) Where(query interface{}, value ...interface{}) *SelectQuery
- type UpdateHook
- type UpdateQuery
- func (b *UpdateQuery) Exec() (sql.Result, error)
- func (b *UpdateQuery) Limit(n uint64) *UpdateQuery
- func (b *UpdateQuery) Set(column string, value interface{}) *UpdateQuery
- func (b *UpdateQuery) SetMap(m map[string]interface{}) *UpdateQuery
- func (b *UpdateQuery) Where(query interface{}, value ...interface{}) *UpdateQuery
Constants ¶
const (
DefaultSelectLimit = 200
)
Variables ¶
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 Eq ¶
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 GetColumnsFromStruct ¶ added in v0.2.2
func GetColumnsFromStruct(s interface{}) []string
func GetColumnsFromStructWithPrefix ¶ added in v0.2.2
func Neq ¶
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 WithPrefix ¶ added in v0.2.2
Types ¶
type Conn ¶ added in v0.2.0
type Conn struct { *dbr.Session InsertHook InsertHook UpdateHook UpdateHook DeleteHook DeleteHook // contains filtered or unexported fields }
func (*Conn) DeleteFrom ¶ added in v0.2.0
func (conn *Conn) DeleteFrom(table string) *DeleteQuery
func (*Conn) InsertInto ¶ added in v0.2.0
func (conn *Conn) InsertInto(table string) *InsertQuery
func (*Conn) Select ¶ added in v0.2.0
func (conn *Conn) Select(columns ...string) *SelectQuery
func (*Conn) SelectAll ¶ added in v0.2.0
func (conn *Conn) SelectAll(columns ...string) *SelectQuery
func (*Conn) SelectBySql ¶ added in v0.2.0
func (conn *Conn) SelectBySql(query string, value ...interface{}) *SelectQuery
func (*Conn) Update ¶ added in v0.2.0
func (conn *Conn) Update(table string) *UpdateQuery
type Database ¶
type Database struct {
Conn *dbr.Connection
}
func OpenDatabase ¶
func OpenDatabase(cfg config.MysqlConfig) (*Database, error)
type DeleteHook ¶ added in v0.1.7
type DeleteHook func(query *DeleteQuery)
type DeleteQuery ¶
type DeleteQuery struct { *dbr.DeleteBuilder Hook DeleteHook // contains filtered or unexported fields }
func (*DeleteQuery) Limit ¶
func (b *DeleteQuery) Limit(n uint64) *DeleteQuery
func (*DeleteQuery) Where ¶
func (b *DeleteQuery) Where(query interface{}, value ...interface{}) *DeleteQuery
type EqCondition ¶ added in v0.1.7
type EventReceiver ¶
type EventReceiver struct {
// contains filtered or unexported fields
}
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 ¶
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
type InsertHook ¶ added in v0.1.7
type InsertHook func(query *InsertQuery)
type InsertQuery ¶
type InsertQuery struct { *dbr.InsertBuilder Hook InsertHook // contains filtered or unexported fields }
func (*InsertQuery) Columns ¶
func (b *InsertQuery) Columns(columns ...string) *InsertQuery
func (*InsertQuery) Record ¶
func (b *InsertQuery) Record(structValue interface{}) *InsertQuery
type SelectQuery ¶
type SelectQuery struct { *dbr.SelectBuilder JoinCount int // for join filter // contains filtered or unexported fields }
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 ¶ added in v0.1.7
type UpdateHook func(query *UpdateQuery)
type UpdateQuery ¶
type UpdateQuery struct { *dbr.UpdateBuilder Hook UpdateHook // contains filtered or unexported fields }
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