scan

package
v0.0.0-...-6945674 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOneRow = fmt.Errorf("sql/scan: expect exactly one row in result set")

ErrOneRow is returned by Row scan when the query returns more than one row

Functions

func Args

func Args(src []interface{}, columns ...string) ([]interface{}, error)

Args returns the arguments

func IsEmpty

func IsEmpty(src interface{}) bool

IsEmpty returns true if the value is empty

func IsNil

func IsNil(src interface{}) bool

IsNil returns true if the value is nil

func NamedQuery

func NamedQuery(query string) (string, []string)

NamedQuery returns the query renamed

func Row

func Row(scanner Scanner, src interface{}) error

Row scans one row to the given value. It fails if the rows holds more than 1 row.

func Rows

func Rows(scanner Scanner, src interface{}) error

Rows scans the given ColumnScanner (basically, sql.Row or sql.Rows) into the given slice.

func Values

func Values(src interface{}, columns ...string) ([]interface{}, error)

Values scans a struct and returns the values associated with the columns provided. Only simple value types are supported (i.e. Bool, Ints, Uints, Floats, Interface, String, NamedArg)

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator allocates values

func NewAllocator

func NewAllocator(target reflect.Type, columns []string) (*Allocator, error)

NewAllocator returns allocator for the given reflect.Type.

func NewAllocatorPrimitive

func NewAllocatorPrimitive(typ reflect.Type) *Allocator

NewAllocatorPrimitive allocates primitive type

func NewAllocatorPtr

func NewAllocatorPtr(target reflect.Type, columns []string) (*Allocator, error)

NewAllocatorPtr wraps the underlying type with rowScan.

func NewAllocatorStruct

func NewAllocatorStruct(target reflect.Type, columns []string) (*Allocator, error)

NewAllocatorStruct returns the a configuration for scanning an sql.Row into a struct.

func (*Allocator) Allocate

func (r *Allocator) Allocate() []interface{}

Allocate allocates values

func (*Allocator) Create

func (r *Allocator) Create(values []interface{}) reflect.Value

Create sets the given values

func (*Allocator) Set

func (r *Allocator) Set(value, next reflect.Value, columns []string)

Set sets the values

type Column

type Column struct {
	Name    string
	Options map[string]string
}

Column information

func Columns

func Columns(src interface{}, names ...string) ([]*Column, error)

Columns returns the columns for given opts

func (*Column) HasOption

func (c *Column) HasOption(name string) bool

HasOption return true if the column has option

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator iterates over a struct fields

func IteratorOf

func IteratorOf(src interface{}) *Iterator

IteratorOf creates a new iterator

func (*Iterator) Column

func (iter *Iterator) Column() *Column

Column returns the column

func (*Iterator) Next

func (iter *Iterator) Next() bool

Next progress

func (*Iterator) Value

func (iter *Iterator) Value() reflect.Value

Value returns the underlying value

type Readable

type Readable interface {
	Scan(interface{}) error
}

Readable provides a scannable interface

type Scanner

type Scanner interface {
	Next() bool
	Scan(...interface{}) error
	Columns() ([]string, error)
}

Scanner is the interface that wraps the three sql.Rows methods used for scanning.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL