Documentation ¶
Overview ¶
Package zeronull contains types that automatically convert between database NULLs and Go zero values.
Sometimes the distinction between a zero value and a NULL value is not useful at the application level. For example, in PostgreSQL an empty string may be stored as NULL. There is usually no application level distinction between an empty string and a NULL string. Package zeronull implements types that seamlessly convert between PostgreSQL NULL and the zero value.
It is recommended to convert types at usage time rather than instantiate these types directly. In the example below, middlename would be stored as a NULL.
firstname := "John" middlename := "" lastname := "Smith" _, err := conn.Exec( ctx, "insert into people(firstname, middlename, lastname) values($1, $2, $3)", zeronull.Text(firstname), zeronull.Text(middlename), zeronull.Text(lastname), )
Index ¶
- type Int2
- func (dst *Int2) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Int2) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Int2) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Int2) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Int2) Scan(src interface{}) error
- func (src Int2) Value() (driver.Value, error)
- type Int4
- func (dst *Int4) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Int4) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Int4) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Int4) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Int4) Scan(src interface{}) error
- func (src Int4) Value() (driver.Value, error)
- type Int8
- func (dst *Int8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Int8) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Int8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Int8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Int8) Scan(src interface{}) error
- func (src Int8) Value() (driver.Value, error)
- type Text
- func (dst *Text) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Text) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Text) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Text) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Text) Scan(src interface{}) error
- func (src Text) Value() (driver.Value, error)
- type Timestamp
- func (dst *Timestamp) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Timestamp) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Timestamp) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Timestamp) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Timestamp) Scan(src interface{}) error
- func (src Timestamp) Value() (driver.Value, error)
- type Timestamptz
- func (dst *Timestamptz) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Timestamptz) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Timestamptz) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Timestamptz) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Timestamptz) Scan(src interface{}) error
- func (src Timestamptz) Value() (driver.Value, error)
- type UUID
- func (dst *UUID) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *UUID) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src UUID) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src UUID) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *UUID) Scan(src interface{}) error
- func (src UUID) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Int2 ¶
type Int2 int16
func (Int2) EncodeBinary ¶
func (Int2) EncodeText ¶
type Int4 ¶
type Int4 int32
func (Int4) EncodeBinary ¶
func (Int4) EncodeText ¶
type Int8 ¶
type Int8 int64
func (Int8) EncodeBinary ¶
func (Int8) EncodeText ¶
type Text ¶
type Text string
func (Text) EncodeBinary ¶
func (Text) EncodeText ¶
type Timestamp ¶
func (*Timestamp) DecodeBinary ¶
func (*Timestamp) DecodeText ¶
func (Timestamp) EncodeBinary ¶
func (Timestamp) EncodeText ¶
type Timestamptz ¶
func (*Timestamptz) DecodeBinary ¶
func (dst *Timestamptz) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
func (*Timestamptz) DecodeText ¶
func (dst *Timestamptz) DecodeText(ci *pgtype.ConnInfo, src []byte) error
func (Timestamptz) EncodeBinary ¶
func (Timestamptz) EncodeText ¶
func (*Timestamptz) Scan ¶
func (dst *Timestamptz) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
type UUID ¶
type UUID [16]byte