Documentation ¶
Overview ¶
Package postgresql provides an adapter for PostgreSQL. See https://github.com/upper/db/adapter/postgresql for documentation, particularities and usage examples.
Index ¶
- Constants
- func JSONBValue(i interface{}) (driver.Value, error)
- func New(sqlDB *sql.DB) (db.Session, error)
- func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)
- func Open(connURL db.ConnectionURL) (db.Session, error)
- func ScanJSONB(dst interface{}, src interface{}) error
- type BoolArray
- type Bytea
- type ByteaArray
- type ConnectionURL
- type Float32Array
- type Float64Array
- type Int32Array
- type Int64Array
- type JSONB
- type JSONBArray
- type JSONBConverter
- type JSONBMap
- type StringArray
Constants ¶
const Adapter = "postgresql"
Adapter is the internal name of the adapter.
Variables ¶
This section is empty.
Functions ¶
func JSONBValue ¶
JSONBValue takes an interface and provides a driver.Value that can be stored as a JSONB column.
func NewTx ¶
func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error)
NewTx creates a sqlbuilder.Tx instance by wrapping a *sql.Tx value.
Types ¶
type BoolArray ¶
type BoolArray []bool
BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray satisfies sqlbuilder.ScannerValuer.
type ByteaArray ¶ added in v4.5.0
type ByteaArray [][]byte
ByteaArray represents a one-dimensional array of strings (`[]string{}`) that is compatible with PostgreSQL's text array (`text[]`). ByteaArray satisfies sqlbuilder.ScannerValuer.
func (*ByteaArray) Scan ¶ added in v4.5.0
func (ba *ByteaArray) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.
type ConnectionURL ¶
type ConnectionURL struct { User string Password string Host string Socket string Database string Options map[string]string // contains filtered or unexported fields }
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 Float32Array ¶ added in v4.5.0
type Float32Array []float32
Float32Array represents a one-dimensional array of float32s (`[]float32{}`) that is compatible with PostgreSQL's double precision array (`double precision[]`). Float32Array satisfies sqlbuilder.ScannerValuer.
func (*Float32Array) Scan ¶ added in v4.5.0
func (f32a *Float32Array) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.
type Float64Array ¶
type Float64Array []float64
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 (f64a *Float64Array) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.
type Int32Array ¶ added in v4.5.0
type Int32Array []int32
Int32Array represents a one-dimensional array of int32s (`[]int32{}`) that is compatible with PostgreSQL's integer array (`integer[]`). Int32Array satisfies sqlbuilder.ScannerValuer.
func (*Int32Array) Scan ¶ added in v4.5.0
func (i32a *Int32Array) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.
type Int64Array ¶
type Int64Array []int64
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 (i64a *Int64Array) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.
type JSONB ¶
type JSONB struct {
Data 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 { }
func (*JSONBConverter) ConvertValue ¶ added in v4.5.0
func (*JSONBConverter) ConvertValue(in interface{}) interface { sql.Scanner driver.Valuer }
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 []string
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 (sa *StringArray) Scan(src interface{}) error
Scan satisfies the sql.Scanner interface.