db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: AGPL-3.0 Imports: 12 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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 SetupMigrator

func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error)

SetupMigrator sets up the migrator to migrate the database.

Types

type ConnGet

type ConnGet func(string) *pgxpool.Conn

ConnGet is an function that returns an connection instance.

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) Gin

func (m *Middleware) Gin(c *gin.Context)

Gin is the Entrypoint for Gin.

func (*Middleware) Setup

func (m *Middleware) Setup(mc middleware.Config)

Setup adds the connections from the configfile into the middleware

func (*Middleware) Sites

func (m *Middleware) Sites(sites []interface{}) (err error)

Sites is an function for getting the migrations of the site

func (*Middleware) Teardown

func (m *Middleware) Teardown()

Teardown closes the DBConnection

type MigrationSite

type MigrationSite interface {
	Database() string
	Migrations(*pgx.Conn) (*migrate.Migrator, error)
}

MigrationSite is an interface for Sites that use an database. this enables sites to provide database migrations.

Jump to

Keyboard shortcuts

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