typing

package
v0.0.0-...-8aeb8a1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTypes = map[string]DataType{
		timestamp.Key:               TIMESTAMP,
		"eventn_ctx_utc_time":       TIMESTAMP,
		"eventn_ctx_interval_start": TIMESTAMP,
		"eventn_ctx_interval_end":   TIMESTAMP,
		"utc_time":                  TIMESTAMP,
		"interval_start":            TIMESTAMP,
		"interval_end":              TIMESTAMP,
	}
)

Typecast tree

 STRING(4)
/      \

FLOAT64(3) TIMESTAMP(5)

  |
INT64(2)
  |
BOOL(1)

Functions

func Convert

func Convert(toType DataType, v interface{}) (interface{}, error)

Convert returns converted into toType value or error if occurred

func IsConvertible

func IsConvertible(from DataType, to DataType) bool

IsConvertible returns false if there isn't any rule for converting from DataType into to DataType

func ParseTimestamp

func ParseTimestamp(rawTimestamp interface{}) (time.Time, error)

func ReformatNumberValue

func ReformatNumberValue(v interface{}) interface{}

ReformatNumberValue process json.Number types into int64 or float64 note: json.Unmarshal returns json.Number type that can be int or float

we have to check does json number have dot in string representation

if have -> return float64 otherwise int64

func ReformatTimeValue

func ReformatTimeValue(value interface{}) interface{}

ReformatTimeValue processes string with ISO DateTime or Golang layout into time.Time

func ReformatValue

func ReformatValue(v interface{}) interface{}

ReformatNumberValue process json.Number types into int64 or float64 processes string with ISO DateTime or Golang layout into time.Time note: json.Unmarshal returns json.Number type that can be int or float

we have to check does json number have dot in string representation

if have -> return float64 otherwise int64

func StringFromType

func StringFromType(dataType DataType) (string, error)

StringFromType returns string representation of DataType or error if mapping doesn't exist

func StringToFloat

func StringToFloat(v interface{}) (interface{}, error)

StringToFloat return float64 value from string or error if unconvertable

func StringToInt

func StringToInt(v interface{}) (interface{}, error)

StringToInt returns int representation of input string or error if unconvertable

func StringWithCommasToFloat

func StringWithCommasToFloat(v interface{}) (interface{}, error)

StringWithCommasToFloat return float64 value from string (1,200.50)

Types

type ConvertFunc

type ConvertFunc func(v interface{}) (interface{}, error)

ConvertFunc is a function for a certain DataType conversion

type DataType

type DataType int

DataType is a type representation of common data types

const (

	//UNKNOWN type for error cases
	UNKNOWN DataType = iota
	//BOOL type for boolean values
	BOOL
	//INT64 type for int values
	INT64
	//FLOAT64 type for float values
	FLOAT64
	//STRING type for string values
	STRING
	//TIMESTAMP type for string values that match timestamp pattern
	TIMESTAMP
)

func DataTypePtr

func DataTypePtr(dt DataType) *DataType

func GetCommonAncestorType

func GetCommonAncestorType(t1, t2 DataType) DataType

GetCommonAncestorType returns lowest common ancestor type

func TypeFromString

func TypeFromString(t string) (DataType, error)

TypeFromString returns DataType from input string or error if mapping doesn't exist

func TypeFromValue

func TypeFromValue(v interface{}) (DataType, error)

TypeFromValue return DataType from v type

func (DataType) String

func (dt DataType) String() string

type SQLColumn

type SQLColumn struct {
	Type       string
	ColumnType string
	Override   bool
}

func (SQLColumn) DDLType

func (c SQLColumn) DDLType() string

type SQLTypes

type SQLTypes map[string]SQLColumn

Jump to

Keyboard shortcuts

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