utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFieldIndexName added in v0.6.0

func GenerateFieldIndexName(tableName, fieldName string) string

GenerateFieldIndexName generates an index name for a single field index

func GenerateIndexName added in v0.6.0

func GenerateIndexName(tableName string, fields []string, unique bool, existingName string) string

GenerateIndexName generates a consistent index name for database indexes If the index already has a name, it returns that name unchanged Otherwise, it generates a name based on the table name and fields

func IsCamelCase

func IsCamelCase(s string) bool

IsCamelCase checks if a string is in camelCase format

func IsPascalCase

func IsPascalCase(s string) bool

IsPascalCase checks if a string is in PascalCase format

func IsSimpleType

func IsSimpleType(t reflect.Type) bool

IsSimpleType checks if a type is a simple type (not struct, slice, etc.)

func IsSnakeCase

func IsSnakeCase(s string) bool

IsSnakeCase checks if a string is in snake_case format

func NormalizeIndexName added in v0.6.0

func NormalizeIndexName(name string) string

NormalizeIndexName normalizes index name for comparison Removes common prefixes and suffixes to allow flexible matching

func Pluralize

func Pluralize(s string) string

Pluralize converts singular to plural (simple version)

func ScanRow

func ScanRow(rows *sql.Rows, dest any) error

ScanRow scans a single row into dest with smart field mapping

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

func ScanRowSimple(row *sql.Row, dest any) error

ScanRowSimple scans a sql.Row into dest (for simple queries)

func ScanRows

func ScanRows(rows *sql.Rows, dest any) error

ScanRows scans multiple rows into a slice with smart field mapping

func ScanRowsToMaps

func ScanRowsToMaps(rows *sql.Rows) ([]map[string]any, error)

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 Singularize

func Singularize(s string) string

Singularize converts plural to singular (simple version)

func ToBool

func ToBool(v any) bool

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 ToCamelCase

func ToCamelCase(s string) string

ToCamelCase converts snake_case to camelCase

func ToFloat32

func ToFloat32(v any) float32

ToFloat32 converts various types to float32 Similar to ToFloat64 but returns float32

func ToFloat64

func ToFloat64(v any) float64

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 ToInt

func ToInt(v any) int

ToInt converts various types to int Similar to ToInt64 but returns int

func ToInt64

func ToInt64(v any) int64

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

func ToInterface(v any) any

ToInterface converts database-specific types to standard Go types Useful for normalizing results from different database drivers

func ToPascalCase

func ToPascalCase(s string) string

ToPascalCase converts string to PascalCase

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts camelCase to snake_case

func ToString

func ToString(v any) string

ToString converts various types to string Handles different database driver representations: - string: direct return - []byte: byte to string conversion - numeric types: formatted conversion - bool: "true" or "false" - nil: ""

Types

This section is empty.

Jump to

Keyboard shortcuts

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