db

package
v0.0.0-...-6899a91 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateDown

func MigrateDown(db *sql.DB, log logrus.FieldLogger) error

MigrateDown run sql-migrate migrations

func MigrateUp

func MigrateUp(db *sql.DB, log logrus.FieldLogger) error

MigrateUp run sql-migrate migrations

func NewDBHandle

func NewDBHandle(dc DatabaseCredentials, logMode bool, log logrus.FieldLogger) (*gorm.DB, error)

NewDBHandle provides the database handle to its callers

func NewFromGormString

func NewFromGormString(connStr string, logMode bool, log logrus.FieldLogger) (*gorm.DB, error)

NewFromGormString creates a gorm db handler from a connection string

Types

type DatabaseCredentials

type DatabaseCredentials struct {
	Readers  []DatabaseInstance `json:"readers"`
	Writers  []DatabaseInstance `json:"writers"`
	Database string             `json:"database"`
	Password string             `json:"password"`
	User     string             `json:"user"`
	Type     string             `json:"type"`
}

DatabaseCredentials credentials

func (*DatabaseCredentials) GetRO

func (dc *DatabaseCredentials) GetRO() (string, error)

GetRO get a read only database

func (*DatabaseCredentials) GetRW

func (dc *DatabaseCredentials) GetRW() (string, error)

GetRW get a read/write database

type DatabaseInstance

type DatabaseInstance struct {
	Port int    `json:"port"`
	Host string `json:"host"`
	Ssl  string `json:"sslmode"`
}

DatabaseInstance host and port

type TransactionManager

type TransactionManager interface {
	DB() *gorm.DB
	Transaction(func(*gorm.DB) error, logrus.FieldLogger) error
}

TransactionManager allows to control a DB transaction

func NewTransactionManager

func NewTransactionManager(db *gorm.DB) TransactionManager

NewTransactionManager returns a new TransactionManager

type Type

type Type string

Type db type

const (
	// PostgreSQL connect string
	PostgreSQL Type = "user=%s password=%s host=%s port=%d DB.name=%s sslmode=%s"

	// PostgreSQLDefaultSslMode default ssl connect string
	PostgreSQLDefaultSslMode = "require"
)

Jump to

Keyboard shortcuts

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