scan

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MPL-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ready

func Ready[T any, U **T](fieldAddr U)

Ready is a helper to prevent nil pointer dereferences when scanning values into sub-fields. The address of the field should be passed in.

func WithDefault

func WithDefault[T any, U *T](fieldAddr U, default_ T) driver.Value

WithDefault is a helper to set a default value, used when Scan methods attempt to scan NULL into a non-pointer field. This is particularly useful with proto3.

The returned value should be used as the argument to Scan.

Types

type Slice

type Slice[T driver.Valuer, U ~[]T] struct {
	// contains filtered or unexported fields
}

Slice implements driver.Valuer and sql.Scanner for a slice of values that also implement driver.Valuer and sql.Scanner.

Due to the oddities of sql.Scanner usually being on the pointer receiver while driver.Valuer is usually on the value receiver, we need to check for the sql.Scanner implementation at runtime.

func NewSlice

func NewSlice[T driver.Valuer, U ~[]T](addr *U) Slice[T, U]

NewSlice creates a new Slice for addr, which should be a pointer to a slice whose member type implements driver.Valuer and sql.Scanner.

func (Slice[T, U]) Scan

func (s Slice[T, U]) Scan(v any) error

Scan scans an SQL array into the address that s wraps. Due to the oddities around sql.Scanner usually being implemented on the pointer receiver (and `rows.Scan` being passed the addresses of variables), Scan needs to check (*T) to ensure it implements sql.Scanner at runtime.

func (Slice[T, U]) Value

func (s Slice[T, U]) Value() (driver.Value, error)

Value returns a database array value from all of the slice's indexes.

Jump to

Keyboard shortcuts

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