decode

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Implements decoding of Postgres types into Golang, using mappings that are generated from pgtype.

The Decoder provides consistent scanners across pgsink components, ensuring the logical subscription decodes Postgres values into the same types as the import.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unpack added in v0.6.0

func Unpack(dest interface{}) interface{}

Unpack extracts the value from a scanner destination, should it be present. Otherwise we return nil.

Types

type Decoder

type Decoder interface {
	ScannerFor(oid uint32) (scanner Scanner, dest interface{}, err error)
}

func NewDecoder

func NewDecoder(mappings []TypeMapping) Decoder

type Scanner

type Scanner interface {
	// Scan satisfies the sql.Scanner interface, allowing us to pass instances to sql.DB
	// method calls
	Scan(src interface{}) error

	// Value is the common interface to all the pgtype constructs
	pgtype.Value
}

Scanner defines what pgtypes must support to be included in the decoder. It is used to filter available types in the generation of mappings.

type TypeMapping

type TypeMapping struct {
	Name    string      // human recognisable type-name
	OID     uint32      // Postgres type OID
	Scanner Scanner     // scanner for parsing type from database
	Empty   interface{} // Golang empty type produced by the scanner
}

TypeMapping binds a Postgres type, denoted by the name and oid, to a Golang type. It is used as a database scanner, but with a restricted interface that ensures Get()ing the scanned value can return only the type allowed by this mapping.

func (TypeMapping) NewEmpty

func (t TypeMapping) NewEmpty() interface{}

NewEmpty allocates a new destination for a given type-mapping. This can be used with the scanner's AssignTo method to construct results of the correct type.

It will return a handle to the exact type of Empty. This means something like a string will be given as a *string, likewise with *[]string, etc.

func (TypeMapping) NewScanner

func (t TypeMapping) NewScanner() Scanner

NewScanner initialises a new scanner, using the mapping Scanner as a template

type UnregisteredType

type UnregisteredType struct {
	OID uint32
}

UnregisteredType is returned whenever we see a Postgres OID that has no associated type mapping. How we handle this depends on the caller.

func (*UnregisteredType) Error

func (e *UnregisteredType) Error() string

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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