Documentation ¶
Overview ¶
Package types provides implementation of some wrapper SQL types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Nullable ¶ added in v0.12.0
Nullable converts the given type (which should be a pointer ideally) into a nullable type. For that, it must be either a pointer of a basic Go type or a type that implements sql.Scanner itself. time.Time and time.Duration are also supported, even though they are none of the above. If the given types does not fall into any of the above categories, it will actually return a valid sql.Scanner that will fail only when the Scan is performed.
Types ¶
type ByteArray ¶ added in v1.2.20
type ByteArray []uint8
ByteArray represents a byte array `bytea`.
type Float32Array ¶
type Float32Array []float32
Float32Array represents a one-dimensional array of the PostgreSQL real type.
func (*Float32Array) Scan ¶
func (a *Float32Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type Int16Array ¶
type Int16Array []int16
Int16Array represents a one-dimensional array of the PostgreSQL integer type.
func (*Int16Array) Scan ¶
func (a *Int16Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type Int32Array ¶
type Int32Array []int32
Int32Array represents a one-dimensional array of the PostgreSQL integer type.
func (*Int32Array) Scan ¶
func (a *Int32Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type Int8Array ¶
type Int8Array []int8
Int8Array represents a one-dimensional array of the PostgreSQL integer type.
type IntArray ¶
type IntArray []int
IntArray represents a one-dimensional array of the PostgreSQL integer type.
type SQLType ¶
SQLType is the common interface a type has to fulfill to be considered a SQL type.
func Array ¶
Array returns an SQLType for the given array type with a specific size. Note that the actual implementation of this relies on reflection, so be cautious with its usage. The array is scanned using a slice of the same type, so the same restrictions as the `Slice` function of this package are applied.
func JSON ¶
func JSON(v interface{}) SQLType
JSON makes sure the given value is converted to and scanned from SQL as a JSON. Note that this uses the standard json.Unmarshal and json.Marshal and it relies on reflection. To speed up the encoding/decoding you can implement interfaces json.Marshaller and json.Unmarshaller for your type with, for example, ffjson.
func Slice ¶
func Slice(v interface{}) SQLType
Slice wraps a slice value so it can be scanned from and converted to PostgreSQL arrays. The following values can be used with this function:
- slices of all Go basic types
- slices of *url.URL and url.URL
- slices of types that implement sql.Scanner and driver.Valuer (take into account that these make use of reflection for scan/value)
NOTE: Keep in mind to always use the following types in the database schema to keep it in sync with the values allowed in Go.
- int64: bigint
- uint64: numeric(20)
- int: bigint
- uint: numeric(20)
- int32: integer
- uint32: bigint
- int16: smallint
- uint16: integer
- int8: smallint
- uint8: smallint
Use them with care.
type Uint16Array ¶
type Uint16Array []uint16
Uint16Array represents a one-dimensional array of the PostgreSQL unsigned integer type.
func (*Uint16Array) Scan ¶
func (a *Uint16Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type Uint32Array ¶
type Uint32Array []uint32
Uint32Array represents a one-dimensional array of the PostgreSQL unsigned integer type.
func (*Uint32Array) Scan ¶
func (a *Uint32Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type Uint64Array ¶
type Uint64Array []uint64
Uint64Array represents a one-dimensional array of the PostgreSQL unsigned bigint type.
func (*Uint64Array) Scan ¶
func (a *Uint64Array) Scan(src interface{}) error
Scan implements the sql.Scanner interface.