gousupostgres

package module
v2.0.0-...-b942c1c Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 8 Imported by: 1

README

PostgreSQL-Integration for Go Universal Service Utilities

Full docu for go-gousu on https://github.com/indece-official/go-gousu

Usage

Config flags
Flag Env-Var Type Default Description
postgres_host POSTGRES_HOST string "127.0.0.1" DB-Server hostname or ip
postgres_port POSTGRES_PORT int 5432 DB-Server port
postgres_user POSTGRES_USER string "" User for authentication against db server
postgres_password POSTGRES_PASSWORD string "" Password for authentication against db server
postgres_database POSTGRES_DATABASE string "" Database to use on db server
postgres_max_retries POSTGRES_MAX_RETRIES int 10 Max number of retries before connecting to db fails
postgres_retry_interval POSTGRES_RETRY_INTERVAL int 6 Interval in seconds between retrying to connect to db
postgres_max_idle_conns POSTGRES_MAX_IDLE_CONNS int 0 Maximum number of idle connections (0 is unlimited)
postgres_max_open_conns POSTGRES_MAX_OPEN_CONNS int 0 Maximum number of open connections (0 is unlimited)

Documentation

Index

Constants

View Source
const ServiceName = "postgres"

ServiceName defines the name of postgres service used for dependency injection

Variables

This section is empty.

Functions

This section is empty.

Types

type IService

type IService interface {
	gousu.IService

	GetDB() *sql.DB
	GetDBSafe() (*sql.DB, error)
}

IService defined the interface of the postgresql database service

type MockService

type MockService struct {
	gousu.MockService

	GetDBFunc           func() *sql.DB
	GetDBSafeFunc       func() (*sql.DB, error)
	GetDBFuncCalled     int
	GetDBSafeFuncCalled int
}

MockService for simply mocking IService

func NewMockService

func NewMockService() *MockService

NewMockService creates a new initialized instance of MockService

func (*MockService) GetDB

func (s *MockService) GetDB() *sql.DB

GetDB calls GetDBFunc and increases GetDBFuncCalled

func (*MockService) GetDBSafe

func (s *MockService) GetDBSafe() (*sql.DB, error)

GetDBSafe calls GetDBSafeFunc and increases GetDBSafeFuncCalled

type Options

type Options struct {
	// SetupSQL can contain the content of a sql-file for updating the
	// database on startup
	SetupSQL string

	// UpdateSQL can contain the content of a sql-file for updating the
	// database on startup
	UpdateSQL string

	// GetDBRevisionSQL can be used for retrieving the revision of the database
	// used, must return/select one integer field
	GetDBRevisionSQL string

	// OpenFunc can be used to override the default sql.Open
	OpenFunc func(driverName string, dataSourceName string) (*sql.DB, error)
}

Options can contain parameters passed to the postgres service

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides the interaction with the postgresql database

func NewServiceBase

func NewServiceBase(ctx gousu.IContext, options *Options) *Service

NewServiceBase creates a new instance of postgres-service, should be used instead

of generating it manually

func (*Service) GetDB deprecated

func (s *Service) GetDB() *sql.DB

GetDB returns the postgres db connection

Deprecated: Use GetDBSafe() instead

func (*Service) GetDBSafe

func (s *Service) GetDBSafe() (*sql.DB, error)

GetDBSafe returns the postgres db connection after verifying it is alive

func (*Service) Health

func (s *Service) Health() error

Health checks the health of the postgres-service by pinging the postgres database

func (*Service) Name

func (s *Service) Name() string

Name returns the name of redis service from ServiceName

func (*Service) Start

func (s *Service) Start() error

Start initializes the connection to the postgres database and executed both setup.sql and update.sql after connecting

func (*Service) Stop

func (s *Service) Stop() error

Stop currently does nothing

Jump to

Keyboard shortcuts

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