db

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDBNotFound = errors.New("no db instance in context")
View Source
var ErrUnsupportedDB = errors.New("unsupported db type")

Functions

func BeginTx

func BeginTx(ctx context.Context) context.Context

BeginTx returns a context with a new transaction. If the context already has a db connection instance, it uses that instance. Otherwise, it uses the connection initialized in the package.

Ensure InitializeDB has been called before using this function.

func CloseDB added in v1.0.0

func CloseDB()

CloseDB close a connection to the database (if one exists). It panics if any error occurs.

func FromContext

func FromContext(ctx context.Context) *gorm.DB

FromContext extracts the db connection instance from the given context.

The function panics, if a connection does not exist.

func GetDB

func GetDB() string

GetDB - gets the database type

func GetSQLConf

func GetSQLConf() config.SQLConfig

func GetSQLDB

func GetSQLDB() string

func GetSQLHost

func GetSQLHost() string

func GetSQLPass

func GetSQLPass() string

func GetSQLPort

func GetSQLPort() int32

func GetSQLSSLMode

func GetSQLSSLMode() string

func GetSQLUser

func GetSQLUser() string

func InitializeDB

func InitializeDB(models ...interface{}) error

InitializeDB initializes a connection to the database (if not already done) and ensures it has the latest schema.

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware to auto-inject the db connection instance in a request's context.

Ensure InitializeDB has been called before using this middleware.

func SetPagination

func SetPagination(ctx context.Context, page, pageSize int) context.Context

func WithContext

func WithContext(ctx context.Context) context.Context

WithContext returns a new context with the db connection instance.

Ensure InitializeDB has been called before using this function.

To extract the db connection use the FromContext function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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