database

package
v0.0.0-...-37076da Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package database contains the database drivers.

Actually, this package implements the DB interface from https://gorm.io

Index

Constants

This section is empty.

Variables

View Source
var ErrCanParseDbInstance = fmt.Errorf("can't parse db instance")

Functions

This section is empty.

Types

type Database

type Database interface {
	// OpenConnection will make a connection to the database.
	//
	// The package database implementations makes a singleton to the connection.
	OpenConnection() error
	// DB returns the gorm.DB instance.
	DB() *gorm.DB
	// contains filtered or unexported methods
}

Database is an abstraction who wraps the gorm.DB.

That wrapper target to extract maximum of code from the gorm.DB.

func NewDatabase

func NewDatabase(dbOptions ...DbOption) Database

type DbOption

type DbOption func(d Database) error

DbOption is a function that sets a database option.

func DatabaseName

func DatabaseName(dbname string) DbOption

DatabaseName will set option dbname for database connection

func DbEntities

func DbEntities(dst ...interface{}) DbOption

DbEntities will set option entities for database connection

NOTE: this option is only for auto migrate.

That will set the entities that will be auto migrated.

func Dialect

func Dialect(dialect func(dsn string) gorm.Dialector) DbOption

Dialect will set option dialect for database connection

func Hostname

func Hostname(hostname string) DbOption

Hostname will set option host for database connection

func Password

func Password(pass string) DbOption

Password will set option password for database connection

func Port

func Port(port string) DbOption

Port will set option port for database connection

func User

func User(user string) DbOption

User will set option user for database connection

Jump to

Keyboard shortcuts

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