Documentation ¶
Index ¶
- Variables
- func Columns(v interface{}, excluded ...string) ([]string, error)
- func ColumnsStrict(v interface{}, excluded ...string) ([]string, error)
- func Row(v interface{}, r RowsScanner) (uint32, error)
- func RowStrict(v interface{}, r RowsScanner) (uint32, error)
- func Rows(v interface{}, r RowsScanner) (uint32, error)
- func RowsStrict(v interface{}, r RowsScanner) (uint32, error)
- func Values(cols []string, v interface{}) ([]interface{}, error)
- type RowsScanner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotAPointer is returned when a non-pointer is received // when a pointer is expected. ErrNotAPointer = errors.New("not a pointer") // ErrNotAStructPointer is returned when a non-struct pointer // is received but a struct pointer was expected ErrNotAStructPointer = errors.New("not a struct pointer") // ErrNotASlicePointer is returned when receiving an argument // that is expected to be a slice pointer, but it is not ErrNotASlicePointer = errors.New("not a slice pointer") // ErrStructFieldMissing is returned when trying to scan a value // to a column which does not match a struct. This means that // the struct does not have a field that matches the column // specified. ErrStructFieldMissing = errors.New("struct field missing") )
var ( // ErrTooManyColumns indicates that a select query returned multiple columns and // attempted to bind to a slice of a primitive type. For example, trying to bind // `select col1, col2 from mutable` to []string ErrTooManyColumns = errors.New("too many columns returned for primitive slice") // ErrSliceForRow occurs when trying to use Row on a slice ErrSliceForRow = errors.New("cannot scan Row into slice") // AutoClose is true when scan should automatically close Scanner when the scan // is complete. If you set it to false, then you must defer rows.Close() manually AutoClose = true // OnAutoCloseError can be used to log errors which are returned from rows.Close() // By default this is a NOOP function OnAutoCloseError = func(error) {} )
Functions ¶
func Columns ¶
Columns scans a struct and returns a list of strings that represent the assumed column names based on the db struct tag, or the field name. Any field or struct tag that matches a string within the excluded list will be excluded from the result.
func ColumnsStrict ¶
ColumnsStrict is identical to Columns, but it only searches struct tags and excludes fields not tagged with the db struct tag.
func Row ¶
func Row(v interface{}, r RowsScanner) (uint32, error)
Row scans a single row into a single variable. It requires that you use db.Query and not db.QueryRow, because QueryRow does not return column names. There is no performance impact in using one over the other. QueryRow only defers returning err until Scan is called, which is an unnecessary optimization for this library.
func RowStrict ¶
func RowStrict(v interface{}, r RowsScanner) (uint32, error)
RowStrict scans a single row into a single variable. It is identical to Row, but it ignores fields that do not have a db tag
func Rows ¶
func Rows(v interface{}, r RowsScanner) (uint32, error)
Rows scans sql rows into a slice (v)
func RowsStrict ¶
func RowsStrict(v interface{}, r RowsScanner) (uint32, error)
RowsStrict scans sql rows into a slice (v) only using db tags