Documentation
¶
Overview ¶
Package scanner maps *sql.Rows into Go values for sqlx.
Public helpers such as github.com/xoctopus/sqlx/pkg/helper.Scan and QueryAndScan delegate here. Adaptor catalog loaders also use Scan to read information_schema rows into structs.
Scan ¶
err := scanner.Scan(ctx, rows, &user) // single row; NOTFOUND if empty err := scanner.Scan(ctx, rows, &users) // []T appends each row err := scanner.Scan(ctx, rows, &count) // scalar / sql.Scanner
Scan closes rows when finished. The destination must be a pointer (or a custom ScanIter). Empty rows with a single-value target return the package errors NOTFOUND code.
Destination shapes ¶
- struct pointer: match row columns to `db` fields (and table__column aliases from joins via frag.Alias); NULL columns are skipped via nullable.NullIgnoreScanner
- WithColumnReceivers: explicit column-name → scan target map
- sql.Scanner / scalar pointer: rows.Scan into that value
- slice pointer: one New/Next cycle per row (SliceScanIter)
- ScanIter: custom New + Next pipeline (ScanIterFor)
Unmatched columns are discarded (nullable.EmptyScanner).
nullable ¶
Subpackage nullable provides nullable.NullIgnoreScanner (nil src leaves the destination unchanged) and EmptyScanner for unused columns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ScanIter ¶
type ScanIter interface {
// New a ptr value for scanning
New() any
// Next for receive scanned value
Next(v any) error
}
func ScanIterFor ¶
type SingleScanIter ¶
type SingleScanIter struct {
// contains filtered or unexported fields
}
func (*SingleScanIter) MustHasRecord ¶
func (s *SingleScanIter) MustHasRecord() bool
func (*SingleScanIter) New ¶
func (s *SingleScanIter) New() any
func (*SingleScanIter) Next ¶
func (s *SingleScanIter) Next(v any) error
type SliceScanIter ¶
type SliceScanIter struct {
// contains filtered or unexported fields
}
func (*SliceScanIter) New ¶
func (s *SliceScanIter) New() any
func (*SliceScanIter) Next ¶
func (s *SliceScanIter) Next(v any) error
type WithColumnReceivers ¶
Click to show internal directories.
Click to hide internal directories.