common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: Apache-2.0, MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var AggregationTypeMapping = EnumStringMap{
	0: "sum",
	1: "count",
	2: "mean",
	3: "min",
	4: "max",
}

AggregationTypeMapping maps aggregation types to their string representations.

View Source
var BinaryOperatorMapping = EnumStringMap{
	0:  "+",
	1:  "-",
	2:  "*",
	3:  "/",
	4:  "==",
	5:  "!=",
	6:  "<",
	7:  "<=",
	8:  ">",
	9:  ">=",
	10: "&&",
	11: "||",
}

BinaryOperatorMapping maps binary operators to their string representations.

View Source
var EvaluationContextMapping = EnumStringMap{
	0: "RowContext",
	1: "GroupContext",
}

EvaluationContextMapping maps evaluation contexts to their string representations.

View Source
var IntervalTypeMapping = EnumStringMap{
	0: "days",
	1: "hours",
	2: "minutes",
	3: "months",
	4: "years",
}

IntervalTypeMapping maps interval types to their string representations.

View Source
var JoinTypeMapping = EnumStringMap{
	0: "INNER",
	1: "LEFT",
	2: "RIGHT",
	3: "FULL",
}

JoinTypeMapping maps join types to their string representations.

View Source
var OrderDirectionMapping = EnumStringMap{
	0: "ASC",
	1: "DESC",
}

OrderDirectionMapping maps order directions to their string representations.

View Source
var UnaryOperatorMapping = EnumStringMap{
	0: "-",
	1: "!",
}

UnaryOperatorMapping maps unary operators to their string representations.

Functions

func FormatAggregationType

func FormatAggregationType(aggType int) string

FormatAggregationType formats an aggregation type enum value.

func FormatAlias

func FormatAlias(expression, alias string) string

FormatAlias formats a column alias using the default formatter.

func FormatBinaryOperation

func FormatBinaryOperation(left, operator, right string) string

FormatBinaryOperation formats a binary operation using the default formatter.

func FormatBinaryOperator

func FormatBinaryOperator(op int) string

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

func FormatEvaluationContext(context int) string

FormatEvaluationContext formats an evaluation context enum value.

func FormatFieldAccess

func FormatFieldAccess(field string, value interface{}) string

FormatFieldAccess formats a field access using the default formatter.

func FormatFunction

func FormatFunction(name string, args ...string) string

FormatFunction formats a function-like string representation using the default formatter.

func FormatIntervalType

func FormatIntervalType(intervalType int) string

FormatIntervalType formats an interval type enum value.

func FormatJoinType

func FormatJoinType(joinType int) string

FormatJoinType formats a join type enum value.

func FormatOptionalClause

func FormatOptionalClause(clauseName string, content interface{}) string

FormatOptionalClause formats an optional SQL clause using the default formatter.

func FormatOrderDirection

func FormatOrderDirection(direction int) string

FormatOrderDirection formats an order direction enum value.

func FormatSQLClause

func FormatSQLClause(clauseName, content string) string

FormatSQLClause formats a SQL clause using the default formatter.

func FormatUnaryOperation

func FormatUnaryOperation(operator, operand string) string

FormatUnaryOperation formats a unary operation using the default formatter.

func FormatUnaryOperator

func FormatUnaryOperator(op int) string

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

func ParseAggregationType(str string) (int, bool)

ParseAggregationType parses an aggregation type string.

func ParseBinaryOperator

func ParseBinaryOperator(str string) (int, bool)

ParseBinaryOperator parses a binary operator string.

func ParseEvaluationContext

func ParseEvaluationContext(str string) (int, bool)

ParseEvaluationContext parses an evaluation context string.

func ParseIntervalType

func ParseIntervalType(str string) (int, bool)

ParseIntervalType parses an interval type string.

func ParseJoinType

func ParseJoinType(str string) (int, bool)

ParseJoinType parses a join type string.

func ParseOrderDirection

func ParseOrderDirection(str string) (int, bool)

ParseOrderDirection parses an order direction string.

func ParseUnaryOperator

func ParseUnaryOperator(str string) (int, bool)

ParseUnaryOperator parses a unary operator string.

func SafeFloat64ToFloat32

func SafeFloat64ToFloat32(value float64) (float32, error)

SafeFloat64ToFloat32 safely converts float64 to float32 using the default converter.

func SafeInt64ToInt

func SafeInt64ToInt(value int64) (int, error)

SafeInt64ToInt safely converts int64 to int using the default converter.

func ToBool

func ToBool(value interface{}) (bool, error)

ToBool converts various types to bool using the default converter.

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

ToFloat64 converts various types to float64 using the default converter.

func ToInt64

func ToInt64(value interface{}) (int64, error)

ToInt64 converts various types to int64 using the default converter.

func ToString

func ToString(value interface{}) string

ToString converts various types to string 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

type EnumStringMap map[int]string

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.

Jump to

Keyboard shortcuts

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