database

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 15 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 Close

func Close(db *gorm.DB) error

Close closes the database connection(s) used by GORM.

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, excludedTables ...[]string)

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. The third argument is optional and can be used to exclude tables from checking whether data is already seeded or not.

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

func (c *Config) Driver() gorm.Dialector

Driver selects the correct DB driver and passes the connection details (DSN). It does not yet open a database connection.

func (*Config) MigrationURL

func (c *Config) MigrationURL() string

MigrationURL returns a database URL with database for migrations.

type GormWriter

type GormWriter struct {
	observance.Logger
}

GormWriter implements the Writer interface for setting up the GORM logger.

func (GormWriter) Printf

func (g GormWriter) Printf(msg string, data ...interface{})

Printf writes a log entry.

Jump to

Keyboard shortcuts

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