pgtypes

package module
v0.0.0-...-9d3009a Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

README

PGTYPES

Build Status Coverage Status Go Report Card GoDoc

Package PgTypes implements some PostgreSQL types in the GoLang. Implemented types can be simply used in DB communication via Pgx or via Pq and/or separately.

Currently implemented types:

  • Interval
  • Numeric
  • UUID

Any suggestions and bugs are welcome.

Documentation

Overview

Package pgtypes implements some PostgreSQL types in the GoLang. Implemented types can be simply used in DB communication and/or separately. Currently implemented types are Interval, Numeric and UUID.

Index

Constants

View Source
const (
	IntervalSecondPrecision      = 0
	IntervalMillisecondPrecision = 3
	IntervalMicrosecondPrecision = 6
	IntervalNanosecondPrecision  = 9
	IntervalPicosecondPrecision  = 12
	IntervalGoPrecision          = IntervalNanosecondPrecision
	IntervalPgPrecision          = IntervalMicrosecondPrecision
	IntervalMaxPrecision         = 12
)

Predefined precisions for Interval.

View Source
const (
	// UUIDLen is a length of UUID in bytes
	UUIDLen = 16
	// UUIDCleanStringLen is a length of raw UUID string representation length in chars ("6ba7b8149dad11d180b400c04fd430c8")
	UUIDCleanStringLen = UUIDLen * 2
	// UUIDStringLen is a length of default UUID string representation length in chars ("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
	UUIDStringLen = UUIDLen*2 + 4
)
View Source
const (
	// IntervalOid is an object identifier (OID) of Interval type used in PostgreSQL.
	IntervalOid = 1186
)
View Source
const (
	// NumericOid is an object identifier (OID) of Numeric type used in PostgreSQL.
	NumericOid = 1700
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval struct {
	Months      int32
	Days        int32
	SomeSeconds int64
	// contains filtered or unexported fields
}

Interval represent time interval in Postgres-compatible way. It consists of 3 public fields:

Months - number months
Days - number of days
SomeSeconds - number of seconds or some smaller units (depends on precision).

All fields are signed. Sign of one field is independent from sign of others. Interval internally stores precision. Precision is number of digits after comma in 10-based representation of seconds. Precision can be from [0; 12] where 0 means that SomeSeconds is seconds and 12 means that SomeSeconds is picoseconds. If Interval created without calling constructor when it has 0 precision (i.e. SomeSeconds is just seconds). If Interval created with calling constructor and its documentation does not say another when it has precision = 9 (i.e. SomeSeconds is nanoseconds). This is because default Go time type has nanosecond precision. If interval is used to store PostgreSQL Interval when recommended precision is 6 (microsecond) because PostgreSQL use microsecond precision. This type is similar to Postgres interval data type. Value from one field is never automatically translated to value of another field, so <60*60*24 seconds> != <1 days> and so on. This is because of compatibility with Postgres, moreover day may have different amount of seconds and month may have different amount of days.

func Day

func Day() Interval

Day returns new Interval equal to 1 day.

func Diff

func Diff(from, to time.Time) Interval

Diff calculates difference between given timestamps (time.Time) as nanoseconds and returns result as Interval (=to-from). Result always have months & days parts set to zero.

func DiffExtended

func DiffExtended(from, to time.Time) (i Interval)

DiffExtended is similar to Diff but calculates difference in months, days & nanoseconds instead of just nanoseconds (=to-from). Result may have non-zero months & days parts. DiffExtended use Location of both passed times while calculation. Most of time it is better to pass times with the same Location (UTC or not).

func FromDuration

func FromDuration(d time.Duration) Interval

FromDuration returns new Interval equivalent for given time.Duration (convert time.Duration to Interval).

func Hour

func Hour() Interval

Hour returns new Interval equal to 1 hour (3600 seconds).

func Microsecond

func Microsecond() Interval

Microsecond returns new Interval equal to 1 microsecond.

func Millisecond

func Millisecond() Interval

Millisecond returns new Interval equal to 1 millisecond.

func Minute

func Minute() Interval

Minute returns new Interval equal to 1 minute (60 seconds).

func Month

func Month() Interval

Month returns new Interval equal to 1 month.

func Nanosecond

func Nanosecond() Interval

Nanosecond returns new Interval equal to 1 nanosecond.

func NewGoInterval

func NewGoInterval() Interval

NewGoInterval returns zero interval with GoLang precision (= nanosecond).

func NewInterval

func NewInterval(p uint8) Interval

NewInterval returns zero interval with specified precision p.

func NewPgInterval

func NewPgInterval() Interval

NewPgInterval returns zero interval with PostgreSQL precision (= microsecond).

func ParseInterval

func ParseInterval(s string, p uint8) (i Interval, err error)

ParseInterval parses incoming string and extract interval with requested precision p. Format is postgres style specification for interval output format. Examples:

-1 year 2 mons -3 days 04:05:06.789
1 mons
2 year -34:56:78
00:00:00

BUG(unsacrificed): ParseInterval may overflow SomeSeconds if computed SomeSeconds should be MinInt64.

func Picosecond

func Picosecond() Interval

Picosecond returns new Interval equal to 1 picosecond. This constructor return interval with precision = 12 (picosecond).

func Second

func Second() Interval

Second returns new Interval equal to 1 second.

func Since

func Since(t time.Time) Interval

Since returns elapsed time since given timestamp as Interval (=Diff(t, time.New()). Result always have months & days parts set to zero.

func SinceExtended

func SinceExtended(t time.Time) Interval

SinceExtended returns elapsed time since given timestamp as Interval (=DiffExtended(t, time.New()). Result may have non-zero months & days parts.

func Year

func Year() Interval

Year returns new Interval equal to 1 year (12 months).

func (Interval) Add

func (i Interval) Add(add Interval) Interval

Add returns i+add.

func (Interval) AddTo

func (i Interval) AddTo(t time.Time) time.Time

AddTo adds original Interval to given timestamp and return result.

func (Interval) Cmp

func (i Interval) Cmp(i2 Interval) (sign int, ok bool)

Cmp returns compare two Intervals. ok indicates is i and i2 comparable. sign means the following:

sign<0 => i<i2
sign=0 => i=i2
sign>0 => i>i2

func (Interval) Comparable

func (i Interval) Comparable(i2 Interval) bool

Comparable returns true only if it is possible to compare Intervals. Intervals "A" and "B" can be compared only if:

  1. all parts of "A" are less or equal to relative parts of "B" or
  2. all parts of "B" are less or equal to relative parts of "A".

In the other words, it is impossible to compare "30 days"-Interval with "1 month"-Interval.

func (Interval) Div

func (i Interval) Div(div int64) Interval

Div divides interval by mul and returns result. Each part of Interval divides independently. Round rule: 0.4=>0 ; 0.5=>1 ; 0.6=>1 ; -0.4=>0 ; -0.5=>-1 ; -0.6=>-1

func (Interval) Duration

func (i Interval) Duration(daysInMonth uint8, minutesInDay uint32) time.Duration

Duration convert Interval to time.Duration. It is required to pass number of days in month (usually 30 or something near) and number of minutes in day (usually 1440) because of converting months and days parts of original Interval to time.Duration nanoseconds. Warning: this method is inaccuracy because in real life daysInMonth & minutesInDay vary and depends on relative timestamp.

func (Interval) Encode

func (i Interval) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (Interval) Equal

func (i Interval) Equal(i2 Interval) bool

Equal compare original Interval with given for full equality part by part.

func (Interval) FormatCode

func (i Interval) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (Interval) Greater

func (i Interval) Greater(i2 Interval) bool

Greater returns true if at least one part of original Interval is greater then relative part of i2 and all other parts of original Interval are greater or equal to relative parts of i2.

func (Interval) GreaterOrEqual

func (i Interval) GreaterOrEqual(i2 Interval) bool

GreaterOrEqual returns true if all parts of original Interval are greater or equal to relative parts of i2.

func (Interval) In

func (i Interval) In(i2 Interval) int64

In counts how many i contains in i2 (=i2/i). Round rule: 0.4=>0 ; 0.5=>1 ; 0.6=>1 ; -0.4=>0 ; -0.5=>-1 ; -0.6=>-1

func (Interval) Less

func (i Interval) Less(i2 Interval) bool

Less returns true if at least one part of original Interval is less then relative part of i2 and all other parts of original Interval are less or equal to relative parts of i2.

func (Interval) LessOrEqual

func (i Interval) LessOrEqual(i2 Interval) bool

LessOrEqual returns true if all parts of original Interval are less or equal to relative parts of i2.

func (Interval) Mul

func (i Interval) Mul(mul int64) Interval

Mul returns interval i multiplied by mul. Each part of Interval multiples independently.

func (Interval) NormalDays

func (i Interval) NormalDays() int32

NormalDays just returns Days part.

func (Interval) NormalHours

func (i Interval) NormalHours() int64

NormalHours returns number of hours in seconds part.

func (Interval) NormalMinutes

func (i Interval) NormalMinutes() int64

NormalMinutes returns number of hours in seconds part after subtracting NormalHours.

func (Interval) NormalMonths

func (i Interval) NormalMonths() int32

NormalMonths return number of months in month part after subtracting NormalYears*12 (as i.Months % 12). Examples: if .Months = 11 then NormalMonths = 11, but if .Months = 13 then NormalMonths = 1.

func (Interval) NormalNanoseconds

func (i Interval) NormalNanoseconds() int64

NormalNanoseconds returns number of nanoseconds in fraction part of seconds part.

func (Interval) NormalSeconds

func (i Interval) NormalSeconds() int64

NormalSeconds returns number of seconds in seconds part after subtracting NormalHours*3600 and NormalMinutes*60 (as i.Seconds % 60).

func (Interval) NormalYears

func (i Interval) NormalYears() int32

NormalYears return number of years in month part (as i.Months / 12).

func (Interval) Nullable

func (i Interval) Nullable() NullInterval

Nullable returns valid NullInterval with Interval i.

func (Interval) Precision

func (i Interval) Precision() uint8

Precision returns internally stored precision.

func (Interval) SafePrec

func (i Interval) SafePrec() uint8

SafePrec returns minimal precision which can be used for current Interval without data loss. Examples:

10 seconds => 0 (second precision, can not be less)
10 milliseconds => 2 (2 digit after decimal point precision)
123 microseconds => 6 (microsecond precision)

func (*Interval) Scan

func (i *Interval) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface.

func (*Interval) ScanPgx

func (i *Interval) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (Interval) SetPrecision

func (i Interval) SetPrecision(p uint8) Interval

SetPrecision returns new interval with changed precision (and do appropriate recalculation). Possible precision is 0..12 where 0 means second precision and 9 means nanosecond precision. If passed p>12 it will be silently replaced with p=12.

func (Interval) String

func (i Interval) String() string

String returns string representation of interval. Output format is the same as for Parse.

BUG(unsacrificed): String may overflow SomeSeconds if SomeSeconds is MinInt64.

func (Interval) Sub

func (i Interval) Sub(sub Interval) Interval

Sub returns i-sub.

func (Interval) SubFrom

func (i Interval) SubFrom(t time.Time) time.Time

SubFrom subtract original Interval from given timestamp and return result.

func (Interval) Value

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

Value implements the driver.Valuer interface.

type NullInterval

type NullInterval struct {
	Interval Interval
	Valid    bool
}

NullInterval represents an Interval that may be null. It implements the pgx.PgxScanner and pgx.Encoder interfaces so it may be used both as an argument to Query[Row] and a destination for ScanPgx.

If Valid is false then the value is NULL.

func (NullInterval) Encode

func (n NullInterval) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (NullInterval) FormatCode

func (n NullInterval) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (*NullInterval) Scan

func (n *NullInterval) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface.

func (*NullInterval) ScanPgx

func (n *NullInterval) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (NullInterval) Value

func (n NullInterval) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type NullNumeric

type NullNumeric struct {
	Numeric Numeric
	Valid   bool // Valid is true if Numeric is not NULL
}

NullNumeric represents an Numeric that may be NULL. NullNumeric implements the pgx.PgxScanner and pgx.Encoder interfaces so it may be used both as an argument to Query[Row] and a destination for ScanPgx.

If Valid is false then the value is NULL.

func (NullNumeric) Encode

func (n NullNumeric) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (NullNumeric) FormatCode

func (n NullNumeric) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (*NullNumeric) Scan

func (n *NullNumeric) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface.

func (*NullNumeric) ScanPgx

func (n *NullNumeric) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (NullNumeric) Value

func (n NullNumeric) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type NullUUID

type NullUUID struct {
	UUID  UUID
	Valid bool // Valid is true if UUID is not NULL
}

NullUUID represents an UUID that may be NULL. NullUUID implements the pgx.PgxScanner and pgx.Encoder interfaces so it may be used both as an argument to Query[Row] and a destination for ScanPgx.

If Valid is false then the value is NULL.

func (NullUUID) Encode

func (u NullUUID) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (NullUUID) FormatCode

func (u NullUUID) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (*NullUUID) Scan

func (u *NullUUID) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface.

func (*NullUUID) ScanPgx

func (u *NullUUID) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (NullUUID) Value

func (u NullUUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Numeric

type Numeric struct {
	// contains filtered or unexported fields
}

Numeric is a PostgreSQL Numeric type implementation in GoLang. It is arbitrary precision numbers type which can store numbers with a very large number of digits. It is especially recommended for storing monetary amounts and other quantities where exactness is required. Calculations with Numeric values yield exact results where possible, e.g. addition, subtraction, multiplication. However, calculations on Numeric values are very slow compared to the integer types, or to the floating-point types. Internally Numeric type has the same structure (except dscale field) as a PostgreSQL numeric type so it perfect for using in DB communications.

func NewInt

func NewInt(x int) *Numeric

NewInt allocates and returns a new Numeric set to x.

func NewInt16

func NewInt16(x int16) *Numeric

NewInt16 allocates and returns a new Numeric set to x.

func NewInt32

func NewInt32(x int32) *Numeric

NewInt32 allocates and returns a new Numeric set to x.

func NewInt64

func NewInt64(x int64) *Numeric

NewInt64 allocates and returns a new Numeric set to x.

func NewInt8

func NewInt8(x int8) *Numeric

NewInt8 allocates and returns a new Numeric set to x.

func NewNumeric

func NewNumeric() *Numeric

NewNumeric allocates and returns a new Numeric set to 0.

func NewUint

func NewUint(x uint) *Numeric

NewUint allocates and returns a new Numeric set to x.

func NewUint16

func NewUint16(x uint16) *Numeric

NewUint16 allocates and returns a new Numeric set to x.

func NewUint32

func NewUint32(x uint32) *Numeric

NewUint32 allocates and returns a new Numeric set to x.

func NewUint64

func NewUint64(x uint64) *Numeric

NewUint64 allocates and returns a new Numeric set to x.

func NewUint8

func NewUint8(x uint8) *Numeric

NewUint8 allocates and returns a new Numeric set to x.

func (*Numeric) Abs

func (z *Numeric) Abs(x *Numeric) *Numeric

Abs sets z to |x| (the absolute value of x) and returns z.

func (*Numeric) Add

func (z *Numeric) Add(x, y *Numeric) *Numeric

Add sets z to the sum x+y and returns z.

func (*Numeric) Cmp

func (x *Numeric) Cmp(y *Numeric) (r int)

Cmp compare two Numeric.

-1 if x <  y
 0 if x == y
+1 if x >  y

NaN treats as equal to other NaN and greater then any other number. This is as in PostgreSQL.

func (*Numeric) Copy

func (z *Numeric) Copy(x *Numeric) *Numeric

Copy sets z to x and returns z. x is not changed even if z and x are the same.

func (Numeric) Encode

func (n Numeric) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (Numeric) FormatCode

func (n Numeric) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (*Numeric) Int

func (x *Numeric) Int() int

Int returns the int representation of x. If x is NaN, the result is 0. If x cannot be represented in an int, the result is undefined.

func (*Numeric) Int16

func (x *Numeric) Int16() int16

Int16 returns the int16 representation of x. If x is NaN, the result is 0. If x cannot be represented in an int16, the result is undefined.

func (*Numeric) Int32

func (x *Numeric) Int32() int32

Int32 returns the int32 representation of x. If x is NaN, the result is 0. If x cannot be represented in an int32, the result is undefined.

func (*Numeric) Int64

func (x *Numeric) Int64() int64

Int64 returns the int64 representation of x. If x is NaN, the result is 0. If x cannot be represented in an int64, the result is undefined.

func (*Numeric) Int8

func (x *Numeric) Int8() int8

Int8 returns the int8 representation of x. If x is NaN, the result is 0. If x cannot be represented in an int8, the result is undefined.

func (*Numeric) IsNaN

func (x *Numeric) IsNaN() bool

IsNaN reports whether x is NaN.

func (*Numeric) IsZero

func (x *Numeric) IsZero() bool

IsZero reports whether x is zero.

func (*Numeric) Mul

func (z *Numeric) Mul(x, y *Numeric) *Numeric

Mul sets z to the product x*y and returns z.

func (*Numeric) Neg

func (z *Numeric) Neg(x *Numeric) *Numeric

Neg sets z to -x and returns z.

func (Numeric) Nullable

func (n Numeric) Nullable() NullNumeric

Nullable returns valid NullNumeric with Numeric n.

func (*Numeric) Quo

func (z *Numeric) Quo(x, y *Numeric) *Numeric

Quo is just a shorthand for QuoPrec with default scale and rounding enabled. Default scale calculates as in PostgreSQL (more or less).

func (*Numeric) QuoPrec

func (z *Numeric) QuoPrec(x, y *Numeric, scale int16, round bool) *Numeric

QuoPrec sets z to the quotient x/y for y != 0 and returns z. Result will truncated or rounded up to scale decimal digits after decimal point. Result will be rounded if round is true, otherwise result will be truncated. If y == 0, a division-by-zero run-time panic occurs. QuoPrec implements truncated division (like Go); see QuoRem for more details.

func (*Numeric) QuoRem

func (z *Numeric) QuoRem(x, y, m *Numeric) (*Numeric, *Numeric)

QuoRem sets z to the quotient x/y and r to the remainder x%y and returns the pair (z, r) for y != 0. If y == 0, a division-by-zero run-time panic occurs.

QuoRem implements T-division and modulus (like Go):

q = x/y      with the result truncated to zero
r = x - y*q

(See Daan Leijen, “Division and Modulus for Computer Scientists”.) Euclidean division and modulus (unlike Go) do not currently implemented for Numeric.

func (*Numeric) Rem

func (z *Numeric) Rem(x, y *Numeric) *Numeric

Rem sets z to the remainder x%y for y != 0 and returns z. If y == 0, a division-by-zero run-time panic occurs. Rem implements truncated modulus (like Go); see QuoRem for more details.

func (*Numeric) Scan

func (n *Numeric) Scan(src interface{}) (err error)

Scan implements the sql.Numeric interface.

func (*Numeric) ScanPgx

func (n *Numeric) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (*Numeric) SetInt

func (z *Numeric) SetInt(x int) *Numeric

SetInt sets z to x and returns z.

func (*Numeric) SetInt16

func (z *Numeric) SetInt16(x int16) *Numeric

SetInt16 sets z to x and returns z.

func (*Numeric) SetInt32

func (z *Numeric) SetInt32(x int32) *Numeric

SetInt32 sets z to x and returns z.

func (*Numeric) SetInt64

func (z *Numeric) SetInt64(x int64) *Numeric

SetInt64 sets z to x and returns z.

func (*Numeric) SetInt8

func (z *Numeric) SetInt8(x int8) *Numeric

SetInt8 sets z to x and returns z.

func (*Numeric) SetNaN

func (z *Numeric) SetNaN() *Numeric

SetNaN sets Number z to NaN and return z.

func (*Numeric) SetString

func (z *Numeric) SetString(s string) (*Numeric, bool)

SetString sets z to the value of s and returns z and a boolean indicating success. s must be a floating-point number of one of format

[+-]?[0-9]*\.[0-9]*	// "123.456", "123.", ".456", ".", "-123.456"
[+-]?[0-9]+		// "123", "-123"

func (*Numeric) SetUint

func (z *Numeric) SetUint(x uint) *Numeric

SetUint sets z to x and returns z.

func (*Numeric) SetUint16

func (z *Numeric) SetUint16(x uint16) *Numeric

SetUint16 sets z to x and returns z.

func (*Numeric) SetUint32

func (z *Numeric) SetUint32(x uint32) *Numeric

SetUint32 sets z to x and returns z.

func (*Numeric) SetUint64

func (z *Numeric) SetUint64(x uint64) *Numeric

SetUint64 sets z to x and returns z.

func (*Numeric) SetUint8

func (z *Numeric) SetUint8(x uint8) *Numeric

SetUint8 sets z to x and returns z.

func (*Numeric) SetZero

func (z *Numeric) SetZero() *Numeric

SetZero sets Number z to zero and return z.

func (*Numeric) Sign

func (x *Numeric) Sign() int

Sign returns first value as following:

-1 if x <  0
 0 if x is 0
+1 if x >  0
+2 if x is NaN

func (*Numeric) String

func (x *Numeric) String() (r string)

String converts the Number x to a string representation (10-base).

func (*Numeric) Sub

func (z *Numeric) Sub(x, y *Numeric) *Numeric

Sub sets z to the difference x-y and returns z.

func (*Numeric) Uint

func (x *Numeric) Uint() uint

Uint returns the uint representation of x. If x is NaN, the result is 0. If x cannot be represented in an uint, the result is undefined.

func (*Numeric) Uint16

func (x *Numeric) Uint16() uint16

Uint16 returns the uint16 representation of x. If x is NaN, the result is 0. If x cannot be represented in an uint16, the result is undefined.

func (*Numeric) Uint32

func (x *Numeric) Uint32() uint32

Uint32 returns the uint32 representation of x. If x is NaN, the result is 0. If x cannot be represented in an uint32, the result is undefined.

func (*Numeric) Uint64

func (x *Numeric) Uint64() uint64

Uint64 returns the uint64 representation of x. If x is NaN, the result is 0. If x cannot be represented in an uint64, the result is undefined.

func (*Numeric) Uint8

func (x *Numeric) Uint8() uint8

Uint8 returns the uint8 representation of x. If x is NaN, the result is 0. If x cannot be represented in an uint8, the result is undefined.

func (Numeric) Value

func (n Numeric) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type UUID

type UUID [UUIDLen]byte

UUID representation compliant with specification described in RFC 4122.

func ParseUUID

func ParseUUID(s string) (u UUID, err error)

ParseUUID parses an UUID standard string representation (like "6ba7b814-9dad-11d1-80b4-00c04fd430c8").

func ParseUUIDBytes

func ParseUUIDBytes(b []byte) (u UUID, err error)

ParseUUIDBytes parses byte slice (as-is) with UUID.

func ParseUUIDClean

func ParseUUIDClean(s string) (u UUID, err error)

ParseUUIDClean parses an UUID clean string representation (like "6ba7b8149dad11d180b400c04fd430c8").

func (UUID) Bytes

func (u UUID) Bytes() []byte

Bytes returns byte slice containing UUID (as-is).

func (UUID) CleanString

func (u UUID) CleanString() string

CleanString returns clean string representation of UUID (without any additional chars and in lower case).

func (UUID) Encode

func (u UUID) Encode(w *pgx.WriteBuf, oid pgx.Oid) error

Encode implements the pgx.Encoder interface.

func (UUID) FormatCode

func (u UUID) FormatCode() int16

FormatCode implements the pgx.Encoder interface.

func (UUID) IsZero

func (u UUID) IsZero() bool

IsZero return true if UUID is zero (all bytes are zero).

func (UUID) Nullable

func (u UUID) Nullable() NullUUID

Nullable returns valid NullUUID with UUID u.

func (*UUID) Scan

func (u *UUID) Scan(src interface{}) (err error)

Scan implements the sql.Scanner interface. Can parse:

bytes as raw UUID representations (as-is)
string/bytes as default UUID string representation

func (*UUID) ScanPgx

func (u *UUID) ScanPgx(vr *pgx.ValueReader) error

ScanPgx implements the pgx.PgxScanner interface.

func (UUID) String

func (u UUID) String() string

String returns standard string representation of UUID.

func (UUID) Value

func (u UUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Notes

Bugs

  • ParseInterval may overflow SomeSeconds if computed SomeSeconds should be MinInt64.

  • String may overflow SomeSeconds if SomeSeconds is MinInt64.

Jump to

Keyboard shortcuts

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