Documentation
¶
Index ¶
- func BuildInsertStmtWithout(db *database.DB, into interface{}, withoutColumn string) string
- func ExecAndApply[Row any](ctx context.Context, db *database.DB, stmt string, args []interface{}, ...) error
- func ForEachRow[Row, Id any](ctx context.Context, db *database.DB, idColumn string, ids []Id, ...) error
- func InsertAndFetchId(ctx context.Context, tx *sqlx.Tx, stmt string, args any) (int64, error)
- func IterateOrderedMap[K cmp.Ordered, V any](m map[K]V) func(func(K, V) bool)
- func RunInTx(ctx context.Context, db *database.DB, fn func(tx *sqlx.Tx) error) error
- func ToDBInt(value int64) types.Int
- func ToDBString(value string) types.String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildInsertStmtWithout ¶
BuildInsertStmtWithout builds an insert stmt without the provided column.
func ExecAndApply ¶
func ExecAndApply[Row any](ctx context.Context, db *database.DB, stmt string, args []interface{}, restoreFunc func(*Row)) error
ExecAndApply applies the provided restoreFunc callback for each successfully retrieved row of the specified type. Returns error on any database failure or fails to acquire the table semaphore.
func ForEachRow ¶
func ForEachRow[Row, Id any](ctx context.Context, db *database.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 ¶
InsertAndFetchId executes the given query and fetches the last inserted ID.
func IterateOrderedMap ¶
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 RunInTx ¶
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 ToDBString ¶
ToDBString transforms the given string to types.String.
Types ¶
This section is empty.