values

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package values converts values between Go and SQLite, of SQLite's five types: integers, floats, text, blobs and NULL. An implementation, such as package ncruces, adapts where SQLite gives values, such as a row's columns, to Value, and where it takes them, such as a statement's arguments, to Setter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(v Value) any

Any returns the value as an int64, a float64, a string, a []byte, or nil

func Duration

func Duration(v Value) (time.Duration, error)

Duration returns the value's duration: an integer, of nanoseconds, which Set writes, a float, of seconds, which SQLite's date and time arithmetic returns, such as (julianday(b) - julianday(a)) * 86400, or text, of Go's format, such as 1h30m, or of nanoseconds

func Scan

func Scan(v Value, dest any) error

Scan scans a value which SQLite gives into a pointer, the first of these which it points to:

  • a sql.Scanner, such as a uuid.UUID, scans Any of the value
  • an any is Any of the value
  • a pointer is nil when it's NULL, or else points to the value
  • NULL is nil, for a slice or a map, the zero time, for a time.Time, and otherwise an error
  • a time.Time, as Time reads it, or a time.Duration, as Duration does
  • an array of bytes of a blob's length, such as the standard library's uuid.UUID, of the blob, unless it's an encoding.BinaryUnmarshaler
  • an encoding.TextUnmarshaler, of text, or an encoding.BinaryUnmarshaler, of a blob, or whichever it is, when it isn't both
  • a json.Unmarshaler, of its JSON
  • a bool, an integer, a float, or a string, of named types too, which a number, or text which is one, fits, without overflowing
  • a []byte, or an array of bytes, such as a [16]byte, of its length
  • a slice, an array, a map or a struct, of its JSON

func Set

func Set(s Setter, value any) error

Set sets a Go value where SQLite takes it, the first of these which it is:

  • nil, or a nil pointer, is NULL
  • a driver.Valuer is its value, such as a uuid.UUID's text
  • a time.Time is text, of RFC 3339, with nanoseconds, or NULL when it's zero
  • a time.Duration is an integer, of nanoseconds
  • a []byte is a blob
  • an encoding.TextMarshaler is its text, such as a netip.Addr's, or the standard library's uuid.UUID's, rather than its binary, when it's both, so it's compared and read as text
  • an encoding.BinaryMarshaler is a blob
  • a json.Marshaler is its JSON, as text
  • a bool is 0 or 1, an integer, which is no larger than an int64, is an integer, a float is a float, and a string is text, of named types too
  • a pointer is of its value
  • an array of bytes, such as a [16]byte, is a blob
  • a slice, an array, a map or a struct is its JSON, as text, such as ["a","b"], which SQLite's json functions read, such as json_each

func Time

func Time(v Value) (time.Time, error)

Time returns the value's time, as SQLite's date and time functions read them: text, of RFC 3339, or of YYYY-MM-DD HH:MM:SS, with optional fractions of a second and time zone, which is otherwise UTC, an integer, of seconds since the Unix epoch, or a float, of a Julian day

Types

type Setter

type Setter interface {
	SetNull() error
	SetInt64(int64) error
	SetFloat(float64) error
	SetText(string) error
	SetBlob([]byte) error
}

Setter is where SQLite takes a value, such as a statement's argument, or a function's result

type Type

type Type int

Type is one of SQLite's types of value

const (
	Null Type = iota
	Integer
	Float
	Text
	Blob
)

func (Type) String

func (t Type) String() string

type Value

type Value interface {
	Type() Type
	Int64() int64
	Float() float64
	Text() string
	Blob() []byte
}

Value is a value which SQLite gives, such as a row's column, or a function's argument. Its methods convert it, as SQLite does, such as an integer to text.

Jump to

Keyboard shortcuts

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