Documentation
¶
Overview ¶
Package magiccol allows to scan sql rows into an arbitrary map
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDataType = errors.New("data type not valid for column")
ErrInvalidDataType columnd declared with a type incompatible with the actual value
var ErrNilRows = errors.New("nil *sql.Rows as argument")
ErrNilRows a nil Rows interface is provided
Functions ¶
This section is empty.
Types ¶
type ColumnType ¶ added in v0.2.0
type ColumnType interface {
Name() string
DatabaseTypeName() string
ScanType() reflect.Type
Nullable() (nullable bool, ok bool)
DecimalSize() (precision int64, scale int64, ok bool)
Length() (length int64, ok bool)
}
ColumnType is identical as defined in sql.ColumnType struct
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper translate sql types to golang types
func DefaultMapper ¶
func DefaultMapper() *Mapper
DefaultMapper provides a mapping for most common sql types type list reference used is: http://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#predefined-type
type Matcher ¶ added in v0.2.0
type Matcher func(ColumnType) (reflect.Type, bool)
Matcher return a type and true if column definition match on a negative match reflect.Type should be null but is not mandatory
func ColumnNameAs ¶ added in v0.2.0
ColumnNameAs match a column name
type Options ¶
type Options struct {
// Rows must be a valid sql.Rows object
Rows Rows
// Mapper can be nil, if so DefaultMapper is used
Mapper *Mapper
}
Options for Scanner
type Rows ¶ added in v0.1.2
type Rows interface {
ColumnTypes() ([]*sql.ColumnType, error)
Columns() ([]string, error)
Next() bool
Err() error
Scan(...any) error
}
Rows allow to mock sql.Rows object
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner read data from an sql.Rows object into a map
func NewScanner ¶
NewScanner create a new Scanner object, return an error if a nil Rows interface is provided or any error is returned by its
func (*Scanner) Scan ¶
Scan return true if there are rows in queue and false if there is no more rows or an error occurred. To distinguish between error or no more rows Err() method should be consulted