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 Duration ¶
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 ¶
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 ¶
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
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