Documentation
¶
Overview ¶
Package common provides shared utilities for string representations and type conversions
Package common provides shared utilities for string formatting, type conversions, and enum handling.
Index ¶
- Variables
- func FormatAggregationType(aggType int) string
- func FormatAlias(expression, alias string) string
- func FormatBinaryOperation(left, operator, right string) string
- func FormatBinaryOperator(op int) string
- func FormatEnum(value int, mapping EnumStringMap) string
- func FormatEvaluationContext(context int) string
- func FormatFieldAccess(field string, value interface{}) string
- func FormatFunction(name string, args ...string) string
- func FormatIntervalType(intervalType int) string
- func FormatJoinType(joinType int) string
- func FormatOptionalClause(clauseName string, content interface{}) string
- func FormatOrderDirection(direction int) string
- func FormatSQLClause(clauseName, content string) string
- func FormatUnaryOperation(operator, operand string) string
- func FormatUnaryOperator(op int) string
- func GetTypeName(value interface{}) string
- func IsFloatType(value interface{}) bool
- func IsIntegerType(value interface{}) bool
- func IsNumericType(value interface{}) bool
- func ParseAggregationType(str string) (int, bool)
- func ParseBinaryOperator(str string) (int, bool)
- func ParseEvaluationContext(str string) (int, bool)
- func ParseIntervalType(str string) (int, bool)
- func ParseJoinType(str string) (int, bool)
- func ParseOrderDirection(str string) (int, bool)
- func ParseUnaryOperator(str string) (int, bool)
- func SafeFloat64ToFloat32(value float64) (float32, error)
- func SafeInt64ToInt(value int64) (int, error)
- func ToBool(value interface{}) (bool, error)
- func ToFloat64(value interface{}) (float64, error)
- func ToInt64(value interface{}) (int64, error)
- func ToString(value interface{}) string
- type EnumRegistry
- type EnumStringMap
- type StringFormatter
- func (sf *StringFormatter) FormatAlias(expression, alias string) string
- func (sf *StringFormatter) FormatBinaryOperation(left, operator, right string) string
- func (sf *StringFormatter) FormatCase(whens []string, elseValue string) string
- func (sf *StringFormatter) FormatEnum(value int, mapping EnumStringMap) string
- func (sf *StringFormatter) FormatFieldAccess(field string, value interface{}) string
- func (sf *StringFormatter) FormatFunction(name string, args ...string) string
- func (sf *StringFormatter) FormatJoin(joinType, table, condition string) string
- func (sf *StringFormatter) FormatList(items []string, separator string) string
- func (sf *StringFormatter) FormatOptionalClause(clauseName string, content interface{}) string
- func (sf *StringFormatter) FormatSQLClause(clauseName, content string) string
- func (sf *StringFormatter) FormatSort(column string, ascending bool) string
- func (sf *StringFormatter) FormatUnaryOperation(operator, operand string) string
- func (sf *StringFormatter) FormatWhen(condition, value string) string
- type StringToEnum
- type TypeConverter
- func (tc *TypeConverter) GetTypeName(value interface{}) string
- func (tc *TypeConverter) IsFloatType(value interface{}) bool
- func (tc *TypeConverter) IsIntegerType(value interface{}) bool
- func (tc *TypeConverter) IsNumericType(value interface{}) bool
- func (tc *TypeConverter) SafeFloat64ToFloat32(value float64) (float32, error)
- func (tc *TypeConverter) SafeInt64ToInt(value int64) (int, error)
- func (tc *TypeConverter) ToBool(value interface{}) (bool, error)
- func (tc *TypeConverter) ToFloat64(value interface{}) (float64, error)
- func (tc *TypeConverter) ToInt64(value interface{}) (int64, error)
- func (tc *TypeConverter) ToString(value interface{}) string
Constants ¶
This section is empty.
Variables ¶
var AggregationTypeMapping = EnumStringMap{
0: "sum",
1: "count",
2: "mean",
3: "min",
4: "max",
}
AggregationTypeMapping maps aggregation types to their string representations.
var BinaryOperatorMapping = EnumStringMap{
0: "+",
1: "-",
2: "*",
3: "/",
4: "==",
5: "!=",
6: "<",
7: "<=",
8: ">",
9: ">=",
10: "&&",
11: "||",
}
BinaryOperatorMapping maps binary operators to their string representations.
var EvaluationContextMapping = EnumStringMap{
0: "RowContext",
1: "GroupContext",
}
EvaluationContextMapping maps evaluation contexts to their string representations.
var IntervalTypeMapping = EnumStringMap{
0: "days",
1: "hours",
2: "minutes",
3: "months",
4: "years",
}
IntervalTypeMapping maps interval types to their string representations.
var JoinTypeMapping = EnumStringMap{
0: "INNER",
1: "LEFT",
2: "RIGHT",
3: "FULL",
}
JoinTypeMapping maps join types to their string representations.
var OrderDirectionMapping = EnumStringMap{
0: "ASC",
1: "DESC",
}
OrderDirectionMapping maps order directions to their string representations.
var UnaryOperatorMapping = EnumStringMap{
0: "-",
1: "!",
}
UnaryOperatorMapping maps unary operators to their string representations.
Functions ¶
func FormatAggregationType ¶
FormatAggregationType formats an aggregation type enum value.
func FormatAlias ¶
FormatAlias formats a column alias using the default formatter.
func FormatBinaryOperation ¶
FormatBinaryOperation formats a binary operation using the default formatter.
func FormatBinaryOperator ¶
FormatBinaryOperator formats a binary operator enum value.
func FormatEnum ¶
func FormatEnum(value int, mapping EnumStringMap) string
FormatEnum formats an enum value using the default formatter.
func FormatEvaluationContext ¶
FormatEvaluationContext formats an evaluation context enum value.
func FormatFieldAccess ¶
FormatFieldAccess formats a field access using the default formatter.
func FormatFunction ¶
FormatFunction formats a function-like string representation using the default formatter.
func FormatIntervalType ¶
FormatIntervalType formats an interval type enum value.
func FormatJoinType ¶
FormatJoinType formats a join type enum value.
func FormatOptionalClause ¶
FormatOptionalClause formats an optional SQL clause using the default formatter.
func FormatOrderDirection ¶
FormatOrderDirection formats an order direction enum value.
func FormatSQLClause ¶
FormatSQLClause formats a SQL clause using the default formatter.
func FormatUnaryOperation ¶
FormatUnaryOperation formats a unary operation using the default formatter.
func FormatUnaryOperator ¶
FormatUnaryOperator formats a unary operator enum value.
func GetTypeName ¶
func GetTypeName(value interface{}) string
GetTypeName returns the type name using the default converter.
func IsFloatType ¶
func IsFloatType(value interface{}) bool
IsFloatType checks if a value is float using the default converter.
func IsIntegerType ¶
func IsIntegerType(value interface{}) bool
IsIntegerType checks if a value is integer using the default converter.
func IsNumericType ¶
func IsNumericType(value interface{}) bool
IsNumericType checks if a value is numeric using the default converter.
func ParseAggregationType ¶
ParseAggregationType parses an aggregation type string.
func ParseBinaryOperator ¶
ParseBinaryOperator parses a binary operator string.
func ParseEvaluationContext ¶
ParseEvaluationContext parses an evaluation context string.
func ParseIntervalType ¶
ParseIntervalType parses an interval type string.
func ParseJoinType ¶
ParseJoinType parses a join type string.
func ParseOrderDirection ¶
ParseOrderDirection parses an order direction string.
func ParseUnaryOperator ¶
ParseUnaryOperator parses a unary operator string.
func SafeFloat64ToFloat32 ¶
SafeFloat64ToFloat32 safely converts float64 to float32 using the default converter.
func SafeInt64ToInt ¶
SafeInt64ToInt safely converts int64 to int using the default converter.
Types ¶
type EnumRegistry ¶
type EnumRegistry struct {
// contains filtered or unexported fields
}
EnumRegistry provides utilities for managing enum string representations.
func NewEnumRegistry ¶
func NewEnumRegistry() *EnumRegistry
NewEnumRegistry creates a new EnumRegistry instance.
func (*EnumRegistry) FormatEnum ¶
func (er *EnumRegistry) FormatEnum(typeName string, value int) string
FormatEnum formats an enum value for a registered type.
func (*EnumRegistry) GetEnumMapping ¶
func (er *EnumRegistry) GetEnumMapping(typeName string) (EnumStringMap, bool)
GetEnumMapping returns the mapping for a registered enum type.
func (*EnumRegistry) RegisterEnum ¶
func (er *EnumRegistry) RegisterEnum(typeName string, mapping EnumStringMap)
RegisterEnum registers an enum type with its string mapping.
type EnumStringMap ¶
EnumStringMap represents a mapping from enum values to string representations.
type StringFormatter ¶
type StringFormatter struct{}
StringFormatter provides common string formatting utilities.
func NewStringFormatter ¶
func NewStringFormatter() *StringFormatter
NewStringFormatter creates a new StringFormatter instance.
func (*StringFormatter) FormatAlias ¶
func (sf *StringFormatter) FormatAlias(expression, alias string) string
FormatAlias formats a column alias.
func (*StringFormatter) FormatBinaryOperation ¶
func (sf *StringFormatter) FormatBinaryOperation(left, operator, right string) string
FormatBinaryOperation formats a binary operation string representation Pattern: (left operator right).
func (*StringFormatter) FormatCase ¶
func (sf *StringFormatter) FormatCase(whens []string, elseValue string) string
FormatCase formats a case expression string representation.
func (*StringFormatter) FormatEnum ¶
func (sf *StringFormatter) FormatEnum(value int, mapping EnumStringMap) string
FormatEnum formats an enum value using the provided mapping.
func (*StringFormatter) FormatFieldAccess ¶
func (sf *StringFormatter) FormatFieldAccess(field string, value interface{}) string
FormatFieldAccess formats a field access string representation Pattern: fieldName(value).
func (*StringFormatter) FormatFunction ¶
func (sf *StringFormatter) FormatFunction(name string, args ...string) string
FormatFunction formats a function-like string representation Pattern: functionName(arg1, arg2, ...)
func (*StringFormatter) FormatJoin ¶
func (sf *StringFormatter) FormatJoin(joinType, table, condition string) string
FormatJoin formats a join clause.
func (*StringFormatter) FormatList ¶
func (sf *StringFormatter) FormatList(items []string, separator string) string
FormatList formats a list of items with separator.
func (*StringFormatter) FormatOptionalClause ¶
func (sf *StringFormatter) FormatOptionalClause(clauseName string, content interface{}) string
FormatOptionalClause formats an optional SQL clause.
func (*StringFormatter) FormatSQLClause ¶
func (sf *StringFormatter) FormatSQLClause(clauseName, content string) string
FormatSQLClause formats a SQL clause string representation Pattern: CLAUSE content.
func (*StringFormatter) FormatSort ¶
func (sf *StringFormatter) FormatSort(column string, ascending bool) string
FormatSort formats a sort specification.
func (*StringFormatter) FormatUnaryOperation ¶
func (sf *StringFormatter) FormatUnaryOperation(operator, operand string) string
FormatUnaryOperation formats a unary operation string representation Pattern: operator(operand).
func (*StringFormatter) FormatWhen ¶
func (sf *StringFormatter) FormatWhen(condition, value string) string
FormatWhen formats a when clause for case expressions.
type StringToEnum ¶
type StringToEnum struct {
// contains filtered or unexported fields
}
StringToEnum provides utilities for parsing enum values from strings.
func NewStringToEnum ¶
func NewStringToEnum() *StringToEnum
NewStringToEnum creates a new StringToEnum instance.
func (*StringToEnum) ParseEnum ¶
func (ste *StringToEnum) ParseEnum(typeName, str string) (int, bool)
ParseEnum parses a string to its enum value.
func (*StringToEnum) RegisterReverseMapping ¶
func (ste *StringToEnum) RegisterReverseMapping(typeName string, mapping EnumStringMap)
RegisterReverseMapping registers a reverse mapping for an enum type.
type TypeConverter ¶
type TypeConverter struct{}
TypeConverter provides common type conversion utilities.
func NewTypeConverter ¶
func NewTypeConverter() *TypeConverter
NewTypeConverter creates a new TypeConverter instance.
func (*TypeConverter) GetTypeName ¶
func (tc *TypeConverter) GetTypeName(value interface{}) string
GetTypeName returns the type name of a value.
func (*TypeConverter) IsFloatType ¶
func (tc *TypeConverter) IsFloatType(value interface{}) bool
IsFloatType checks if a value is of a floating-point type.
func (*TypeConverter) IsIntegerType ¶
func (tc *TypeConverter) IsIntegerType(value interface{}) bool
IsIntegerType checks if a value is of an integer type.
func (*TypeConverter) IsNumericType ¶
func (tc *TypeConverter) IsNumericType(value interface{}) bool
IsNumericType checks if a value is of a numeric type.
func (*TypeConverter) SafeFloat64ToFloat32 ¶
func (tc *TypeConverter) SafeFloat64ToFloat32(value float64) (float32, error)
SafeFloat64ToFloat32 safely converts float64 to float32, checking for overflow.
func (*TypeConverter) SafeInt64ToInt ¶
func (tc *TypeConverter) SafeInt64ToInt(value int64) (int, error)
SafeInt64ToInt safely converts int64 to int, checking for overflow.
func (*TypeConverter) ToBool ¶
func (tc *TypeConverter) ToBool(value interface{}) (bool, error)
ToBool converts various types to bool.
func (*TypeConverter) ToFloat64 ¶
func (tc *TypeConverter) ToFloat64(value interface{}) (float64, error)
ToFloat64 converts various numeric types to float64.
func (*TypeConverter) ToInt64 ¶
func (tc *TypeConverter) ToInt64(value interface{}) (int64, error)
ToInt64 converts various numeric types to int64.
func (*TypeConverter) ToString ¶
func (tc *TypeConverter) ToString(value interface{}) string
ToString converts various types to string.