Help us shape the future of Go! Take the 2026 Go Developer Survey

scanner

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 12 Imported by: 0

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

func Scan

func Scan(ctx context.Context, rows *sql.Rows, v any) (err error)

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

func ScanIterFor(v any) (ScanIter, error)

type ScanIterT

type ScanIterT[T any] interface {
	New() T
	Next(T) error
}

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

type WithColumnReceivers interface {
	ColumnReceivers() map[string]any
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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