types

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: MIT Imports: 11 Imported by: 0

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

func Nullable(typ interface{}) sql.Scanner

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 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.

func (Float32Array) Value

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

Value implements the driver.Valuer 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.

func (Int16Array) Value

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

Value implements the driver.Valuer 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.

func (Int32Array) Value

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

Value implements the driver.Valuer interface.

type Int8Array

type Int8Array []int8

Int8Array represents a one-dimensional array of the PostgreSQL integer type.

func (*Int8Array) Scan

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

Scan implements the sql.Scanner interface.

func (Int8Array) Value

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

Value implements the driver.Valuer interface.

type IntArray

type IntArray []int

IntArray represents a one-dimensional array of the PostgreSQL integer type.

func (*IntArray) Scan

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

Scan implements the sql.Scanner interface.

func (IntArray) Value

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

Value implements the driver.Valuer interface.

type SQLType

type SQLType interface {
	sql.Scanner
	driver.Valuer
}

SQLType is the common interface a type has to fulfill to be considered a SQL type.

func Array

func Array(v interface{}, size int) SQLType

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 URL

type URL url.URL

URL is a wrapper of url.URL that implements SQLType interface.

func (*URL) Scan

func (u *URL) Scan(v interface{}) error

func (URL) Value

func (u URL) Value() (driver.Value, error)

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.

func (Uint16Array) Value

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

Value implements the driver.Valuer 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.

func (Uint32Array) Value

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

Value implements the driver.Valuer 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.

func (Uint64Array) Value

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

Value implements the driver.Valuer interface.

type Uint8Array

type Uint8Array []uint8

Uint8Array represents a one-dimensional array of the PostgreSQL unsigned integer type.

func (*Uint8Array) Scan

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

Scan implements the sql.Scanner interface.

func (Uint8Array) Value

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

Value implements the driver.Valuer interface.

type UintArray

type UintArray []uint

UintArray represents a one-dimensional array of the PostgreSQL unsigned integer type.

func (*UintArray) Scan

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

Scan implements the sql.Scanner interface.

func (UintArray) Value

func (a UintArray) 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