Documentation
¶
Overview ¶
Package db is an middleware that manages multiple database pools and provides applications with an way to access the database
Index ¶
- Constants
- func GetConnection(c *gin.Context, db string) (*pgxpool.Conn, error)
- func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error)
- type ConnGet
- type Middleware
- func (m *Middleware) AddDB(name, uri string) (err error)
- func (*Middleware) Defaults() middleware.Config
- func (m *Middleware) GetConn(name string) *pgxpool.Conn
- func (m *Middleware) Gin(c *gin.Context)
- func (m *Middleware) PostSetup(sites []any) (err error)
- func (m *Middleware) Setup(mc middleware.Config)
- func (m *Middleware) Teardown()
- type MigrationSite
- type PoolSite
Constants ¶
const ContextKey string = "db"
ContextKey is the key that is used in a gin.Context to get the Middleware
Variables ¶
This section is empty.
Functions ¶
func GetConnection ¶ added in v0.5.5
GetConnection is an simple helper function that returns an connection to the db
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware return a handler that sets the db into the context of every request. uri is an url in the form dbtype:connectargs
func NewMiddleware ¶
func NewMiddleware() *Middleware
NewMiddleware return an initialized Middleware Object.
func (*Middleware) AddDB ¶
func (m *Middleware) AddDB(name, uri string) (err error)
AddDB adds an db connection to the middleware.
func (*Middleware) Defaults ¶
func (*Middleware) Defaults() middleware.Config
Defaults returns an default config for connections
func (*Middleware) GetConn ¶
func (m *Middleware) GetConn(name string) *pgxpool.Conn
GetConn returns a connection from the specified database or if not found one of the default database.
func (*Middleware) PostSetup ¶ added in v0.4.1
func (m *Middleware) PostSetup(sites []any) (err error)
PostSetup is an function for getting the migrations of the site
func (*Middleware) Setup ¶
func (m *Middleware) Setup(mc middleware.Config)
Setup adds the connections from the configfile into the middleware
type MigrationSite ¶
MigrationSite is an interface for Sites that use an database. this enables sites to provide database migrations.
type PoolSite ¶ added in v0.5.4
type PoolSite interface {
MigrationSite
Pool(*pgxpool.Pool)
}
PoolSite is an interface for site that need access to the pool outside of requests