Documentation ¶
Index ¶
- Constants
- func Apply(transforms ...Transform) schema.ColumnResolver
- func TagNameTransformer(field reflect.StructField) (string, error)
- func TagTypeTransformer(field reflect.StructField) (arrow.DataType, error)
- type Transform
- func AssertType[T any]() Transform
- func DecodeBase64() Transform
- func GetElementAt(n int) Transform
- func GetMapEntry[K comparable, V any](key K) Transform
- func NilIfZero() Transform
- func OnObjectField(path string) Transform
- func OrDefault(value any) Transform
- func RemapValue[K comparable, V any](remap map[K]V) Transform
- func ToBool() Transform
- func ToInt() Transform
- func ToString() Transform
- func TrimString() Transform
Constants ¶
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 ¶
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 ¶
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 ¶
OnObjectField gets the value from a Golang object by extracting the value associated with the field as per the path.
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.