Package zeronull
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),
)
- type Float8
- func (dst *Float8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
- func (dst *Float8) DecodeText(ci *pgtype.ConnInfo, src []byte) error
- func (src Float8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (src Float8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
- func (dst *Float8) Scan(src interface{}) error
- func (src Float8) Value() (driver.Value, error)
- 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)
Package files
doc.go
float8.go
int2.go
int4.go
int8.go
text.go
timestamp.go
timestamptz.go
uuid.go
type Float8 float64
func (dst *Float8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error
func (dst *Float8) DecodeText(ci *pgtype.ConnInfo, src []byte) error
func (src Float8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
func (src Float8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)
func (*Float8) Scan
¶
func (dst *Float8) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Float8) Value
¶
func (src Float8) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int2 int16
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 (*Int2) Scan
¶
func (dst *Int2) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Int2) Value
¶
func (src Int2) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int4 int32
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 (*Int4) Scan
¶
func (dst *Int4) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Int4) Value
¶
func (src Int4) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Int8 int64
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 (*Int8) Scan
¶
func (dst *Int8) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Int8) Value
¶
func (src Int8) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Text string
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 (*Text) Scan
¶
func (dst *Text) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Text) Value
¶
func (src Text) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Timestamp time.Time
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 (*Timestamp) Scan
¶
func (dst *Timestamp) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Timestamp) Value
¶
func (src Timestamp) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type Timestamptz time.Time
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 (*Timestamptz) Scan
¶
func (dst *Timestamptz) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (Timestamptz) Value
¶
func (src Timestamptz) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.
type UUID [16]byte
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 (*UUID) Scan
¶
func (dst *UUID) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
func (UUID) Value
¶
func (src UUID) Value() (driver.Value, error)
Value implements the database/sql/driver Valuer interface.