utils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package utils contains some common utilities used by all other packages.

Index

Constants

View Source
const (
	PrimaryKeySeparator = "-#-" // used to hash a composite primary key
)

Variables

This section is empty.

Functions

func CloseAndLog added in v0.10.2

func CloseAndLog(closer Closer)

CloseAndLog closes a resource and logs any error. This is useful for defer statements where the error cannot be meaningfully handled except by logging. Example: defer utils.CloseAndLog(db)

func CloseAndLogWithContext added in v0.10.2

func CloseAndLogWithContext(ctx context.Context, closer ContextCloser)

CloseAndLogWithContext closes a resource that requires context and logs any error. This is useful for defer statements on resources like table locks. Example: defer utils.CloseAndLogWithContext(ctx, lock)

func HashKey

func HashKey(key []any) string

HashKey is used to convert a composite key into a string so that it can be placed in a map.

func IntersectNonGeneratedColumns

func IntersectNonGeneratedColumns(t1, t2 *table.TableInfo) string

IntersectNonGeneratedColumns returns a string of columns that are in both tables The column names are in backticks and comma separated.

func IntersectNonGeneratedColumnsAsSlice

func IntersectNonGeneratedColumnsAsSlice(t1, t2 *table.TableInfo) []string

IntersectNonGeneratedColumnsAsSlice returns a slice of column names that are in both tables

func UnhashKeyToString

func UnhashKeyToString(key string) string

UnhashKeyToString converts a hashed key to a string that can be used in a query.

Types

type Closer added in v0.10.2

type Closer interface {
	Close() error
}

Closer is an interface for types that have a Close() method. This is compatible with io.Closer and many other types in the codebase.

type ContextCloser added in v0.10.2

type ContextCloser interface {
	Close(context.Context) error
}

ContextCloser is an interface for types that have a Close(context.Context) method. This is used for resources like table locks that need context for cleanup.

Jump to

Keyboard shortcuts

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