database

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToDatabase

func ConnectToDatabase() (*sql.DB, error)

ConnectToDatabase establishes a connection to a PostgreSQL database. Configures connection pooling and verifies connectivity. Returns the database handle or an error if the connection fails.

func IsDuplicateError added in v1.2.3

func IsDuplicateError(err error) *string

IsDuplicateError checks if the error is a Postgres duplicate entry error (unique_violation). Returns the constraint/field name if duplicate, otherwise nil.

func Transaction added in v1.1.4

func Transaction(database *sql.DB, operation TransactionFunction) (err error)

Transaction executes a database transaction with robust panic handling, consistent timestamps, and enhanced logging for debugging. It returns an error if the transaction fails or panics.

Types

type TransactionFunction added in v1.1.3

type TransactionFunction func(transaction *sql.Tx) error

TransactionFunction defines the signature for the transactional operation. It accepts a transaction and returns an error if the operation fails.

Jump to

Keyboard shortcuts

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