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) Commit() error
- 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) Rollback() 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 ¶
MapToSlice map query and struct as sql and args
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) BeginTx ¶
BeginTx begin a transaction with option
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext exec query with args
func (*DB) ExecMap ¶
ExecMap exec query with map
func (*DB) ExecMapContext ¶
ExecMapContext exec map with context.ContextHook insert into (name) values (?) insert into (name) values (?name)
func (*DB) ExecStruct ¶
ExecStruct exec query with struct
func (*DB) ExecStructContext ¶
func (db *DB) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)
ExecStructContext exec query with map
func (*DB) NeedLogSQL ¶
NeedLogSQL returns true if need to log SQL
func (*DB) Prepare ¶
Prepare creates a prepare statement
func (*DB) PrepareContext ¶
PrepareContext creates a prepare statement
func (*DB) Query ¶
Query overwrites sql.DB.Query
func (*DB) QueryContext ¶
QueryContext overwrites sql.DB.QueryContext
func (*DB) QueryMap ¶
QueryMap executes query with parameters via map
func (*DB) QueryMapContext ¶
QueryMapContext executes query with parameters via map and context
func (*DB) QueryRow ¶
QueryRow query row with args
func (*DB) QueryRowContext ¶
QueryRowContext query row with args
func (*DB) QueryRowMap ¶
QueryRowMap query row with map
func (*DB) QueryRowMapContext ¶
QueryRowMapContext query row with map
func (*DB) QueryRowStruct ¶
QueryRowStruct query row with struct
func (*DB) QueryRowStructContext ¶
QueryRowStructContext query row with struct
func (*DB) QueryStruct ¶
QueryStruct query rows with struct
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 NullTime ¶
NullTime defines a customize type NullTime
func (*NullTime) Scan ¶
Scan implements driver.Valuer
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
}
Row reprents a row of a tab
func (*Row) Columns ¶
Columns returns all columns of the row
func (*Row) Scan ¶
Scan retrieves all row column values
func (*Row) ScanMap ¶
ScanMap scan data to a map's pointer
func (*Row) ScanSlice ¶
ScanSlice scan data to a slice's pointer, slice's length should equal to columns' number
func (*Row) ScanStructByIndex ¶
ScanStructByIndex retrieves all row column values into a struct
func (*Row) ScanStructByName ¶
ScanStructByName retrieves all row column values into a struct
type Rows ¶
Rows represents rows of table
func (*Rows) ScanMap ¶
ScanMap scan data to a map's pointer
func (*Rows) ScanSlice ¶
ScanSlice scan data to a slice's pointer, slice's length should equal to columns' number
func (*Rows) ScanStructByIndex ¶
ScanStructByIndex scan data to a struct's pointer according field index
func (*Rows) ScanStructByName ¶
ScanStructByName scan data to a struct's pointer according field name
type Stmt ¶
Stmt reprents a stmt objects
func (*Stmt) ExecContext ¶
ExecContext with args
func (*Stmt) ExecMap ¶
ExecMap executes with map
func (*Stmt) ExecMapContext ¶
ExecMapContext execute with map
func (*Stmt) ExecStruct ¶
ExecStruct executes with struct
func (*Stmt) ExecStructContext ¶
ExecStructContext executes with struct
func (*Stmt) QueryContext ¶
QueryContext query with args
func (*Stmt) QueryMap ¶
QueryMap query with map
func (*Stmt) QueryMapContext ¶
QueryMapContext query with map
func (*Stmt) QueryRow ¶
QueryRow query row with args
func (*Stmt) QueryRowContext ¶
QueryRowContext query row with args
func (*Stmt) QueryRowMap ¶
QueryRowMap query row with map
func (*Stmt) QueryRowMapContext ¶
QueryRowMapContext query row with map
func (*Stmt) QueryRowStruct ¶
QueryRowStruct query row with struct
func (*Stmt) QueryRowStructContext ¶
QueryRowStructContext query row with struct
func (*Stmt) QueryStruct ¶
QueryStruct query with struct
type Tx ¶
Tx represents a transaction
func (*Tx) ExecContext ¶
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query with args
func (*Tx) ExecMap ¶
ExecMap executes query with args in a map
func (*Tx) ExecMapContext ¶
ExecMapContext executes query with args in a map
func (*Tx) ExecStruct ¶
ExecStruct executes query with args in a struct
func (*Tx) ExecStructContext ¶
func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error)
ExecStructContext executes query with args in a struct
func (*Tx) PrepareContext ¶
PrepareContext prepare the query
func (*Tx) Query ¶
Query query with args
func (*Tx) QueryContext ¶
QueryContext query with args
func (*Tx) QueryMap ¶
QueryMap query with args in a map
func (*Tx) QueryMapContext ¶
QueryMapContext query with args in a map
func (*Tx) QueryRow ¶
QueryRow query one row with args
func (*Tx) QueryRowContext ¶
QueryRowContext query one row with args
func (*Tx) QueryRowMap ¶
QueryRowMap query one row with args in a map
func (*Tx) QueryRowMapContext ¶
QueryRowMapContext query one row with args in a map
func (*Tx) QueryRowStruct ¶
QueryRowStruct query one row with args in struct
func (*Tx) QueryRowStructContext ¶
QueryRowStructContext query one row with args in struct
func (*Tx) QueryStruct ¶
QueryStruct query with args in struct
func (*Tx) QueryStructContext ¶
QueryStructContext query with args in struct