conn

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

README

api/sinks/postgres/conn

Manages the PostgreSQL connection pool for the rest of the database layer. Builds a connection URL from the config, auto-creates the target database if it does not yet exist by briefly connecting to the default postgres database, then opens a pgxpool connection pool. The pool is used by all concurrent request handlers without contention.

The connection is distributed to route handlers via Gin middleware: the middleware stores the pool in each request's context, and a pair of context-based accessors allow handlers to retrieve it — one that panics on error (for cases where a missing connection is always a programming error) and one that returns an error explicitly.

Documentation

Overview

Package conn handles the initialization and distribution of the database connection object. You probably want to run conn.Get()

Index

Constants

View Source
const DBKey string = "db-object"

DBKey is the key used to store the database object in the request context.

Variables

This section is empty.

Functions

func DBMiddleware

func DBMiddleware(c *gin.Context)

Middleware stores the database connection object in the gin context. This can be retrieved as necessary by routes.

func Get

func Get(c *gin.Context) *pgxpool.Pool

Get returns the database object stored in the request context. Panics on error.

func GetE

func GetE(c *gin.Context) (*pgxpool.Pool, error)

GetE returns the database object stored in the request context.

func InitDBConnection

func InitDBConnection(ctx context.Context, cfg *config.PGConfig) (*pgxpool.Pool, error)

InitDBConnection connects to the database and changes some of the driver settings. It requires that the config be loaded before running.

Types

This section is empty.

Jump to

Keyboard shortcuts

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