Documentation
¶
Overview ¶
Package utils provides utility functions for pgcopy
Index ¶
- Constants
- Variables
- func Colorize(color, text string) string
- func ExtractConnectionDetails(connStr string) string
- func FormatDuration(d time.Duration) string
- func FormatLogDuration(d time.Duration) string
- func FormatLogLevel(level string) string
- func FormatNumber(n int64) string
- func HighlightFKName(fkName string) string
- func HighlightNumber(number any) string
- func HighlightTableName(schema, table string) string
- func IsColorSupported() bool
- func MaskPassword(connStr string) string
- func MatchesAnyPattern(text string, patterns []string) bool
- func MatchesAnyTablePattern(schema, table string, patterns []string) bool
- func MatchesPattern(text, pattern string) bool
- func MatchesTablePattern(schema, table, pattern string) bool
- func QuoteIdent(s string) string
- func QuoteJoinIdents(cols []string) string
- func QuoteLiteral(s string) string
- func QuoteTable(schema, table string) string
- type LogLevel
- type Logger
- type SimpleLogger
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorMagenta = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" ColorBold = "\033[1m" ColorDim = "\033[2m" )
ANSI color codes
Variables ¶
var ( // ErrCanceled indicates the operation was canceled (typically via context cancellation). ErrCanceled = errors.New("operation canceled") // ErrDeadlineExceeded indicates the operation exceeded its deadline (context timeout). ErrDeadlineExceeded = errors.New("deadline exceeded") // ErrInvalidConfig indicates invalid or inconsistent configuration values. ErrInvalidConfig = errors.New("invalid configuration") // ErrCopyFailures aggregates one or more errors that occurred during copy operations. ErrCopyFailures = errors.New("one or more copy operations failed") // ErrFKBackupExists indicates an FK backup file exists from a previous run and needs attention. ErrFKBackupExists = errors.New("foreign key backup file exists") // ErrFKRecoveryFailed indicates attempts to recover FKs from the backup file encountered errors. ErrFKRecoveryFailed = errors.New("foreign key backup recovery failed") )
Functions ¶
func ExtractConnectionDetails ¶ added in v0.3.0
ExtractConnectionDetails extracts clean postgres://server:port/database information from a connection string Removes credentials for safe display
func FormatDuration ¶
FormatDuration formats a duration without decimal parts
func FormatLogDuration ¶
FormatLogDuration formats duration for log files with rounded values
func FormatLogLevel ¶
FormatLogLevel formats log levels with colors and icons
func FormatNumber ¶
FormatNumber formats large numbers with K/M suffixes
func HighlightFKName ¶
HighlightFKName highlights foreign key constraint names
func HighlightNumber ¶
HighlightNumber highlights numbers in brackets and standalone numbers
func HighlightTableName ¶
HighlightTableName highlights table names in log messages
func IsColorSupported ¶
func IsColorSupported() bool
IsColorSupported checks if the terminal supports colors
func MaskPassword ¶ added in v0.3.0
MaskPassword masks password in PostgreSQL connection strings for safe display
func MatchesAnyPattern ¶
MatchesAnyPattern checks if a string matches any of the given patterns
func MatchesAnyTablePattern ¶ added in v0.5.0
MatchesAnyTablePattern returns true if any pattern matches either table or schema.table.
func MatchesPattern ¶
MatchesPattern checks if a string matches a wildcard pattern Supports * wildcard for matching any sequence of characters
func MatchesTablePattern ¶ added in v0.5.0
MatchesTablePattern checks if a pattern matches either the simple table name or the fully-qualified name schema.table. Patterns support * wildcards. Examples:
users -> matches table name "users" public.users -> matches full name "public.users" public.* -> matches any table in schema public *.users -> matches table "users" in any schema
func QuoteIdent ¶ added in v0.5.0
QuoteIdent returns a PostgreSQL-quoted identifier with embedded quotes escaped. Example: My"Tbl -> "My""Tbl"
func QuoteJoinIdents ¶ added in v0.5.0
QuoteJoinIdents quotes each identifier and joins them with comma+space.
func QuoteLiteral ¶ added in v0.5.0
QuoteLiteral returns a single-quoted SQL string literal with embedded quotes escaped.
func QuoteTable ¶ added in v0.5.0
QuoteTable returns a fully-qualified, quoted table name: "schema"."table".
Types ¶
type Logger ¶
type Logger interface {
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
}
Logger interface for colorized logging
type SimpleLogger ¶
type SimpleLogger struct {
// contains filtered or unexported fields
}
SimpleLogger provides basic logging functionality
func NewSilentLogger ¶
func NewSilentLogger() *SimpleLogger
NewSilentLogger creates a new silent logger that suppresses all output
func NewSimpleLogger ¶
func NewSimpleLogger(logger *log.Logger) *SimpleLogger
NewSimpleLogger creates a new simple logger
func (*SimpleLogger) Debug ¶ added in v0.4.0
func (l *SimpleLogger) Debug(format string, args ...any)
Debug logs verbose diagnostic information.
func (*SimpleLogger) Error ¶ added in v0.4.0
func (l *SimpleLogger) Error(format string, args ...any)
Error logs errors.
func (*SimpleLogger) Info ¶ added in v0.4.0
func (l *SimpleLogger) Info(format string, args ...any)
Info logs informational messages (general progress).
func (*SimpleLogger) Warn ¶ added in v0.4.0
func (l *SimpleLogger) Warn(format string, args ...any)
Warn logs warnings.