kind

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package kind encapsulates the notion of data "kind": that is, it is an abstraction over data types across implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector is used to detect the kind of a stream of values. The caller adds values via Sample and then invokes Detect.

func NewDetector

func NewDetector() *Detector

NewDetector returns a new instance.

func (*Detector) Detect

func (d *Detector) Detect() (kind Kind, mungeFn MungeFunc, err error)

Detect returns the detected Kind. If ambiguous, Text is returned, unless all sampled values were nil, in which case Null is returned. If the returned mungeFn is non-nil, it can be used to convert input values to their canonical form. For example, for Datetime the MungeFunc would accept string "2020-06-11T02:50:54Z" and return a time.Time, while for Date, the MungeFunc would accept "1970-01-01" or "01 Jan 1970" and always return a string in the canonicalized form "1970-01-01".

func (*Detector) Sample

func (d *Detector) Sample(v interface{})

Sample adds a sample to the detector.

type Kind

type Kind int

Kind models a generic data kind, which ultimately maps to some more specific implementation data type, such as a SQL VARCHAR or JSON boolean.

const (
	// Unknown indicates an unknown kind.
	Unknown Kind = iota

	// Null indicates a NULL kind.
	Null

	// Text indicates a text kind.
	Text

	// Int indicates an integer kind.
	Int

	// Float indicates a float kind.
	Float

	// Decimal indicates a decimal kind.
	Decimal

	// Bool indicates a boolean kind.
	Bool

	// Bytes indicates a bytes or blob kind.
	Bytes

	// Datetime indicates a date-time kind.
	Datetime

	// Date indicates a date-only kind.
	Date

	// Time indicates a time-only kind.
	Time
)

func (Kind) MarshalJSON

func (k Kind) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Kind) MarshalText

func (k Kind) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Kind) String

func (k Kind) String() string

func (*Kind) UnmarshalText

func (k *Kind) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type MungeFunc

type MungeFunc func(interface{}) (interface{}, error)

MungeFunc is a function that accepts a value and returns a munged value with the appropriate Kind. For example, a Datetime MungeFunc would accept string "2020-06-11T02:50:54Z" and return a time.Time,

Jump to

Keyboard shortcuts

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