pulid

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const EncodedSize = ulid.EncodedSize + 2

EncodedSize is the length of a text encoded PULID.

Variables

This section is empty.

Functions

func MarshalID

func MarshalID(id ID) graphql.Marshaler

MarshalID providers a graphql marshaler for ULIDs.

Types

type ID

type ID struct {
	Prefix string
	ulid.ULID
}

ID - Prefixed ULID. The first two characters indicate the type of entity being described.

func Parse

func Parse(pulid string) (id ID, err error)

Parse returns the string encoding of the PULID.

func UnmarshalID

func UnmarshalID(v interface{}) (id ID, err error)

UnmarshalID unmarshals ULID.

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface by returning the ULID as a byte slice.

func (ID) MarshalBinaryTo

func (id ID) MarshalBinaryTo(dst []byte) error

MarshalBinaryTo writes the binary encoding of the ULID to the given buffer. ErrBufferSize is returned when the len(dst) != 16.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface by returning the string encoded ULID.

func (*ID) Scan

func (id *ID) Scan(src interface{}) error

Scan implements the sql.Scanner interface. It supports scanning a string or byte slice.

func (ID) String

func (id ID) String() string

String returns the string encoding of the PULID.

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface by copying the passed data and converting it to an ULID. ErrDataSize is returned if the data length is different from ULID length.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(v []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface by

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements the sql/driver.Valuer interface. This returns the value represented as a byte slice. If instead a string is desirable, a wrapper type can be created that calls String().

// stringValuer wraps a ULID as a string-based driver.Valuer.
type stringValuer ULID

func (id stringValuer) Value() (driver.Value, error) {
	return ULID(id).String(), nil
}

// Example usage.
db.Exec("...", stringValuer(id))

Jump to

Keyboard shortcuts

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