database

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DialectMysql is the mysql dialect.
	DialectMysql = "mysql"
	// DialectPostgres is the postgres dialect.
	DialectPostgres = "postgres"
)

Variables

This section is empty.

Functions

func EnsureMigrations

func EnsureMigrations(folder string, config Config) (returnErr error)

EnsureMigrations checks which migrations from the given folder need to be executed It performs all missing migrations This implementation does not use an existing db instance since the lock release mechanism in "NewWithDatabaseInstance" is buggy

func MustApplyDatabaseSeed

func MustApplyDatabaseSeed(file string, db *gorm.DB)

MustApplyDatabaseSeed applies all SQL queries from the given file to the currently active database. If any database table besides "schema_migrations" already contains data, the seed file will not be applied.

func SetupGORM

func SetupGORM(config Config, logger observance.Logger) (*gorm.DB, error)

SetupGORM loads the ORM with the given configuration The setup includes sending a ping and creating the database if it didn't exist. A logger will be activated if logLevel is 'debug'.

Types

type Config

type Config struct {
	Dialect  string
	Host     string
	Port     string
	User     string
	Password string
	Name     string
	SSLMode  string // optional, only used for postgres
}

Config holds all configuration values for the DB setup

func (*Config) ConnectionString

func (c *Config) ConnectionString() string

ConnectionString returns a valid string for sql.Open.

func (*Config) MigrationURL

func (c *Config) MigrationURL() string

MigrationURL returns a database URL with database for migrations.

type GormLogrus

type GormLogrus struct {
	observance.Logger
}

GormLogrus is a logrus logger that implements the gorm interface for logging.

func (GormLogrus) Print

func (g GormLogrus) Print(v ...interface{})

Print implements the gorm.LogWriter interface, courtesy of https://gist.github.com/bnadland/2e4287b801a47dcfcc94.

Jump to

Keyboard shortcuts

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