pq_types

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 14 Imported by: 0

README

pq-types Build Status GoDoc

This Go package provides additional types for PostgreSQL:

  • Int32Array for int[] (compatible with intarray module);
  • Int64Array for bigint[];
  • StringArray for varchar[];
  • JSONText for varchar, text, json and jsonb;
  • PostGISPoint, PostGISBox2D and PostGISPolygon.

Install it: go get github.com/mc2soft/pq-types

Documentation

Overview

Package pq_types provides additional types for PostgreSQL: int, bigint and string arrays (former is compatible with intarray module), json and jsonb values, few PostGIS types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NullInt32 added in v1.1.0

func NullInt32(src int32) sql.NullInt32

NullInt32 covers trivial case of int32 to sql.NullInt32 conversion assuming 0 to be NULL

func NullInt64 added in v1.1.0

func NullInt64(src int64) sql.NullInt64

NullInt64 covers trivial case of int64 to sql.NullInt64 conversion assuming 0 to be NULL

func NullString added in v1.1.0

func NullString(src string) sql.NullString

NullString covers trivial case of string to sql.NullString conversion assuming empty string to be NULL

func NullTimestampP added in v1.1.0

func NullTimestampP(src *time.Time) sql.NullTime

NullTimestampP converts *time.Time to a sql.NullTime

Types

type Int32Array

type Int32Array []int32

Int32Array is a slice of int32 values, compatible with PostgreSQL's int[] and intarray module.

func (Int32Array) EqualWithoutOrder

func (a Int32Array) EqualWithoutOrder(b Int32Array) bool

EqualWithoutOrder returns true if two int32 arrays are equal without order, false otherwise. It may sort both arrays in-place to do so.

func (Int32Array) Len

func (a Int32Array) Len() int

func (Int32Array) Less

func (a Int32Array) Less(i, j int) bool

func (*Int32Array) Scan

func (a *Int32Array) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (Int32Array) Swap

func (a Int32Array) Swap(i, j int)

func (Int32Array) Value

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

Value implements database/sql/driver Valuer interface.

type Int64Array

type Int64Array []int64

Int64Array is a slice of int64 values, compatible with PostgreSQL's bigint[].

func (Int64Array) EqualWithoutOrder

func (a Int64Array) EqualWithoutOrder(b Int64Array) bool

EqualWithoutOrder returns true if two int64 arrays are equal without order, false otherwise. It may sort both arrays in-place to do so.

func (Int64Array) Len

func (a Int64Array) Len() int

func (Int64Array) Less

func (a Int64Array) Less(i, j int) bool

func (*Int64Array) Scan

func (a *Int64Array) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (Int64Array) Swap

func (a Int64Array) Swap(i, j int)

func (Int64Array) Value

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

Value implements database/sql/driver Valuer interface.

type JSONText

type JSONText []byte

JSONText is a raw encoded JSON value, compatible with PostgreSQL's varchar, text, json and jsonb. It behaves like json.RawMessage by implementing json.Marshaler and json.Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.

func (JSONText) MarshalJSON

func (j JSONText) MarshalJSON() ([]byte, error)

MarshalJSON returns j as the JSON encoding of j.

func (*JSONText) Scan

func (j *JSONText) Scan(value interface{}) error

Scan implements database/sql Scanner interface. It store value in *j. No validation is done.

func (JSONText) String

func (j JSONText) String() string

String implements fmt.Stringer for better output and logging.

func (*JSONText) UnmarshalJSON

func (j *JSONText) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *j to a copy of data.

func (JSONText) Value

func (j JSONText) Value() (driver.Value, error)

Value implements database/sql/driver Valuer interface. It performs basic validation by unmarshaling itself into json.RawMessage. If j is not valid JSON, it returns and error.

type PostGISBox2D

type PostGISBox2D struct {
	Min, Max PostGISPoint
}

PostGISBox2D is wrapper for PostGIS Box2D type.

func (*PostGISBox2D) Scan

func (b *PostGISBox2D) Scan(value interface{}) error

Scan implements database/sql Scanner interface. It expectes WKT.

func (PostGISBox2D) Value

func (b PostGISBox2D) Value() (driver.Value, error)

Value implements database/sql/driver Valuer interface. It returns box as WKT.

type PostGISPoint

type PostGISPoint struct {
	Lon, Lat float64
}

PostGISPoint is wrapper for PostGIS POINT type.

func (*PostGISPoint) Scan

func (p *PostGISPoint) Scan(value interface{}) error

Scan implements database/sql Scanner interface. It expectes EWKB with SRID 4326 (WGS 84).

func (PostGISPoint) Value

func (p PostGISPoint) Value() (driver.Value, error)

Value implements database/sql/driver Valuer interface. It returns point as WKT with SRID 4326 (WGS 84).

type PostGISPolygon

type PostGISPolygon struct {
	Points []PostGISPoint
}

PostGISPolygon is wrapper for PostGIS Polygon type.

func MakeEnvelope

func MakeEnvelope(min, max PostGISPoint) PostGISPolygon

MakeEnvelope returns rectangular (min, max) polygon

func (*PostGISPolygon) Max

func (p *PostGISPolygon) Max() PostGISPoint

Max returns max side of rectangular polygon

func (*PostGISPolygon) Min

func (p *PostGISPolygon) Min() PostGISPoint

Min returns min side of rectangular polygon

func (*PostGISPolygon) Scan

func (p *PostGISPolygon) Scan(value interface{}) error

Scan implements database/sql Scanner interface. It expectes EWKB with SRID 4326 (WGS 84).

func (PostGISPolygon) Value

func (p PostGISPolygon) Value() (driver.Value, error)

Value implements database/sql/driver Valuer interface. It returns polygon as WKT with SRID 4326 (WGS 84).

type StringArray

type StringArray []string

StringArray is a slice of string values, compatible with PostgreSQL's varchar[].

func (StringArray) Len

func (a StringArray) Len() int

func (StringArray) Less

func (a StringArray) Less(i, j int) bool

func (*StringArray) Scan

func (a *StringArray) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (StringArray) Swap

func (a StringArray) Swap(i, j int)

func (StringArray) Value

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

Value implements database/sql/driver Valuer interface.

Jump to

Keyboard shortcuts

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