database

package
v0.0.0-...-0ae98b0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DsnStringFormat           = "postgres://%s:%s@%s:%s/%s?sslmode=disable&TimeZone=Asia/Kolkata"
	ConfigKeyDatabasePort     = "database.port"
	ConfigKeyDatabaseHost     = "database.host"
	ConfigKeyDatabaseUserName = "database.username"
	ConfigKeyDatabasePassword = "database.password"
	ConfigKeyDatabaseName     = "database.name"
)

Variables

This section is empty.

Functions

func DisconnectDatabase

func DisconnectDatabase()

DisconnectDatabase closes the connection to database.

func GetDatabase

func GetDatabase() *gorm.DB

GetDatabase returns the database instance

func GetTableName

func GetTableName(db *gorm.DB, entityStruct interface{}) (string, error)

func InitDatabase

func InitDatabase()

InitDatabase initializes postgres connection with default yaml configuration keys.

func InitDatabaseWithConfig

func InitDatabaseWithConfig(config Config)

InitDatabaseWithConfig initializes postgres connection with provided configuration.

func SetMaxIdleConnections

func SetMaxIdleConnections(sqlDB *sql.DB, connections int)

func SetMaxOpenConnections

func SetMaxOpenConnections(sqlDB *sql.DB, connections int)

Types

type Config

type Config struct {
	Host               string
	Port               string
	Username           string
	Password           string
	DbName             string
	MaxIdleConnections int
	MaxOpenConnections int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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