tupleconv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: BSD-2-Clause Imports: 9 Imported by: 0

README

Tarantool tuples converter in Go

Go Reference Actions Status Code Coverage

Table of contents

Documentation

Converter

Converter[S,T] converts objects of type S into objects of type T. Converters are basic entities on which mappers are based.
Implementations of some converters are available, for example, converters from strings to golang types.
Usage example:

// Basic converter.
strToBoolConv := tupleconv.MakeStringToBoolConverter()
result, err := strToBoolConv.Convert("true") // true <nil>

// Function based converter.
funcConv := tupleconv.MakeFuncConverter(func(s string) (string, error) {
    return s + " world!", nil
})
result, err = funcConv.Convert("hello") // hello world! <nil>

Note 1: You can use the provided converters.

Note 2: You can create your own converters based on the functions with tupleconv.MakeFuncConverter.

Note 3: You can create your own converters, implementing Converter[S,T] interface.

Mapper

Mapper is an object that converts tuples. It is built using a list of converters.
Usage example:

// Mapper example.
mapper := tupleconv.MakeMapper[string, any]([]tupleconv.Converter[string, any]{
    tupleconv.MakeFuncConverter(func(s string) (any, error) {
        return s + "1", nil
    }),
    tupleconv.MakeFuncConverter(func(s string) (any, error) {
        iVal, err := strconv.Atoi(s)
        if err != nil {
            return nil, errors.New("can't convert")
        }
	return iVal + 1, nil
    }),
})
result, err := mapper.Map([]string{"a", "4"}) // []any{"a1", 5} <nil>
result, err = mapper.Map([]string{"0"}) // []any{"01"} <nil>
// Single mapper example.
toStringMapper := tupleconv.MakeMapper([]tupleconv.Converter[any, string]{}).
        WithDefaultConverter(tupleconv.MakeFuncConverter(
            func(s any) (string, error) {
                return fmt.Sprintln(s), nil
        }),
)
res, err := toStringMapper.Map([]any{1, 2.5, nil}) // ["1\n", "2.5\n", "<nil>\n"] <nil>

Note 1: To create a mapper, an array of converters is needed, each of which transforms a certain type S into type T.

Note 2: To perform tuple mapping, you can use the function Map, which will return control to the calling code upon the first error.

Note 3: You can set a default converter that will be applied if the tuple length exceeds the size of the primary converters list.
For example, if you only set a default converter, Map will work like the map function in functional programming languages.

Note 4: If tuple length is less than converters list length, then only corresponding converters will be applied.

Mappers to tarantool types
Example

For building an array of converters, especially when it comes to conversions to tarantool types, there is a built-in solution.
Let's consider an example:

factory := tupleconv.MakeStringToTTConvFactory().
                WithDecimalSeparators(",.")

spaceFmt := []tupleconv.SpaceField{
    {Type: tupleconv.TypeUnsigned},
    {Type: tupleconv.TypeDouble, IsNullable: true},
    {Type: tupleconv.TypeString},
}

converters, _ := tupleconv.MakeTypeToTTConverters[string](factory, spaceFmt)
mapper := tupleconv.MakeMapper(converters)
result, err := mapper.Map([]string{"1", "-2,2", "some_string"}) // [1, -2.2, "some_string"] <nil>

Note 1: To build an array of converters, the space format and a certain object implementing TTConvFactory are used. Function MakeTypeToTTConverters takes these entities and gives the converters list.

Note 2: TTConvFactory[Type] is capable of building a converter from Type to each tarantool type.

Note 3: There is a basic factory available called StringToTTConvFactory, which is used for conversions from strings to tarantool types.

Note 4: StringToTTConvFactory can be configured with options like WithDecimalSeparators.

String to nullable

When converting nullable types with StringToTTConvFactory, first, an attempt is made to convert to null.

For example, empty string is interpreted like null with default options. If a field has a string type and is nullable, then an empty string will be converted to null during the conversion process, rather than being converted to empty string.

String to any/scalar

When converting to any/scalar with StringToTTConvFactory, by default, an attempt will be made to convert them to the following types, in the following order:

  • number
  • decimal
  • boolean
  • datetime
  • uuid
  • interval
  • string
Customization

TTConvFactory[Type] is an interface that can build a mapper from Type to each tarantool type.
To customize the behavior for specific types, one can inherit from the existing factory and override the necessary methods.
For example, let's make the standard factory for conversion from strings to tarantool types always convert any type to a string:

type customFactory struct {
    tupleconv.StringToTTConvFactory
}

func (f *customFactory) MakeTypeToAnyMapper() tupleconv.Converter[string, any] {
    return tupleconv.MakeFuncConverter(func(s string) (any, error) {
        return s, nil
    })
}

func example() {
    factory := &customFactory{}
    spaceFmt := []tupleconv.SpaceField{{Type: "any"}}
    converters, _ := tupleconv.MakeTypeToTTConverters[string](factory, spaceFmt)

    res, err := converters[0].Convert("12") // "12" <nil>
}

Documentation

Overview

Example (TtEncoder)

Example_ttEncoder demonstrates how to create an encoder, using Mapper with only a default Converter defined.

cleanupTarantool, err := upTarantool()
if err != nil {
	fmt.Println(err)
	return
}
defer cleanupTarantool()

converter := tupleconv.MakeFuncConverter(makeTtEncoder())
tupleEncoder := tupleconv.MakeMapper([]tupleconv.Converter[any, string]{}).
	WithDefaultConverter(converter)

conn, _ := tarantool.Connect(context.Background(), dialer, opts)
defer conn.Close()

req := tarantool.NewSelectRequest("finances")

var tuples [][]any
if err := conn.Do(req).GetTyped(&tuples); err != nil {
	fmt.Printf("can't select tuples: %v\n", err)
	return
}

for _, tuple := range tuples {
	encoded, err := tupleEncoder.Map(tuple)
	if err != nil {
		fmt.Printf("can't encode tuple: %v\n", err)
		return
	}
	fmt.Println(encoded)
}
Output:

[1 14.15 2023-08-30T12:13:00+0000]
[2 193000 2023-08-31T00:00:00 Europe/Paris]
[3 -111111 2023-09-02T00:01:00+0400]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter[S any, T any] interface {
	Convert(src S) (T, error)
}

Converter is a converter from S to T.

Example

ExampleConverter demonstrates the basic usage of the Converter.

// Basic converter.
strToBoolConv := tupleconv.MakeStringToBoolConverter()
result, err := strToBoolConv.Convert("true")
fmt.Println(result, err)

// Function based converter.
funcConv := tupleconv.MakeFuncConverter(func(s string) (string, error) {
	return s + " world!", nil
})
result, err = funcConv.Convert("hello")
fmt.Println(result, err)

var filterConv tupleconv.Converter[string, int64] = filterIntConverter{toFilter: "th"}
result, err = filterConv.Convert("100th")
fmt.Println(result, err)
Output:

true <nil>
hello world! <nil>
100 <nil>

func GetConverterByType

func GetConverterByType[Type any](
	fac TTConvFactory[Type], typ TypeName) (conv Converter[Type, any], err error)

GetConverterByType returns a converter by TTConvFactory and typename.

func MakeSequenceConverter

func MakeSequenceConverter[S any, T any](converters []Converter[S, T]) Converter[S, T]

MakeSequenceConverter makes a sequential Converter from a Converter list.

func MakeTypeToTTConverters

func MakeTypeToTTConverters[Type any](
	fac TTConvFactory[Type],
	spaceFmt []SpaceField) ([]Converter[Type, any], error)

MakeTypeToTTConverters creates list of the converters from Type to tt type by the factory and space format.

type DatetimeToStringConverter

type DatetimeToStringConverter struct{}

DatetimeToStringConverter is a converter from datetime.Datetime to string.

func MakeDatetimeToStringConverter

func MakeDatetimeToStringConverter() DatetimeToStringConverter

MakeDatetimeToStringConverter creates DatetimeToStringConverter.

func (DatetimeToStringConverter) Convert

Convert is the implementation of Converter[datetime.Datetime, string] for DatetimeToStringConverter.

type FuncConverter

type FuncConverter[S any, T any] struct {
	// contains filtered or unexported fields
}

FuncConverter is a function-based Converter.

func MakeFuncConverter

func MakeFuncConverter[S any, T any](convFunc func(S) (T, error)) FuncConverter[S, T]

MakeFuncConverter creates FuncConverter.

func (FuncConverter[S, T]) Convert

func (conv FuncConverter[S, T]) Convert(src S) (T, error)

Convert is the implementation of Converter for FuncConverter.

type IdentityConverter

type IdentityConverter[S any] struct{}

IdentityConverter is a converter from S to any, that doesn't change the input.

func MakeIdentityConverter

func MakeIdentityConverter[S any]() IdentityConverter[S]

MakeIdentityConverter creates IdentityConverter.

func (IdentityConverter[S]) Convert

func (IdentityConverter[S]) Convert(src S) (any, error)

Convert is the implementation of Converter[S, any] for IdentityConverter.

type IntervalToStringConverter

type IntervalToStringConverter struct{}

IntervalToStringConverter is a converter from datetime.Interval to string.

func MakeIntervalToStringConverter

func MakeIntervalToStringConverter() IntervalToStringConverter

MakeIntervalToStringConverter creates IntervalToStringConverter.

func (IntervalToStringConverter) Convert

Convert is the implementation of Converter[datetime.Interval, string] for IntervalToStringConverter.

type Mapper

type Mapper[S any, T any] struct {
	// contains filtered or unexported fields
}

Mapper performs tuple mapping.

Example (BasicMapper)

ExampleMapper_basicMapper demonstrates the basic usage of the Mapper.

// Mapper example.
mapper := tupleconv.MakeMapper[string, any]([]tupleconv.Converter[string, any]{
	tupleconv.MakeFuncConverter(func(s string) (any, error) {
		return s + "1", nil
	}),
	tupleconv.MakeFuncConverter(func(s string) (any, error) {
		iVal, err := strconv.Atoi(s)
		if err != nil {
			return nil, errors.New("can't convert")
		}
		return iVal + 1, nil
	}),
})
result, err := mapper.Map([]string{"a", "4"})
fmt.Println(result, err)

result, err = mapper.Map([]string{"0"})
fmt.Println(result, err)
Output:

[a1 5] <nil>
[01] <nil>
Example (SingleMapper)

ExampleMapper_singleMapper demonstrates the usage of the Mapper with only the default converter.

// Single mapper example.
toStringMapper := tupleconv.MakeMapper([]tupleconv.Converter[any, string]{}).
	WithDefaultConverter(tupleconv.MakeFuncConverter(
		func(s any) (string, error) {
			return fmt.Sprint(s), nil
		}),
	)
res, err := toStringMapper.Map([]any{1, 2.5, nil})
fmt.Println(res, err)
Output:

[1 2.5 <nil>] <nil>

func MakeMapper

func MakeMapper[S any, T any](converters []Converter[S, T]) Mapper[S, T]

MakeMapper creates Mapper.

func (Mapper[S, T]) Map

func (mapper Mapper[S, T]) Map(tuple []S) ([]T, error)

Map maps tuple until the first error.

func (Mapper[S, T]) WithDefaultConverter

func (mapper Mapper[S, T]) WithDefaultConverter(converter Converter[S, T]) Mapper[S, T]

WithDefaultConverter sets defaultConverter.

type SpaceField

type SpaceField struct {
	Id         uint32   `msgpack:"id,omitempty"`
	Name       string   `msgpack:"name"`
	Type       TypeName `msgpack:"type"`
	IsNullable bool     `msgpack:"is_nullable,omitempty"`
}

SpaceField is a space field.

type StringToBinaryConverter

type StringToBinaryConverter struct{}

StringToBinaryConverter is a converter from string to binary.

func MakeStringToBinaryConverter

func MakeStringToBinaryConverter() StringToBinaryConverter

MakeStringToBinaryConverter creates StringToBinaryConverter.

func (StringToBinaryConverter) Convert

func (StringToBinaryConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToBinaryConverter.

type StringToBoolConverter

type StringToBoolConverter struct{}

StringToBoolConverter is a converter from string to bool.

func MakeStringToBoolConverter

func MakeStringToBoolConverter() StringToBoolConverter

MakeStringToBoolConverter creates StringToBoolConverter.

func (StringToBoolConverter) Convert

func (StringToBoolConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToBoolConverter.

type StringToDatetimeConverter

type StringToDatetimeConverter struct{}

StringToDatetimeConverter is a converter from string to datetime.Datetime. Time formats used: - 2006-01-02T15:04:05.999999999-0700 - 2006-01-02T15:04:05.999999999 Europe/Moscow.

func MakeStringToDatetimeConverter

func MakeStringToDatetimeConverter() StringToDatetimeConverter

MakeStringToDatetimeConverter creates StringToDatetimeConverter.

func (StringToDatetimeConverter) Convert

func (StringToDatetimeConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToDatetimeConverter.

type StringToDecimalConverter

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

StringToDecimalConverter is a converter from string to decimal.Decimal.

func MakeStringToDecimalConverter

func MakeStringToDecimalConverter(ignoreChars, decSeparators string) StringToDecimalConverter

MakeStringToDecimalConverter creates StringToDecimalConverter.

func (StringToDecimalConverter) Convert

func (conv StringToDecimalConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToDecimalConverter.

type StringToFloatConverter

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

StringToFloatConverter is a converter from string to float64.

func MakeStringToFloatConverter

func MakeStringToFloatConverter(ignoreChars, decSeparators string) StringToFloatConverter

MakeStringToFloatConverter creates StringToFloatConverter.

func (StringToFloatConverter) Convert

func (conv StringToFloatConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToFloatConverter.

type StringToIntConverter

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

StringToIntConverter is a converter from string to int64.

func MakeStringToIntConverter

func MakeStringToIntConverter(ignoreChars string) StringToIntConverter

MakeStringToIntConverter creates StringToIntConverter.

func (StringToIntConverter) Convert

func (conv StringToIntConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToIntConverter.

type StringToIntervalConverter

type StringToIntervalConverter struct{}

StringToIntervalConverter is a converter from string to datetime.Interval.

func MakeStringToIntervalConverter

func MakeStringToIntervalConverter() StringToIntervalConverter

MakeStringToIntervalConverter creates StringToIntervalConverter.

func (StringToIntervalConverter) Convert

func (StringToIntervalConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToIntervalConverter.

type StringToMapConverter

type StringToMapConverter struct{}

StringToMapConverter is a converter from string to map. Only `json` is supported now.

func MakeStringToMapConverter

func MakeStringToMapConverter() StringToMapConverter

MakeStringToMapConverter creates StringToMapConverter.

func (StringToMapConverter) Convert

func (StringToMapConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToMapConverter.

type StringToNullConverter

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

StringToNullConverter is a converter from string to nil.

func MakeStringToNullConverter

func MakeStringToNullConverter(nullValue string) StringToNullConverter

MakeStringToNullConverter creates StringToNullConverter.

func (StringToNullConverter) Convert

func (conv StringToNullConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToNullConverter.

type StringToSliceConverter

type StringToSliceConverter struct{}

StringToSliceConverter is a converter from string to slice. Only `json` is supported now.

func MakeStringToSliceConverter

func MakeStringToSliceConverter() StringToSliceConverter

MakeStringToSliceConverter creates StringToSliceConverter.

func (StringToSliceConverter) Convert

func (StringToSliceConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToSliceConverter.

type StringToTTConvFactory

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

StringToTTConvFactory is the default TypeToTTConvFactory for strings. To customize the creation of converters, inherit from it and override the necessary methods.

Example

ExampleStringToTTConvFactory demonstrates how to create Converter list for Mapper using helper functions and StringToTTConvFactory.

factory := tupleconv.MakeStringToTTConvFactory().
	WithDecimalSeparators(",.")

spaceFmt := []tupleconv.SpaceField{
	{Type: tupleconv.TypeUnsigned},
	{Type: tupleconv.TypeDouble, IsNullable: true},
	{Type: tupleconv.TypeString},
}

converters, _ := tupleconv.MakeTypeToTTConverters[string](factory, spaceFmt)
mapper := tupleconv.MakeMapper(converters)
result, err := mapper.Map([]string{"1", "-2,2", "some_string"})
fmt.Println(result, err)
Output:

[1 -2.2 some_string] <nil>
Example (ConvertNullable)

ExampleStringToTTConvFactory_convertNullable demonstrates an example of converting a nullable type: an attempt to convert to null will be made before attempting to convert to the main type.

factory := tupleconv.MakeStringToTTConvFactory().
	WithNullValue("2.5")

converters, _ := tupleconv.MakeTypeToTTConverters[string](factory, []tupleconv.SpaceField{
	{Type: tupleconv.TypeDouble, IsNullable: true},
})
fmt.Println(converters[0].Convert("2.5"))
Output:

<nil> <nil>
Example (ManualConverters)

ExampleStringToTTConvFactory_manualConverters demonstrates how to obtain Converter from TTConvFactory for manual Converter list construction.

factory := tupleconv.MakeStringToTTConvFactory().
	WithDecimalSeparators(",.")

fieldTypes := []tupleconv.TypeName{
	tupleconv.TypeUnsigned,
	tupleconv.TypeDouble,
	tupleconv.TypeString,
}

converters := make([]tupleconv.Converter[string, any], 0)
for _, typ := range fieldTypes {
	conv, _ := tupleconv.GetConverterByType[string](factory, typ)
	converters = append(converters, conv)
}

mapper := tupleconv.MakeMapper(converters)
result, err := mapper.Map([]string{"1", "-2,2", "some_string"})
fmt.Println(result, err)
Output:

[1 -2.2 some_string] <nil>

func MakeStringToTTConvFactory

func MakeStringToTTConvFactory() StringToTTConvFactory

MakeStringToTTConvFactory creates StringToTTConvFactory.

func (StringToTTConvFactory) GetAnyConverter

func (fac StringToTTConvFactory) GetAnyConverter() Converter[string, any]

func (StringToTTConvFactory) GetArrayConverter

func (StringToTTConvFactory) GetArrayConverter() Converter[string, any]

func (StringToTTConvFactory) GetBooleanConverter

func (StringToTTConvFactory) GetBooleanConverter() Converter[string, any]

func (StringToTTConvFactory) GetDatetimeConverter

func (StringToTTConvFactory) GetDatetimeConverter() Converter[string, any]

func (StringToTTConvFactory) GetDecimalConverter

func (fac StringToTTConvFactory) GetDecimalConverter() Converter[string, any]

func (StringToTTConvFactory) GetDoubleConverter

func (fac StringToTTConvFactory) GetDoubleConverter() Converter[string, any]

func (StringToTTConvFactory) GetIntegerConverter

func (fac StringToTTConvFactory) GetIntegerConverter() Converter[string, any]

func (StringToTTConvFactory) GetIntervalConverter

func (fac StringToTTConvFactory) GetIntervalConverter() Converter[string, any]

func (StringToTTConvFactory) GetMapConverter

func (StringToTTConvFactory) GetMapConverter() Converter[string, any]

func (StringToTTConvFactory) GetNumberConverter

func (fac StringToTTConvFactory) GetNumberConverter() Converter[string, any]

func (StringToTTConvFactory) GetScalarConverter

func (fac StringToTTConvFactory) GetScalarConverter() Converter[string, any]

func (StringToTTConvFactory) GetStringConverter

func (StringToTTConvFactory) GetStringConverter() Converter[string, any]

func (StringToTTConvFactory) GetUUIDConverter

func (StringToTTConvFactory) GetUUIDConverter() Converter[string, any]

func (StringToTTConvFactory) GetUnsignedConverter

func (fac StringToTTConvFactory) GetUnsignedConverter() Converter[string, any]

func (StringToTTConvFactory) GetVarbinaryConverter

func (StringToTTConvFactory) GetVarbinaryConverter() Converter[string, any]

func (StringToTTConvFactory) MakeNullableConverter

func (fac StringToTTConvFactory) MakeNullableConverter(
	converter Converter[string, any]) Converter[string, any]

func (StringToTTConvFactory) WithDecimalSeparators

func (fac StringToTTConvFactory) WithDecimalSeparators(separators string) StringToTTConvFactory

WithDecimalSeparators sets decimalSeparators.

func (StringToTTConvFactory) WithNullValue

func (fac StringToTTConvFactory) WithNullValue(nullValue string) StringToTTConvFactory

WithNullValue sets nullValue.

func (StringToTTConvFactory) WithThousandSeparators

func (fac StringToTTConvFactory) WithThousandSeparators(
	separators string) StringToTTConvFactory

WithThousandSeparators sets thousandSeparators.

type StringToUIntConverter

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

StringToUIntConverter is a converter from string to uint64.

func MakeStringToUIntConverter

func MakeStringToUIntConverter(ignoreChars string) StringToUIntConverter

MakeStringToUIntConverter creates StringToUIntConverter.

func (StringToUIntConverter) Convert

func (conv StringToUIntConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToUIntConverter.

type StringToUUIDConverter

type StringToUUIDConverter struct{}

StringToUUIDConverter is a converter from string to UUID.

func MakeStringToUUIDConverter

func MakeStringToUUIDConverter() StringToUUIDConverter

MakeStringToUUIDConverter creates StringToUUIDConverter.

func (StringToUUIDConverter) Convert

func (StringToUUIDConverter) Convert(src string) (any, error)

Convert is the implementation of Converter[string, any] for StringToUUIDConverter.

type TTConvFactory

type TTConvFactory[Type any] interface {
	// GetBooleanConverter returns a converter from Type to boolean.
	GetBooleanConverter() Converter[Type, any]

	// GetStringConverter returns a converter from Type to string.
	GetStringConverter() Converter[Type, any]

	// GetUnsignedConverter returns a converter from Type to unsigned.
	GetUnsignedConverter() Converter[Type, any]

	// GetDatetimeConverter returns a converter from Type to datetime.
	GetDatetimeConverter() Converter[Type, any]

	// GetUUIDConverter returns a converter from Type to uuid.
	GetUUIDConverter() Converter[Type, any]

	// GetMapConverter returns a converter from Type to map.
	GetMapConverter() Converter[Type, any]

	// GetArrayConverter returns a converter from Type to array.
	GetArrayConverter() Converter[Type, any]

	// GetVarbinaryConverter returns a converter from Type to varbinary.
	GetVarbinaryConverter() Converter[Type, any]

	// GetDoubleConverter returns a converter from Type to double.
	GetDoubleConverter() Converter[Type, any]

	// GetDecimalConverter returns a converter from Type to decimal.
	GetDecimalConverter() Converter[Type, any]

	// GetIntegerConverter returns a converter from Type to integer.
	GetIntegerConverter() Converter[Type, any]

	// GetNumberConverter returns a converter from Type to number.
	GetNumberConverter() Converter[Type, any]

	// GetAnyConverter returns a converter from Type to any.
	GetAnyConverter() Converter[Type, any]

	// GetScalarConverter returns a converter from Type to scalar.
	GetScalarConverter() Converter[Type, any]

	// GetIntervalConverter returns a converter from Type to interval.
	GetIntervalConverter() Converter[Type, any]

	// MakeNullableConverter extends the incoming converter to a nullable converter.
	MakeNullableConverter(Converter[Type, any]) Converter[Type, any]
}

TTConvFactory is a factory capable of creating converters from Type to tarantool types.

Example (Custom)

ExampleTTConvFactory_custom demonstrates how to customize the behavior of TTConvFactory by inheriting from it and overriding the necessary functions.

facture := &customFactory{}
spaceFmt := []tupleconv.SpaceField{{Type: tupleconv.TypeAny}}
converters, _ := tupleconv.MakeTypeToTTConverters[string](facture, spaceFmt)

res, err := converters[0].Convert("12")
fmt.Println(res, err)
Output:

12 <nil>

type TypeName

type TypeName string

TypeName is the data type for type names.

const (
	TypeBoolean   TypeName = "boolean"
	TypeString    TypeName = "string"
	TypeInteger   TypeName = "integer"
	TypeUnsigned  TypeName = "unsigned"
	TypeDouble    TypeName = "double"
	TypeNumber    TypeName = "number"
	TypeDecimal   TypeName = "decimal"
	TypeDatetime  TypeName = "datetime"
	TypeUUID      TypeName = "uuid"
	TypeArray     TypeName = "array"
	TypeMap       TypeName = "map"
	TypeVarbinary TypeName = "varbinary"
	TypeScalar    TypeName = "scalar"
	TypeAny       TypeName = "any"
	TypeInterval  TypeName = "interval"
)

Types are supported tarantool types.

Jump to

Keyboard shortcuts

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