Documentation ¶
Overview ¶
Package sqlutils contains functionality to wrap existing database functionality
Index ¶
- func GetProcedure[T any](np NamedPreparer, sqlQuery string, arg interface{}) (*T, error)
- func SelectProcedure[T any](np NamedPreparer, sqlQuery string, arg interface{}) ([]*T, error)
- func WithTransaction[T any](txPrep TransactionPreparer, txFunc TransactionFunc[T]) (*T, error)
- type NamedPreparer
- type TransactionFunc
- type TransactionPreparer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetProcedure ¶
func GetProcedure[T any](np NamedPreparer, sqlQuery string, arg interface{}) (*T, error)
GetProcedure is a wrapper function that handles the boiler plate of creating and executing a returned object from the database Under the hood, it calls stmt.Get to return an object from the database
func SelectProcedure ¶
func SelectProcedure[T any](np NamedPreparer, sqlQuery string, arg interface{}) ([]*T, error)
SelectProcedure is a wrapper function that handles the boiler plate of creating and executing a returned object from the database Under the hood, it calls stmt.Select to return a collection of objects
func WithTransaction ¶
func WithTransaction[T any](txPrep TransactionPreparer, txFunc TransactionFunc[T]) (*T, error)
WithTransaction is a wrapper function which handles creating, committing or rolling back a transaction If there are any errors when executing the txFunc, the tx is rolled back. Otherwise, the tx is committed.
Types ¶
type NamedPreparer ¶
NamedPreparer is an interface used by to execute a sqlx transaction either directly or as a transacation.
type TransactionFunc ¶
TransactionFunc defines the function signature needed to represent passing a transaction and returning a generic type
type TransactionPreparer ¶
TransactionPreparer is an interface used to initiate a sqlx.TX