dbarray

package
v0.0.0-...-da924b9 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dbarray provides support for database array types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Array

func Array(a interface{}) interface {
	driver.Valuer
	sql.Scanner
}

Array returns the optimal driver.Valuer and sql.Scanner for an array or slice of any dimension.

For example:

db.Query(`SELECT * FROM t WHERE id = ANY($1)`, pq.Array([]int{235, 401}))

var x []sql.NullInt64
db.QueryRow(`SELECT ARRAY[235, 401]`).Scan(pq.Array(&x))

Scanning multi-dimensional arrays is not supported. Arrays where the lower bound is not one (such as `[0:0]={1}') are not supported.

func EnableInfinityTS

func EnableInfinityTS(negative time.Time, positive time.Time)

EnableInfinityTS controls the handling of Postgres' "-infinity" and "infinity" "timestamp"s.

If EnableInfinityTS is not called, "-infinity" and "infinity" will return []byte("-infinity") and []byte("infinity") respectively, and potentially cause error "sql: Scan error on column index 0: unsupported driver -> Scan pair: []uint8 -> *time.Time", when scanning into a time.Time value.

Once EnableInfinityTS has been called, all connections created using this driver will decode Postgres' "-infinity" and "infinity" for "timestamp", "timestamp with time zone" and "date" types to the predefined minimum and maximum times, respectively. When encoding time.Time values, any time which equals or precedes the predefined minimum time will be encoded to "-infinity". Any values at or past the maximum time will similarly be encoded to "infinity".

If EnableInfinityTS is called with negative >= positive, it will panic. Calling EnableInfinityTS after a connection has been established results in undefined behavior. If EnableInfinityTS is called more than once, it will panic.

Types

type Bool

type Bool []bool

Bool represents a one-dimensional array of the PostgreSQL boolean type.

func (*Bool) Scan

func (a *Bool) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Bool) Value

func (a Bool) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Bytea

type Bytea [][]byte

Bytea represents a one-dimensional array of the PostgreSQL bytea type.

func (*Bytea) Scan

func (a *Bytea) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Bytea) Value

func (a Bytea) Value() (driver.Value, error)

Value implements the driver.Valuer interface. It uses the "hex" format which is only supported on PostgreSQL 9.0 or newer.

type Delimiter

type Delimiter interface {
	// Delimiter returns the delimiter character(s) for this element's type.
	Delimiter() string
}

Delimiter may be optionally implemented by driver.Valuer or sql.Scanner to override the array delimiter used by Generic.

type Float32

type Float32 []float32

Float32 represents a one-dimensional array of the PostgreSQL double precision type.

func (*Float32) Scan

func (a *Float32) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Float32) Value

func (a Float32) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Float64

type Float64 []float64

Float64 represents a one-dimensional array of the PostgreSQL double precision type.

func (*Float64) Scan

func (a *Float64) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Float64) Value

func (a Float64) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Generic

type Generic struct{ A interface{} }

Generic implements the driver.Valuer and sql.Scanner interfaces for an array or slice of any dimension.

func (Generic) Scan

func (a Generic) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Generic) Value

func (a Generic) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Int32

type Int32 []int32

Int32 represents a one-dimensional array of the PostgreSQL integer types.

func (*Int32) Scan

func (a *Int32) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Int32) Value

func (a Int32) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Int64

type Int64 []int64

Int64 represents a one-dimensional array of the PostgreSQL integer types.

func (*Int64) Scan

func (a *Int64) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Int64) Value

func (a Int64) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type String

type String []string

String represents a one-dimensional array of the PostgreSQL character types.

func (*String) Scan

func (a *String) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (String) Value

func (a String) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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