csql

package
v0.0.0-...-5538d7f Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Fx module that provides a connection to a Postgres DB using GORM. It also provides a middleware to wrap http requests into db transactions.

Functions

func GetConn

func GetConn(ctx context.Context, db *gorm.DB) *gorm.DB

GetConn returns a db connection from the context or the given default connection if context is empty.

func NewDBTxnMiddleware

func NewDBTxnMiddleware(db *gorm.DB, logger clogger.Logger) chttp.MiddlewareFunc

func NewDBTxnMiddlewareFx

func NewDBTxnMiddlewareFx(db *gorm.DB, logger clogger.Logger) chttp.GlobalMiddlewareFuncResult

func NewGormDB

func NewGormDB(p GormDBParams) (*gorm.DB, error)

Types

type Config

type Config struct {
	Host     string
	Port     uint
	Name     string
	User     string
	Password string
}

Config holds the parameters to connect to a Postgres database

type DBTxnMiddleware

type DBTxnMiddleware interface {
	WrapInTxn(next http.Handler) http.Handler
}

DBTxnMiddleware provides a middleware that wraps the http request in a database transaction. If the response status code is between 100-399, the transaction is committed, else a rollback is performed.

type GormDBParams

type GormDBParams struct {
	fx.In

	Config    Config
	Logger    clogger.Logger
	Lifecycle fx.Lifecycle `optional:"true"`
}

Jump to

Keyboard shortcuts

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