Versions in this module Expand all Collapse all v0 v0.0.0 Jun 18, 2020 Changes in this version + const CommonInsert + const IgnoreInsert + const ReplaceInsert + func CommitOrRollback(tx Tx) error + func LogHook(ctx context.Context, ev *Event) + func Scan(rs Rows, target interface{}) error + func SetTagName(name string) + func Struct2Assign(raw interface{}) map[string]interface + func Struct2AssignList(raws ...interface{}) []map[string]interface + func Struct2Where(raw interface{}) map[string]interface + type Conn interface + DB func() DB + RawConn func() *sql.Conn + type DB interface + Name func() string + Raw func() *sql.DB + func MockDb() (DB, sqlmock.Sqlmock, error) + type DBConfig struct + ConnMaxLifeTime time.Duration + MaxIdleConns int + MaxOpenConns int + type DeleteBuilder struct + Table string + Wheres map[string]interface{} + func NewDeleteBuilder(table string, wheres map[string]interface{}) *DeleteBuilder + func (d *DeleteBuilder) Compile() (sql string, args []interface{}, err error) + func (d *DeleteBuilder) From(table string) *DeleteBuilder + func (d *DeleteBuilder) Where(wheres map[string]interface{}) *DeleteBuilder + type Event struct + Args []interface{} + Cost time.Duration + DB DB + Err error + Log Logger + Sql string + Type EventType + func NewEvent(db DB, typ EventType, cost time.Duration, sql string, args []interface{}, ...) *Event + type EventType int8 + const EventExec + const EventPing + const EventQuery + const EventQueryRow + const EventStmt + const EventStmtClose + const EventTxBegin + const EventTxCommit + const EventTxRollback + type Handler func(ctx context.Context, ev *Event) + type Hooks struct + Handlers [9][]Handler + func NewLogHooks() *Hooks + func (hs *Hooks) AddHandler(he EventType, h Handler) + func (hs *Hooks) Append(hook *Hooks) + func (hs *Hooks) Empty(et EventType) bool + func (hs *Hooks) SetHandler(he EventType, h Handler) + func (hs *Hooks) Trigger(ctx context.Context, event *Event) + type InsertBuilder struct + Assigns []map[string]interface{} + Table string + func NewIgnoreInsertBuilder(table string, assigns []map[string]interface{}) *InsertBuilder + func NewInsertBuilder(table string, assigns []map[string]interface{}) *InsertBuilder + func NewReplaceInsertBuilder(table string, assigns []map[string]interface{}) *InsertBuilder + func (i *InsertBuilder) Compile() (sql string, args []interface{}, err error) + func (i *InsertBuilder) InsertIgnoreInto(table string) *InsertBuilder + func (i *InsertBuilder) InsertInto(table string) *InsertBuilder + func (i *InsertBuilder) ReplaceInto(table string) *InsertBuilder + func (i *InsertBuilder) Values(assigns []map[string]interface{}) *InsertBuilder + type Logger interface + Error func(...interface{}) + Errorf func(format string, args ...interface{}) + Info func(...interface{}) + Infof func(format string, args ...interface{}) + Warnf func(format string, args ...interface{}) + type MyDB struct + AccessLog Logger + Config *DBConfig + DBName string + DSN string + Hooks *Hooks + Protocol string + StatusLogger Logger + func (db *MyDB) AddHook(et EventType, h Handler) + func (db *MyDB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) + func (db *MyDB) Close() error + func (db *MyDB) Conn(ctx context.Context) (Conn, error) + func (db *MyDB) Driver() driver.Driver + func (db *MyDB) EnableLog(enable bool) + func (db *MyDB) ExecContext(ctx context.Context, query string, args ...interface{}) (rst sql.Result, err error) + func (db *MyDB) ExecContextWithBuilder(ctx context.Context, builder SqlBuilder) (sql.Result, error) + func (db *MyDB) Init() (err error) + func (db *MyDB) Name() string + func (db *MyDB) Ping(ctx context.Context) error + func (db *MyDB) PrepareContext(ctx context.Context, query string) (Stmt, error) + func (db *MyDB) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) + func (db *MyDB) QueryContextWithBuilder(ctx context.Context, builder SqlBuilder) (Rows, error) + func (db *MyDB) QueryContextWithBuilderStruct(ctx context.Context, builder SqlBuilder, dst interface{}) error + func (db *MyDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row + func (db *MyDB) QueryRowContextWithBuilder(ctx context.Context, builder SqlBuilder) Row + func (db *MyDB) QueryRowContextWithBuilderStruct(ctx context.Context, builder SqlBuilder, dst interface{}) error + func (db *MyDB) Raw() *sql.DB + func (db *MyDB) SetConnMaxLifetime(d time.Duration) + func (db *MyDB) SetHook(et EventType, h Handler) + func (db *MyDB) SetMaxIdleConns(n int) + func (db *MyDB) SetMaxOpenConns(n int) + func (db *MyDB) Start() error + func (db *MyDB) Stats() sql.DBStats + func (db *MyDB) Stop(os.Signal) + type QueryExecer interface + type Row interface + Raw func() *sql.Row + type Rows interface + Raw func() *sql.Rows + type SelectBuilder struct + SelectField []string + Table string + Wheres map[string]interface{} + func NewSelectBuilder(table string, wheres map[string]interface{}, selectField []string) *SelectBuilder + func (s *SelectBuilder) Compile() (sql string, args []interface{}, err error) + func (s *SelectBuilder) From(table string) *SelectBuilder + func (s *SelectBuilder) Select(selectFields []string) *SelectBuilder + func (s *SelectBuilder) Where(wheres map[string]interface{}) *SelectBuilder + type SqlBuilder interface + Compile func() (sql string, args []interface{}, err error) + type Stmt interface + Close func() error + Raw func() *sql.Stmt + type Tx interface + Raw func() *sql.Tx + type TxError struct + CommitErr error + RollError error + func (txError *TxError) Error() string + type UpdateBuilder struct + Assigns map[string]interface{} + Table string + Wheres map[string]interface{} + func NewUpdateBuilder(table string, wheres map[string]interface{}, assigns map[string]interface{}) *UpdateBuilder + func (u *UpdateBuilder) Assign(assign map[string]interface{}) *UpdateBuilder + func (u *UpdateBuilder) Compile() (sql string, args []interface{}, err error) + func (u *UpdateBuilder) From(table string) *UpdateBuilder + func (u *UpdateBuilder) Where(wheres map[string]interface{}) *UpdateBuilder