Documentation ¶
Overview ¶
Package pgt provides missing type wrappers to automatically decode and encode advanced PostgreSQL types.
* Real number arrays * Integer number arrays * String arrays * UUID * Time intervals (duration) * more ...
This types provides some interfaces for additional Marshallers (like JSON, YAML)
Index ¶
- Variables
- func CheckPgNoRows(title string, err error) errstack.E
- func CheckRowsAffected(title string, expected int, res orm.Result, err error) errstack.E
- func ErrNotNoRows(title string, err error) errstack.E
- func FilterValidStrings(ss ...String) []string
- func ParseFloatArray(src []byte) ([]float64, error)
- func ParseInt64Array(src []byte) ([]int64, error)
- func SplitNestedSimpleArray(src []byte) [][]byte
- func SplitSimpleArray(src []byte) [][]byte
- type BigInt
- type Float64
- func (s Float64) Add(other Float64) Float64
- func (s Float64) Equals(other *Float64) bool
- func (s Float64) MarshalJSON() ([]byte, error)
- func (s Float64) MarshalYAML() (interface{}, error)
- func (s *Float64) Scan(src interface{}) error
- func (s Float64) String() string
- func (s *Float64) UnmarshalJSON(data []byte) error
- func (s *Float64) UnmarshalYAML(unmarshal func(v interface{}) error) error
- func (s Float64) Value() (driver.Value, error)
- type Float64s
- type Int64
- type Ints
- type Logger
- type String
- type Strings
- func (s Strings) Contains(val string) bool
- func (s Strings) ContainsAll(vals []string) bool
- func (s Strings) ContainsAllSorted(s2 Strings) bool
- func (s Strings) Distinct() Strings
- func (s Strings) EmptyToNil() Strings
- func (s Strings) Equals(s2 Strings) bool
- func (s Strings) Exclude(ss ...string) Strings
- func (s Strings) ForEachPair(f func(string, string))
- func (s Strings) GetOrEmpty(i int) string
- func (s Strings) Map(f func(string) string) Strings
- func (s *Strings) Scan(src interface{}) error
- func (s Strings) TrimMap(m map[string]bool) Strings
- func (s Strings) TrimSpace() Strings
- func (s Strings) Value() (driver.Value, error)
- type Time
- func (t Time) Add(d time.Duration) Time
- func (t Time) MarshalBinary() ([]byte, error)
- func (t Time) MarshalJSON() ([]byte, error)
- func (t *Time) Scan(value interface{}) error
- func (t *Time) UnmarshalBinary(data []byte) (err error)
- func (t *Time) UnmarshalJSON(data []byte) (err error)
- func (t Time) Value() (driver.Value, error)
- type TruncInterval
- type UUID
- func (u UUID) Empty() bool
- func (u UUID) Equals(u2 UUID) bool
- func (u UUID) MarshalJSON() ([]byte, error)
- func (u UUID) MarshalYAML() (interface{}, error)
- func (u *UUID) Scan(value interface{}) error
- func (u UUID) String() string
- func (u *UUID) UnmarshalJSON(data []byte) error
- func (u *UUID) UnmarshalYAML(unmarshaler func(interface{}) error) error
- func (u UUID) Value() (driver.Value, error)
- type UUIDIterator
- type UUIDs
Constants ¶
This section is empty.
Variables ¶
var EmptyArray = []byte("{}")
EmptyArray represents a value of empty Postgresql Array
Functions ¶
func CheckPgNoRows ¶
CheckPgNoRows wraps pg error into errstack.E
func CheckRowsAffected ¶
CheckRowsAffected asserts that expected number of rows has been affected in the SQL operation.
func ErrNotNoRows ¶
ErrNotNoRows if errors is not Nil and is not ErrNoRows then it returns nil. Otherwise it will wrap the error as an IO error.
func FilterValidStrings ¶
FilterValidStrings returns a slice of only valid strings
func ParseFloatArray ¶
ParseFloatArray parses float array column
func ParseInt64Array ¶
ParseInt64Array parses int64 array column
func SplitNestedSimpleArray ¶
SplitNestedSimpleArray splits Postgresql encoded Array of simple types which doesn't require any escape charaters into list of bytes of elements.
func SplitSimpleArray ¶
SplitSimpleArray splits Postgresql encoded Array into list of bytes of elements. It trims {} characters and split by ','
Types ¶
type BigInt ¶
BigInt represents Postgresql numeric type for natural number
func (BigInt) MarshalJSON ¶
MarshalJSON implements the json.Unmarshaler interface.
func (*BigInt) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Float64 ¶
type Float64 sql.NullFloat64
Float64 is a database.sql.NullString Float64
func (Float64) MarshalJSON ¶
MarshalJSON implements Marshaler interface
func (Float64) MarshalYAML ¶
MarshalYAML implements Marshaler
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface
func (*Float64) UnmarshalYAML ¶
UnmarshalYAML implements Unmarshaler
type Float64s ¶
type Float64s []float64
Float64s is a slice of floats for valuer interface
type Int64 ¶
Int64 is a database.sql.Int64 wrapper
func (Int64) MarshalJSON ¶
MarshalJSON implements Marshaler interface
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface
type Ints ¶
type Ints []int64
Ints is a slice of long integers for valuer interface
type Logger ¶
type Logger interface { // Fatal should stop the execution Fatal(msg string, ctx ...interface{}) }
Logger defines the reporting interface for utils error functions
type String ¶
type String sql.NullString
String is a database.sql.NullString wrapper
func (String) MarshalJSON ¶
MarshalJSON implements Marshaler interface
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface
type Strings ¶
type Strings []string
Strings is a slice of strings for valuer interface
func (Strings) ContainsAll ¶
ContainsAll checks if s contains all vals
func (Strings) ContainsAllSorted ¶
ContainsAllSorted checks if s contains all elements from `s2`. We assume that both slices are sorted.
func (Strings) EmptyToNil ¶
EmptyToNil returns nil slice if source contains only empty elements. Otherwise original slice is returned
func (Strings) ForEachPair ¶
ForEachPair executes function for each pair inside Strings. See tests for details
func (Strings) GetOrEmpty ¶
GetOrEmpty returns n-th element or empty string if i is out of range
func (*Strings) Scan ¶
Scan implements sql.Scanner for the String slice type Scanners take the database value (in this case as a byte slice) and sets the value of the type. Here we cast to a string and do a regexp based parse
type Time ¶
Time overrides time.Time for two reasons: (1) json serialization (2) nullability.
On default time.Time serializes two json as string (ISO format). For communication with client we need serialize to UNIX timestamp.
As time.Time is as struct, we are unable to distinguish null value (best we can do is use time.Time.IsZero()). To overcome this issue, agtime.Time has `Valid` field which enables us to handle nulls property. Mainly replicates pq.NullTime behavior
func UTCNow ¶
func UTCNow() Time
UTCNow is an utility method for creating Time representing "now" in UTC time zone
func (Time) MarshalBinary ¶
MarshalBinary implements binary encoding for time This pair of methods are used if agtime.Time is msgpacked.
func (Time) MarshalJSON ¶
MarshalJSON implements Marshaller interface
func (*Time) UnmarshalBinary ¶
UnmarshalBinary implements binary decoding for time
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaller interface
type TruncInterval ¶
type TruncInterval string
TruncInterval is a type for postgres date_trunc first argument - `field`
const ( Microseconds TruncInterval = "microseconds" Milliseconds TruncInterval = "milliseconds" Second TruncInterval = "second" Minute TruncInterval = "minute" Hour TruncInterval = "hour" Day TruncInterval = "day" Week TruncInterval = "week" Month TruncInterval = "month" Quarter TruncInterval = "quarter" Year TruncInterval = "year" Decade TruncInterval = "decade" Century TruncInterval = "century" Millennium TruncInterval = "millennium" )
Valid TruncInterval values
func ParseTruncInterval ¶
func ParseTruncInterval(s string, required bool) (TruncInterval, error)
ParseTruncInterval converts s to valid TruncInternal or "" if s is empty and not required
func (*TruncInterval) Scan ¶
func (tc *TruncInterval) Scan(src interface{}) error
Scan implements sql.Scanner for the TruncInterval type
type UUID ¶
UUID type to wrap uuid package
func ExtractUUIDs ¶
func ExtractUUIDs(i UUIDIterator, optLength ...int) []UUID
ExtractUUIDs returns a list of unique ids from given interator
func MustParseUUID ¶
MustParseUUID parses UUID from string. The function will panic if `s` is not a proper UUID
func (UUID) MarshalJSON ¶
MarshalJSON implements Marshaller interface
func (UUID) MarshalYAML ¶
MarshalYAML implements Marshaler interface of YAML
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaller interface
func (*UUID) UnmarshalYAML ¶
UnmarshalYAML implements Unmarshaler interface of YAML
type UUIDIterator ¶
UUIDIterator is an interface used by `ExtractUUIDs` function