db

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToDb

func ConnectToDb(ctx context.Context, config *Config) chan CnxResult

Creates a connection to the DB and returns it

Types

type CnxResult

type CnxResult struct {
	Cnx   *sql.DB
	Error error
}

type Config

type Config struct {
	// Hostname
	Host string
	// Port
	Port string
	// User
	User string
	// Password
	Pwd string
	// Database Name
	Name string
	// Whether SSL is enabled on the connection or not
	Ssl bool
	// Schema name
	SchemaName string
}

Config holds the configuration to connect to a database

func GetM3DbConfig

func GetM3DbConfig() *Config

GetM3DbConfig returns a `Config` object with the values for the database by either reading them from the environment or defaulting them to a known value.

func GetTenantDBConfig

func GetTenantDBConfig(tenantName string) *Config

type Singleton

type Singleton struct {
	Db *sql.DB
	// contains filtered or unexported fields
}

func GetInstance

func GetInstance() *Singleton

Returns a Singleton instance that keeps the connections to the Database

func (*Singleton) Close

func (s *Singleton) Close() error

Close all connectiosn

func (*Singleton) GetTenantDB

func (s *Singleton) GetTenantDB(tenantName string) *sql.DB

GetTenantDB returns a database connection to the tenant being accessed, if the connection has been established then it's returned from a local cache, else it's created, cached and returned.

func (*Singleton) RemoveCnx

func (s *Singleton) RemoveCnx(tenantName string)

RemoveCnx removes a tenant DB connection from the cache

Jump to

Keyboard shortcuts

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