spbc

package module
v0.0.0-...-5fdaa72 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

README

spbc - SQL Protobuf Column

LICENSE goreportcard pkg.go reference go.mod version

spbc is a library for dealing with SQL columns that represent protobuf objects.

Installation

go get github.com/illumitacit/spbc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PBJSON

type PBJSON[T proto.Message] struct {
	Object T
	Valid  bool
}

PBJSON represents a protojson message of a specific type, controlled by the generic type parameter.

Note that this handles NULL in postgres separately from an empty protobuf object. A NULL column value will be represented with a false value for the Valid field.

func NewPBJSON

func NewPBJSON[T proto.Message](o T, valid bool) PBJSON[T]

NewPBJSON creates a new PBJSON object.

func PBJSONFrom

func PBJSONFrom[T proto.Message](o T) PBJSON[T]

PBJSONFrom creates a new PBJSON from a valid protobuf object.

Note that proto.Message is inherently a pointer to a protobuf object and thus can be nil, but golang's type system isn't smart enough to allow nil checks against the generic type since it can't guarantee it's a pointer. As such, we have to resort to a lousy reflect check.

func (PBJSON[T]) IsValid

func (o PBJSON[T]) IsValid() bool

IsValid returns true if this carries an explicit value.

func (PBJSON[T]) MarshalJSON

func (o PBJSON[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (PBJSON[T]) MarshalText

func (o PBJSON[T]) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*PBJSON[T]) Scan

func (o *PBJSON[T]) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (*PBJSON[T]) UnmarshalJSON

func (o *PBJSON[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*PBJSON[T]) UnmarshalText

func (o *PBJSON[T]) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (PBJSON[T]) Value

func (o PBJSON[T]) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type PBO

type PBO[T proto.Message] struct {
	Object T
	Valid  bool
}

PBO represents a protobuf message of a specific type, controlled by the generic type parameter.

Note that this handles NULL in postgres separately from an empty protobuf object. A NULL column value will be represented with a false value for the Valid field.

func NewPBO

func NewPBO[T proto.Message](o T, valid bool) PBO[T]

NewPBO creates a new PBO object.

func PBOFrom

func PBOFrom[T proto.Message](o T) PBO[T]

PBOFrom creates a new PBO from a valid protobuf object.

Note that proto.Message is inherently a pointer to a protobuf object and thus can be nil, but golang's type system isn't smart enough to allow nil checks against the generic type since it can't guarantee it's a pointer. As such, we have to resort to a lousy reflect check.

func (PBO[T]) IsValid

func (o PBO[T]) IsValid() bool

IsValid returns true if this carries an explicit value.

func (PBO[T]) MarshalJSON

func (o PBO[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (PBO[T]) MarshalText

func (o PBO[T]) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*PBO[T]) Scan

func (o *PBO[T]) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (*PBO[T]) UnmarshalJSON

func (o *PBO[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*PBO[T]) UnmarshalText

func (o *PBO[T]) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (PBO[T]) Value

func (o PBO[T]) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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