Documentation
¶
Overview ¶
Package utils contains some common utilities used by all other packages.
Index ¶
- Constants
- func CloseAndLog(closer Closer)
- func CloseAndLogWithContext(ctx context.Context, closer ContextCloser)
- func HashKey(key []any) string
- func IntersectNonGeneratedColumns(t1, t2 *table.TableInfo) string
- func IntersectNonGeneratedColumnsAsSlice(t1, t2 *table.TableInfo) []string
- func UnhashKeyToString(key string) string
- type Closer
- type ContextCloser
Constants ¶
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 ¶
HashKey is used to convert a composite key into a string so that it can be placed in a map.
func IntersectNonGeneratedColumns ¶
IntersectNonGeneratedColumns returns a string of columns that are in both tables The column names are in backticks and comma separated.
func IntersectNonGeneratedColumnsAsSlice ¶
IntersectNonGeneratedColumnsAsSlice returns a slice of column names that are in both tables
func UnhashKeyToString ¶
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
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.