zeronull

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int2

type Int2 int16

func (*Int2) DecodeBinary

func (dst *Int2) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*Int2) DecodeText

func (dst *Int2) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (Int2) EncodeBinary

func (src Int2) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Int2) EncodeText

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

type Int4 int32

func (*Int4) DecodeBinary

func (dst *Int4) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*Int4) DecodeText

func (dst *Int4) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (Int4) EncodeBinary

func (src Int4) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Int4) EncodeText

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

type Int8 int64

func (*Int8) DecodeBinary

func (dst *Int8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*Int8) DecodeText

func (dst *Int8) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (Int8) EncodeBinary

func (src Int8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Int8) EncodeText

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

type Text string

func (*Text) DecodeBinary

func (dst *Text) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*Text) DecodeText

func (dst *Text) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (Text) EncodeBinary

func (src Text) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Text) EncodeText

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

type Timestamp time.Time

func (*Timestamp) DecodeBinary

func (dst *Timestamp) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*Timestamp) DecodeText

func (dst *Timestamp) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (Timestamp) EncodeBinary

func (src Timestamp) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Timestamp) EncodeText

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

type Timestamptz time.Time

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 (src Timestamptz) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (Timestamptz) EncodeText

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

type UUID [16]byte

func (*UUID) DecodeBinary

func (dst *UUID) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

func (*UUID) DecodeText

func (dst *UUID) DecodeText(ci *pgtype.ConnInfo, src []byte) error

func (UUID) EncodeBinary

func (src UUID) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

func (UUID) EncodeText

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.

Jump to

Keyboard shortcuts

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