Standard library / database/sql

sql.Scanner

Receives database values through Scan. Handle supported source types, nil and conversion errors; copy borrowed bytes if retained. Expected stdout: 'Ada true\n'.

Formal Syntax & Structure

go syntaxgo
type Scanner interface {  Scan(src any) error}

Working Example

Example Snippetgo
package main
import (  "database/sql"  "fmt")
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}func main() {  var n sql.NullString  var s sql.Scanner = &n  check(s.Scan("Ada"))  fmt.Println(n.String, n.Valid)}
Go Reference