Documentation
¶
Index ¶
- func ContainsFold(a, b string) bool
- func FirstWord(s string) string
- func IfElse(ifCondition bool, ifValue, elseValue string) string
- func ImplSQLScanner(t reflect.Type) bool
- func ImplType(src, target reflect.Type) bool
- func IsQuerySQL(sql string) (string, bool)
- func LookupDriverName(driver driver.Driver) string
- type ExecResult
- type MapMapping
- type MapPreparer
- type Mapping
- type MiniDB
- type NullAny
- type Preparer
- type SQLExec
- type SQLRun
- type StructMapping
- type StructPreparer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsFold ¶
ContainsFold tell if a contains b in case-insensitively.
func ImplSQLScanner ¶
ImplSQLScanner tells t whether it implements sql.Scanner interface.
func IsQuerySQL ¶
IsQuerySQL tests a sql is a query or not.
func LookupDriverName ¶
LookupDriverName get driverName from the driver instance. The database/sql API doesn't provide a way to get the registry name for a driver from the driver type. from https://github.com/golang/go/issues/12600
Types ¶
type ExecResult ¶
type ExecResult struct { Error error CostTime time.Duration Headers []string Rows interface{} // [][]string or []YourStruct RowsCount int RowsAffected int64 LastInsertID int64 IsQuery bool }
ExecResult defines the result structure of sql execution.
func (ExecResult) StringRows ¶
func (r ExecResult) StringRows() [][]string
StringRows return the string rows when using MapPreparer.
type MapMapping ¶
type MapMapping struct {
// contains filtered or unexported fields
}
MapMapping maps the query rows to maps.
func (*MapMapping) RowsData ¶
func (m *MapMapping) RowsData() interface{}
RowsData returns the mapped rows data.
func (*MapMapping) Scan ¶
func (m *MapMapping) Scan(rowNum int) error
Scan scans the rows one by one.
type MapPreparer ¶
type MapPreparer struct { // NullReplace is the replacement of null values. NullReplace string }
MapPreparer prepares to scan query rows.
func NewMapPreparer ¶
func NewMapPreparer(nullReplace string) *MapPreparer
NewMapPreparer creates a new MapPreparer.
type MiniDB ¶
type MiniDB interface { // Exec executes update. Exec(query string, args ...interface{}) (sql.Result, error) // Query performs query. Query(query string, args ...interface{}) (*sql.Rows, error) }
MiniDB wraps Exec method.
type NullAny ¶
NullAny represents any that may be null. it implements the Scanner interface so it can be used as a scan destination.
func (*NullAny) Scan ¶
Scan assigns a value from a database driver.
The src value will be of one of the following types:
int64 float64 bool []byte string time.Time nil - for NULL values
An error should be returned if the value cannot be stored without loss of information.
Reference types such as []byte are only valid until the next call to Scan and should not be retained. Their underlying memory is owned by the driver. If retention is necessary, copy their values before the next call to Scan.
type Preparer ¶
type Preparer interface { // Prepare prepares to scan query rows. Prepare(rows *sql.Rows, columns []string) Mapping }
Preparer prepares to scan query rows.
type SQLExec ¶
type SQLExec struct {
MiniDB
}
SQLExec is used to execute only updates.
func NewSQLExec ¶
NewSQLExec creates a new SQLExec for only updates.
func (*SQLExec) DoUpdate ¶
func (s *SQLExec) DoUpdate(query string, vars ...interface{}) (result ExecResult)
DoUpdate does the update.
type SQLRun ¶
SQLRun is used to execute queries and updates.
func (*SQLRun) DoExec ¶
func (s *SQLRun) DoExec(query string, args ...interface{}) ExecResult
DoExec executes a SQL.
func (*SQLRun) DoQuery ¶
func (s *SQLRun) DoQuery(query string, args ...interface{}) (result ExecResult)
DoQuery does the query.
type StructMapping ¶
type StructMapping struct { *StructPreparer // contains filtered or unexported fields }
StructMapping is the structure for mapping row to a structure.
func (*StructMapping) RowsData ¶
func (s *StructMapping) RowsData() interface{}
RowsData returns the mapped rows data.
func (*StructMapping) Scan ¶
func (s *StructMapping) Scan(rowNum int) error
Scan scans the query result to fetch the rows one by one.
type StructPreparer ¶
StructPreparer is the the structure to create struct mapping.
func NewStructPreparer ¶
func NewStructPreparer(v interface{}) *StructPreparer
NewStructPreparer creates a new StructPreparer.