Standard library / database/sql

sql.NullInt16.Value()

Implements driver.Valuer, returning nil for an invalid wrapper and a converted driver value for a valid wrapper. Expected stdout: 'true\ntrue\nfalse\n'.

Formal Syntax & Structure

go syntaxgo
func (n NullInt16) Value() (driver.Value, error)

Return Value

(driver.Value, error)

Implements driver. Check returned errors where applicable.

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.NullInt16  check(n.Scan(int64(7)))  fmt.Println(n.Valid)  v := must(n.Value())  fmt.Println(v != nil)  check(n.Scan(nil))  fmt.Println(n.Valid)}
Go Reference