postgresql

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 19 Imported by: 43

README

PostgreSQL adapter for upper.io/db

Please read the full docs, acknowledgements and examples at https://upper.io/db.v3/postgresql

Documentation

Overview

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

Index

Constants

View Source
const Adapter = `postgresql`

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

Variables

This section is empty.

Functions

func Array

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

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

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

func EncodeJSONB

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

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

func JSONBValue

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

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

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

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

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

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

Types

type BoolArray

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

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

Scan satisfies the sql.Scanner interface.

func (BoolArray) Value

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

Value satisfies the driver.Valuer interface.

type ConnectionURL

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

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

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

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

type Float64Array

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

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

Scan satisfies the sql.Scanner interface.

func (Float64Array) Value

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

Value satisfies the driver.Valuer interface.

type GenericArray

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

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

Scan satisfies the sql.Scanner interface.

func (GenericArray) Value

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

Value satisfies the driver.Valuer interface.

type Int64Array

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

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

Scan satisfies the sql.Scanner interface.

func (Int64Array) Value

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

Value satisfies the driver.Valuer interface.

type JSONB

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

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

MarshalJSON encodes the wrapper value as JSON.

func (*JSONB) Scan

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

Scan satisfies the sql.Scanner interface.

func (*JSONB) UnmarshalJSON

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

UnmarshalJSON decodes the given JSON into the wrapped value.

func (JSONB) Value

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

Value satisfies the driver.Valuer interface.

type JSONBArray

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

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

Scan satisfies the sql.Scanner interface.

func (JSONBArray) Value

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

Value satisfies the driver.Valuer interface.

type JSONBConverter

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

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

WrapValue satisfies sqlbuilder.ValueWrapper

type JSONBMap

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

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

Scan satisfies the sql.Scanner interface.

func (JSONBMap) Value

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

Value satisfies the driver.Valuer interface.

type StringArray

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

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

Scan satisfies the sql.Scanner interface.

func (StringArray) Value

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

Value satisfies the driver.Valuer interface.

Jump to

Keyboard shortcuts

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