db.v3: upper.io/db.v3/postgresql Index | Files

package postgresql

import "upper.io/db.v3/postgresql"

Package postgresql wraps the github.com/lib/pq PostgreSQL driver. See https://upper.io/db.v3/postgresql for documentation, particularities and usage examples.

Index

Package Files

collection.go connection.go custom_types.go database.go postgresql.go template.go tx.go

Constants

const Adapter = `postgresql`

Adapter is the unique name that you can use to refer to this adapter.

func Array Uses

func Array(in interface{}) sqlbuilder.ScannerValuer

Array returns a sqlbuilder.ScannerValuer for any given slice. Slice elements may require their own sqlbuilder.ScannerValuer.

func DecodeJSONB Uses

func DecodeJSONB(dst interface{}, src interface{}) error

DecodeJSONB is deprecated and going to be removed. Use JSONBValue instead.

func EncodeJSONB Uses

func EncodeJSONB(i interface{}) (driver.Value, error)

EncodeJSONB is deprecated and going to be removed. Use ScanJSONB instead.

func JSONBValue Uses

func JSONBValue(i interface{}) (driver.Value, error)

JSONBValue takes an interface and provides a driver.Value that can be stored as a JSONB column.

func New Uses

func New(sess *sql.DB) (sqlbuilder.Database, error)

New wraps a regular *sql.DB session and creates a new upper-db session backed by it.

func NewTx Uses

func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)

NewTx wraps a regular *sql.Tx transaction and returns a new upper-db transaction backed by it.

func Open Uses

func Open(settings db.ConnectionURL) (sqlbuilder.Database, error)

Open opens a new connection with the PostgreSQL server. The returned session is validated first by Ping and then with a test query before being returned. You may call Open() just once and use it on multiple goroutines on a long-running program. See https://golang.org/pkg/database/sql/#Open and http://go-database-sql.org/accessing.html

func ScanJSONB Uses

func ScanJSONB(dst interface{}, src interface{}) error

ScanJSONB decodes a JSON byte stream into the passed dst value.

type BoolArray Uses

type BoolArray pq.BoolArray

BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray satisfies sqlbuilder.ScannerValuer.

func (*BoolArray) Scan Uses

func (b *BoolArray) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (BoolArray) Value Uses

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

Value satisfies the driver.Valuer interface.

type ConnectionURL Uses

type ConnectionURL struct {
    User     string
    Password string
    Host     string
    Socket   string
    Database string
    Options  map[string]string
}

ConnectionURL represents a parsed PostgreSQL connection URL.

You can use a ConnectionURL struct as an argument for Open:

var settings = postgresql.ConnectionURL{
  Host:       "localhost",          // PostgreSQL server IP or name.
  Database:   "peanuts",            // Database name.
  User:       "cbrown",             // Optional user name.
  Password:   "snoopy",             // Optional user password.
}

sess, err = postgresql.Open(settings)

If you already have a valid DSN, you can use ParseURL to convert it into a ConnectionURL before passing it to Open.

func ParseURL Uses

func ParseURL(s string) (u ConnectionURL, err error)

ParseURL parses the given DSN into a ConnectionURL struct. A typical PostgreSQL connection URL looks like:

postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full

func (ConnectionURL) String Uses

func (c ConnectionURL) String() (s string)

String reassembles the parsed PostgreSQL connection URL into a valid DSN.

type Float64Array Uses

type Float64Array pq.Float64Array

Float64Array represents a one-dimensional array of float64s (`[]float64{}`) that is compatible with PostgreSQL's double precision array (`double precision[]`). Float64Array satisfies sqlbuilder.ScannerValuer.

func (*Float64Array) Scan Uses

func (f *Float64Array) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (Float64Array) Value Uses

func (f Float64Array) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

type GenericArray Uses

type GenericArray pq.GenericArray

GenericArray represents a one-dimensional array of any type (`[]interface{}`) that is compatible with PostgreSQL's array type. GenericArray satisfies sqlbuilder.ScannerValuer and its elements may need to satisfy sqlbuilder.ScannerValuer too.

func (*GenericArray) Scan Uses

func (g *GenericArray) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (GenericArray) Value Uses

func (g GenericArray) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

type Int64Array Uses

type Int64Array pq.Int64Array

Int64Array represents a one-dimensional array of int64s (`[]int64{}`) that is compatible with PostgreSQL's integer array (`integer[]`). Int64Array satisfies sqlbuilder.ScannerValuer.

func (*Int64Array) Scan Uses

func (i *Int64Array) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (Int64Array) Value Uses

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

Value satisfies the driver.Valuer interface.

type JSONB Uses

type JSONB struct {
    V interface{}
}

JSONB represents a PostgreSQL's JSONB value: https://www.postgresql.org/docs/9.6/static/datatype-json.html. JSONB satisfies sqlbuilder.ScannerValuer.

func (JSONB) MarshalJSON Uses

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

MarshalJSON encodes the wrapper value as JSON.

func (*JSONB) Scan Uses

func (j *JSONB) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (*JSONB) UnmarshalJSON Uses

func (j *JSONB) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the given JSON into the wrapped value.

func (JSONB) Value Uses

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

Value satisfies the driver.Valuer interface.

type JSONBArray Uses

type JSONBArray []interface{}

JSONBArray represents an array of any type (`[]interface{}`) that is compatible with PostgreSQL's JSONB type. JSONBArray satisfies sqlbuilder.ScannerValuer.

func (*JSONBArray) Scan Uses

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

Scan satisfies the sql.Scanner interface.

func (JSONBArray) Value Uses

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

Value satisfies the driver.Valuer interface.

type JSONBConverter Uses

type JSONBConverter struct {
}

JSONBConverter provides a helper method WrapValue that satisfies sqlbuilder.ValueWrapper, can be used to encode Go structs into JSONB PostgreSQL types and vice versa.

Example:

type MyCustomStruct struct {
  ID int64 `db:"id" json:"id"`
  Name string `db:"name" json:"name"`
  ...
  postgresql.JSONBConverter
}

func (*JSONBConverter) WrapValue Uses

func (obj *JSONBConverter) WrapValue(src interface{}) interface{}

WrapValue satisfies sqlbuilder.ValueWrapper

type JSONBMap Uses

type JSONBMap map[string]interface{}

JSONBMap represents a map of interfaces with string keys (`map[string]interface{}`) that is compatible with PostgreSQL's JSONB type. JSONBMap satisfies sqlbuilder.ScannerValuer.

func (*JSONBMap) Scan Uses

func (m *JSONBMap) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface.

func (JSONBMap) Value Uses

func (m JSONBMap) Value() (driver.Value, error)

Value satisfies the driver.Valuer interface.

type StringArray Uses

type StringArray pq.StringArray

StringArray represents a one-dimensional array of strings (`[]string{}`) that is compatible with PostgreSQL's text array (`text[]`). StringArray satisfies sqlbuilder.ScannerValuer.

func (*StringArray) Scan Uses

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

Scan satisfies the sql.Scanner interface.

func (StringArray) Value Uses

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

Value satisfies the driver.Valuer interface.

Package postgresql imports 19 packages (graph) and is imported by 2 packages. Updated 2018-09-25. Refresh now. Tools for package owners.