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
- func Array(in interface{}) sqlbuilder.ScannerValuer
- func DecodeJSONB(dst interface{}, src interface{}) error
- func EncodeJSONB(i interface{}) (driver.Value, error)
- func JSONBValue(i interface{}) (driver.Value, error)
- func New(sess *sql.DB) (sqlbuilder.Database, error)
- func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)
- func Open(settings db.ConnectionURL) (sqlbuilder.Database, error)
- func ScanJSONB(dst interface{}, src interface{}) error
- type BoolArray
- type ConnectionURL
- type Float64Array
- type GenericArray
- type Int64Array
- type JSONB
- type JSONBArray
- type JSONBConverter
- type JSONBMap
- type StringArray
Constants ¶
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 ¶
EncodeJSONB is deprecated and going to be removed. Use ScanJSONB instead.
func JSONBValue ¶
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
Types ¶
type BoolArray ¶
BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray satisfies sqlbuilder.ScannerValuer.
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.
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.
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.
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 ¶
MarshalJSON encodes the wrapper value as JSON.
func (*JSONB) UnmarshalJSON ¶
UnmarshalJSON decodes the given JSON into the wrapped value.
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.
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.
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.