Documentation
¶
Index ¶
- func IsCamelCase(s string) bool
- func IsPascalCase(s string) bool
- func IsSimpleType(t reflect.Type) bool
- func IsSnakeCase(s string) bool
- func LogCommand(command string, duration time.Duration)
- func LogDebug(format string, args ...any)
- func LogError(format string, args ...any)
- func LogInfo(format string, args ...any)
- func LogSQL(sql string, args []any, duration time.Duration)
- func LogWarn(format string, args ...any)
- func Pluralize(s string) string
- func ScanRow(rows *sql.Rows, dest any) error
- func ScanRowContext(db interface{ ... }, ctx context.Context, query string, args []any, dest any) error
- func ScanRowSimple(row *sql.Row, dest any) error
- func ScanRows(rows *sql.Rows, dest any) error
- func ScanRowsToMaps(rows *sql.Rows) ([]map[string]any, error)
- func SetGlobalLogger(logger Logger)
- func Singularize(s string) string
- func ToBool(v any) bool
- func ToCamelCase(s string) string
- func ToFloat32(v any) float32
- func ToFloat64(v any) float64
- func ToInt(v any) int
- func ToInt64(v any) int64
- func ToInterface(v any) any
- func ToPascalCase(s string) string
- func ToSnakeCase(s string) string
- func ToString(v any) string
- type DefaultLogger
- func (l *DefaultLogger) Debug(format string, args ...any)
- func (l *DefaultLogger) Error(format string, args ...any)
- func (l *DefaultLogger) Info(format string, args ...any)
- func (l *DefaultLogger) LogCommand(command string, duration time.Duration)
- func (l *DefaultLogger) LogSQL(sql string, args []any, duration time.Duration)
- func (l *DefaultLogger) SetLevel(level LogLevel)
- func (l *DefaultLogger) SetOutput(w io.Writer)
- func (l *DefaultLogger) Warn(format string, args ...any)
- type LogLevel
- type Logger
- type NullLogger
- func (n *NullLogger) Debug(format string, args ...any)
- func (n *NullLogger) Error(format string, args ...any)
- func (n *NullLogger) Info(format string, args ...any)
- func (n *NullLogger) LogCommand(command string, duration time.Duration)
- func (n *NullLogger) LogSQL(sql string, args []any, duration time.Duration)
- func (n *NullLogger) SetLevel(level LogLevel)
- func (n *NullLogger) SetOutput(w io.Writer)
- func (n *NullLogger) Warn(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCamelCase ¶
IsCamelCase checks if a string is in camelCase format
func IsPascalCase ¶
IsPascalCase checks if a string is in PascalCase format
func IsSimpleType ¶
IsSimpleType checks if a type is a simple type (not struct, slice, etc.)
func IsSnakeCase ¶
IsSnakeCase checks if a string is in snake_case format
func LogCommand ¶ added in v0.4.0
func ScanRowContext ¶
func ScanRowContext(db interface {
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
},
ctx context.Context, query string, args []any, dest any) error
ScanRowContext handles scanning from QueryRowContext for both simple and complex types
func ScanRowSimple ¶
ScanRowSimple scans a sql.Row into dest (for simple queries)
func ScanRowsToMaps ¶
ScanRowsToMaps scans SQL rows into a slice of maps This is useful for raw queries where the result structure is not known at compile time
func SetGlobalLogger ¶ added in v0.4.0
func SetGlobalLogger(logger Logger)
SetGlobalLogger sets the global logger
func Singularize ¶
Singularize converts plural to singular (simple version)
func ToBool ¶
ToBool converts various types to bool Handles different database driver representations: - bool: direct conversion - int/int64: 0 = false, non-zero = true - string: "true"/"1" = true, "false"/"0" = false - nil: false
func ToFloat32 ¶
ToFloat32 converts various types to float32 Similar to ToFloat64 but returns float32
func ToFloat64 ¶
ToFloat64 converts various types to float64 Handles different database driver representations: - float32/float64: direct conversion - int/int32/int64: conversion - string: parsing - bool: true = 1.0, false = 0.0 - nil: 0.0
func ToInt64 ¶
ToInt64 converts various types to int64 Handles different database driver representations: - int/int32/int64: direct conversion - uint/uint32/uint64: conversion with bounds checking - float32/float64: truncation - string: parsing - bool: true = 1, false = 0 - nil: 0
func ToInterface ¶
ToInterface converts database-specific types to standard Go types Useful for normalizing results from different database drivers
Types ¶
type DefaultLogger ¶ added in v0.4.0
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger is the default logger implementation
func NewDefaultLogger ¶ added in v0.4.0
func NewDefaultLogger(prefix string) *DefaultLogger
NewDefaultLogger creates a new default logger
func (*DefaultLogger) Debug ¶ added in v0.4.0
func (l *DefaultLogger) Debug(format string, args ...any)
Debug logs a debug message
func (*DefaultLogger) Error ¶ added in v0.4.0
func (l *DefaultLogger) Error(format string, args ...any)
Error logs an error message
func (*DefaultLogger) Info ¶ added in v0.4.0
func (l *DefaultLogger) Info(format string, args ...any)
Info logs an info message
func (*DefaultLogger) LogCommand ¶ added in v0.4.0
func (l *DefaultLogger) LogCommand(command string, duration time.Duration)
LogCommand logs a command (like MongoDB commands) with duration
func (*DefaultLogger) LogSQL ¶ added in v0.4.0
func (l *DefaultLogger) LogSQL(sql string, args []any, duration time.Duration)
LogSQL logs SQL query with parameters and duration
func (*DefaultLogger) SetLevel ¶ added in v0.4.0
func (l *DefaultLogger) SetLevel(level LogLevel)
SetLevel sets the logging level
func (*DefaultLogger) SetOutput ¶ added in v0.4.0
func (l *DefaultLogger) SetOutput(w io.Writer)
SetOutput sets the output writer
func (*DefaultLogger) Warn ¶ added in v0.4.0
func (l *DefaultLogger) Warn(format string, args ...any)
Warn logs a warning message
type Logger ¶ added in v0.4.0
type Logger interface {
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
// SQL/Command specific logging
LogSQL(sql string, args []any, duration time.Duration)
LogCommand(command string, duration time.Duration)
// Configuration
SetLevel(level LogLevel)
SetOutput(w io.Writer)
}
Logger interface defines logging methods
func GetGlobalLogger ¶ added in v0.4.0
func GetGlobalLogger() Logger
GetGlobalLogger returns the global logger
type NullLogger ¶ added in v0.4.0
type NullLogger struct{}
NullLogger is a logger that does nothing
func (*NullLogger) Debug ¶ added in v0.4.0
func (n *NullLogger) Debug(format string, args ...any)
func (*NullLogger) Error ¶ added in v0.4.0
func (n *NullLogger) Error(format string, args ...any)
func (*NullLogger) Info ¶ added in v0.4.0
func (n *NullLogger) Info(format string, args ...any)
func (*NullLogger) LogCommand ¶ added in v0.4.0
func (n *NullLogger) LogCommand(command string, duration time.Duration)
func (*NullLogger) LogSQL ¶ added in v0.4.0
func (n *NullLogger) LogSQL(sql string, args []any, duration time.Duration)
func (*NullLogger) SetLevel ¶ added in v0.4.0
func (n *NullLogger) SetLevel(level LogLevel)
func (*NullLogger) SetOutput ¶ added in v0.4.0
func (n *NullLogger) SetOutput(w io.Writer)
func (*NullLogger) Warn ¶ added in v0.4.0
func (n *NullLogger) Warn(format string, args ...any)