Documentation ¶
Index ¶
- Variables
- func MapToSlice(query string, mp interface{}) (string, []interface{}, error)
- func StructToSlice(query string, st interface{}) (string, []interface{}, error)
- type DB
- func (db *DB) AddHook(h ...contexts.Hook)
- func (db *DB) Begin() (*Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecMap(query string, mp interface{}) (sql.Result, error)
- func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error)
- func (db *DB) ExecStruct(query string, st interface{}) (sql.Result, error)
- func (db *DB) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)
- func (db *DB) NeedLogSQL(ctx context.Context) bool
- func (db *DB) Prepare(query string) (*Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (db *DB) Query(query string, args ...interface{}) (*Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error)
- func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error)
- func (db *DB) QueryRow(query string, args ...interface{}) *Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (db *DB) QueryRowMap(query string, mp interface{}) *Row
- func (db *DB) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row
- func (db *DB) QueryRowStruct(query string, st interface{}) *Row
- func (db *DB) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row
- func (db *DB) QueryStruct(query string, st interface{}) (*Rows, error)
- func (db *DB) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error)
- type EmptyScanner
- type Executer
- type NullTime
- type QueryExecuter
- type Queryer
- type Row
- func (row *Row) Columns() ([]string, error)
- func (row *Row) Scan(dest ...interface{}) error
- func (row *Row) ScanMap(dest interface{}) error
- func (row *Row) ScanSlice(dest interface{}) error
- func (row *Row) ScanStructByIndex(dest interface{}) error
- func (row *Row) ScanStructByName(dest interface{}) error
- func (row *Row) ToMapString() (map[string]string, error)
- type Rows
- type Stmt
- func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)
- func (s *Stmt) ExecMap(mp interface{}) (sql.Result, error)
- func (s *Stmt) ExecMapContext(ctx context.Context, mp interface{}) (sql.Result, error)
- func (s *Stmt) ExecStruct(st interface{}) (sql.Result, error)
- func (s *Stmt) ExecStructContext(ctx context.Context, st interface{}) (sql.Result, error)
- func (s *Stmt) Query(args ...interface{}) (*Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error)
- func (s *Stmt) QueryMap(mp interface{}) (*Rows, error)
- func (s *Stmt) QueryMapContext(ctx context.Context, mp interface{}) (*Rows, error)
- func (s *Stmt) QueryRow(args ...interface{}) *Row
- func (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row
- func (s *Stmt) QueryRowMap(mp interface{}) *Row
- func (s *Stmt) QueryRowMapContext(ctx context.Context, mp interface{}) *Row
- func (s *Stmt) QueryRowStruct(st interface{}) *Row
- func (s *Stmt) QueryRowStructContext(ctx context.Context, st interface{}) *Row
- func (s *Stmt) QueryStruct(st interface{}) (*Rows, error)
- func (s *Stmt) QueryStructContext(ctx context.Context, st interface{}) (*Rows, error)
- type Tx
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) ExecMap(query string, mp interface{}) (sql.Result, error)
- func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error)
- func (tx *Tx) ExecStruct(query string, st interface{}) (sql.Result, error)
- func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)
- func (tx *Tx) Prepare(query string) (*Stmt, error)
- func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (tx *Tx) QueryMap(query string, mp interface{}) (*Rows, error)
- func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error)
- func (tx *Tx) QueryRow(query string, args ...interface{}) *Row
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (tx *Tx) QueryRowMap(query string, mp interface{}) *Row
- func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row
- func (tx *Tx) QueryRowStruct(query string, st interface{}) *Row
- func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row
- func (tx *Tx) QueryStruct(query string, st interface{}) (*Rows, error)
- func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error)
- func (tx *Tx) Stmt(stmt *Stmt) *Stmt
- func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoMapPointer represents error when no map pointer ErrNoMapPointer = errors.New("mp should be a map's pointer") // ErrNoStructPointer represents error when no struct pointer ErrNoStructPointer = errors.New("mp should be a struct's pointer") )
var (
// DefaultCacheSize sets the default cache size
DefaultCacheSize = 200
)
Functions ¶
func MapToSlice ¶
func StructToSlice ¶
Types ¶
type DB ¶
type DB struct { *sql.DB Mapper names.Mapper Logger log.ContextLogger // contains filtered or unexported fields }
DB is a wrap of sql.DB with extra contents
func (*DB) ExecContext ¶
func (*DB) ExecMapContext ¶
ExecMapContext exec map with context.ContextHook insert into (name) values (?) insert into (name) values (?name)
func (*DB) ExecStructContext ¶
func (*DB) NeedLogSQL ¶
NeedLogSQL returns true if need to log SQL
func (*DB) PrepareContext ¶
func (*DB) QueryContext ¶
QueryContext overwrites sql.DB.QueryContext
func (*DB) QueryMapContext ¶
QueryMapContext executes query with parameters via map and context
func (*DB) QueryRowContext ¶
func (*DB) QueryRowMap ¶
func (*DB) QueryRowMapContext ¶
func (*DB) QueryRowStruct ¶
func (*DB) QueryRowStructContext ¶
type EmptyScanner ¶
type EmptyScanner struct { }
func (EmptyScanner) Scan ¶
func (EmptyScanner) Scan(src interface{}) error
type Executer ¶
type Executer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Executer represents an interface to execute a SQL
type QueryExecuter ¶
QueryExecuter combines the Queryer and Executer
type Queryer ¶
type Queryer interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
}
Queryer represents an interface to query a SQL to get data from database
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
func (*Row) ScanSlice ¶
scan data to a slice's pointer, slice's length should equal to columns' number
func (*Row) ScanStructByIndex ¶
func (*Row) ScanStructByName ¶
type Rows ¶
func (*Rows) ScanSlice ¶
scan data to a slice's pointer, slice's length should equal to columns' number
func (*Rows) ScanStructByIndex ¶
scan data to a struct's pointer according field index
func (*Rows) ScanStructByName ¶
scan data to a struct's pointer according field name
type Stmt ¶
Stmt reprents a stmt objects
func (*Stmt) ExecContext ¶
func (*Stmt) ExecMapContext ¶
func (*Stmt) ExecStructContext ¶
func (*Stmt) QueryContext ¶
func (*Stmt) QueryMapContext ¶
func (*Stmt) QueryRowContext ¶
func (*Stmt) QueryRowMap ¶
func (*Stmt) QueryRowMapContext ¶
func (*Stmt) QueryRowStruct ¶
func (*Stmt) QueryRowStructContext ¶
func (*Stmt) QueryStruct ¶
type Tx ¶
Tx represents a transaction