transform

package
v0.0.0-...-56951d6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// NameTag is the tag applied to structs fields to specify a column name.
	NameTag = "cq-name"
	// TypeTag is the tag applied to structs fields to specify a column type.
	TypeTag = "cq-type"
)

Variables

This section is empty.

Functions

func Apply

func Apply(transforms ...Transform) schema.ColumnResolver

Apply returns a ColumnResolver that is made up of a sequence of Transforms whose purpose is that of extracting information from the input, changing it along the way and returning the final value to be stored in the database.

func TagNameTransformer

func TagNameTransformer(field reflect.StructField) (string, error)

TagNameTransformer checks if a struct field is annotated with a "cq-name" tag and if so uses its value as the name of the column in the generated schema.

func TagTypeTransformer

func TagTypeTransformer(field reflect.StructField) (arrow.DataType, error)

TagTypeTransformer checks if a struct field is annotated with a "cq-type" tag and if so uses its value as the type of the column in the generated schema.

Types

type Transform

type Transform func(ctx context.Context, meta schema.ClientMeta, r *schema.Resource, c schema.Column, v any) (any, error)

Transform is the type of function that transforms a value into another value.

func AssertType

func AssertType[T any]() Transform

AssertType checks if the input value is of the given (generic) type.

func DecodeBase64

func DecodeBase64() Transform

DecodeBase64 decodes the input value (if it is a string) from base64 and returns it as a string.

func GetElementAt

func GetElementAt(n int) Transform

GetElementAt gets the n-th element from a slice; it returns an error if the value is not an array.

func GetMapEntry

func GetMapEntry[K comparable, V any](key K) Transform

GetMapEntry returns the value associated with the given map key; it assumes that the input value is a map where the key is of type K, and the value is of type V.

func NilIfZero

func NilIfZero() Transform

NilIfZero returns nil if the current value is the zero value of its respective type.

func OnObjectField

func OnObjectField(path string) Transform

OnObjectField gets the value from a Golang object by extracting the value associated with the field as per the path.

func OrDefault

func OrDefault(value any) Transform

OrDefault sets the current value to the given default value if it is nil.

func RemapValue

func RemapValue[K comparable, V any](remap map[K]V) Transform

RemapValue remaps the current value to a different value according to the input map; it can be used to convert e.g. integer values into their string representations.

func ToBool

func ToBool() Transform

ToBool converts the current value into its bool representation.

func ToInt

func ToInt() Transform

ToInt converts the value to an int; numeric types are cast into an int, whereas strings are parsed.

func ToString

func ToString() Transform

ToString converts the current value into its string representation.

func TrimString

func TrimString() Transform

TrimString assumes that the current valule is a string and trims it of its spaces.

Jump to

Keyboard shortcuts

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