typeconv

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBoolConverter

func DefaultBoolConverter(source interface{}) (interface{}, error)

DefaultBoolConverter handles multiple source types for bool target

func DefaultNullTimeConverter

func DefaultNullTimeConverter(source interface{}) (interface{}, error)

DefaultNullTimeConverter handles multiple source types for sql.NullTime target

func DefaultTimeConverter

func DefaultTimeConverter(source interface{}) (interface{}, error)

DefaultTimeConverter handles multiple source types for time.Time target

func Int64ToBool

func Int64ToBool(source interface{}) (interface{}, error)

Int64ToBool converts SQLite integer (0/1) to bool

func Int64ToNullTime

func Int64ToNullTime(source interface{}) (interface{}, error)

Int64ToNullTime converts Unix timestamp (int64) to sql.NullTime

func Int64ToTime

func Int64ToTime(source interface{}) (interface{}, error)

Int64ToTime converts Unix timestamp (int64) to time.Time

func StringToBool

func StringToBool(source interface{}) (interface{}, error)

StringToBool converts string to bool

func StringToNullTime

func StringToNullTime(source interface{}) (interface{}, error)

StringToNullTime converts a string to sql.NullTime

func StringToTime

func StringToTime(source interface{}) (interface{}, error)

StringToTime converts a string to time.Time Tries multiple common formats

func TimeToNullTime

func TimeToNullTime(source interface{}) (interface{}, error)

TimeToNullTime converts time.Time to sql.NullTime

func TimeToTime

func TimeToTime(source interface{}) (interface{}, error)

TimeToTime is a pass-through converter (for completeness)

Types

type ConverterFunc

type ConverterFunc func(source interface{}) (interface{}, error)

ConverterFunc is a function that converts a source value to a target type

type Registry

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

Registry manages type conversions between database types and Go types

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new type converter registry

func (*Registry) Convert

func (r *Registry) Convert(source interface{}, targetType reflect.Type) (interface{}, error)

Convert converts a source value to the target type using registered converters

func (*Registry) CreateScanner

func (r *Registry) CreateScanner(targetType reflect.Type) sql.Scanner

CreateScanner creates a sql.Scanner that can handle conversion to the target type

func (*Registry) NeedsConversion

func (r *Registry) NeedsConversion(sourceType, targetType reflect.Type) bool

NeedsConversion checks if a conversion is needed for the given type pair

func (*Registry) Register

func (r *Registry) Register(sourceType, targetType reflect.Type, converter ConverterFunc)

Register registers a specific converter for a source->target type pair

func (*Registry) RegisterDefault

func (r *Registry) RegisterDefault(targetType reflect.Type, converter ConverterFunc)

RegisterDefault registers a default converter for a target type This converter will be used when no specific converter is found

type TypePair

type TypePair struct {
	Source reflect.Type
	Target reflect.Type
}

TypePair represents a pair of source and target types

Jump to

Keyboard shortcuts

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