sqlutils

package
v0.0.0-...-5acab9f Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sqlutils contains functionality to wrap existing database functionality

Index

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

type NamedPreparer interface {
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
}

NamedPreparer is an interface used by to execute a sqlx transaction either directly or as a transacation.

type TransactionFunc

type TransactionFunc[T any] func(*sqlx.Tx) (*T, error)

TransactionFunc defines the function signature needed to represent passing a transaction and returning a generic type

type TransactionPreparer

type TransactionPreparer interface {
	Beginx() (*sqlx.Tx, error)
}

TransactionPreparer is an interface used to initiate a sqlx.TX

Jump to

Keyboard shortcuts

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