utils

package
v0.0.0-...-cd37cee Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInsertStmtWithout

func BuildInsertStmtWithout(db *icingadb.DB, into interface{}, withoutColumn string) string

BuildInsertStmtWithout builds an insert stmt without the provided column.

func ForEachRow

func ForEachRow[Row, Id any](ctx context.Context, db *icingadb.DB, idColumn string, ids []Id, restoreFunc func(*Row)) error

ForEachRow applies the provided restoreFunc callback for each successfully retrieved row of the specified type. It will bulk SELECT the data from the database scoped to the specified ids and scans into the provided Row type. Returns error on any database failure or fails to acquire the table semaphore.

func InsertAndFetchId

func InsertAndFetchId(ctx context.Context, tx *sqlx.Tx, stmt string, args any) (int64, error)

InsertAndFetchId executes the given query and fetches the last inserted ID.

func IterateOrderedMap

func IterateOrderedMap[K cmp.Ordered, V any](m map[K]V) func(func(K, V) bool)

IterateOrderedMap implements iter.Seq2 to iterate over a map in the key's order.

This function returns a func yielding key-value-pairs from a given map in the order of their keys, if their type is cmp.Ordered.

Please note that currently - being at Go 1.22 - rangefuncs are still an experimental feature and cannot be directly used unless compiled with `GOEXPERIMENT=rangefunc`. However, they can still be invoked normally. https://go.dev/wiki/RangefuncExperiment

func RemoveIf

func RemoveIf[T any](slice []T, pred func(T) bool) []T

func RemoveNils

func RemoveNils[T any](slice []*T) []*T

func RunInTx

func RunInTx(ctx context.Context, db *icingadb.DB, fn func(tx *sqlx.Tx) error) error

RunInTx allows running a function in a database transaction without requiring manual transaction handling.

A new transaction is started on db which is then passed to fn. After fn returns, the transaction is committed unless an error was returned. If fn returns an error, that error is returned, otherwise an error is returned if a database operation fails.

func ToDBInt

func ToDBInt(value int64) types.Int

ToDBInt transforms the given value to types.Int.

func ToDBString

func ToDBString(value string) types.String

ToDBString transforms the given string to types.String.

Types

This section is empty.

Jump to

Keyboard shortcuts

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