database

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const RequestDefaultDbKey context.RequestKey = "DefaultDb"

Variables

View Source
var (
	ErrorMissingInstance = fmt.Errorf("missing database instance")
)
View Source
var (
	Instance *gorm.DB = nil
)

Functions

func Connect

func Connect(dbType, dsn string) (err error)

Connect opens a new database connection and stores it in a package instance for further use with the Get and MustGet functions

func Get

func Get() (db *gorm.DB, err error)

Get returns the package instance connection or a "missing database instance" error

func GetRequestDB

func GetRequestDB(tag string, r *http.Request) (db interface{})

func GetRequestDefaultDB

func GetRequestDefaultDB(r *http.Request) (db interface{})

func GetRequestSpecificDB

func GetRequestSpecificDB(fTag feature.Tag, tag string, r *http.Request) (db interface{})

func MakeRequestDbKey

func MakeRequestDbKey(tag string) (key context.RequestKey)

func MakeRequestDbSpecificKeys

func MakeRequestDbSpecificKeys(fTag feature.Tag, tag string) (tagKey, specificKey context.RequestKey)

func MustGet

func MustGet() (db *gorm.DB)

MustGet returns the package instance connection or panics with a log.FatalF call

func New

func New(dbType, dsn string) (db *gorm.DB, err error)

New returns a newly opened database connection with inherited log settings

func NewWithLoggerConfig

func NewWithLoggerConfig(dbType, dsn string, config logger.Config) (db *gorm.DB, err error)

NewWithLoggerConfig returns a newly opened database connection using the given logger.Config

Types

This section is empty.

Jump to

Keyboard shortcuts

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