Documentation
¶
Overview ¶
Package database provides a layer for interacting with read/write databases
Index ¶
Constants ¶
const ( MySQLDriver = "mysql" PostgreSQLDriver = "postgresql" )
Database constants
Variables ¶
This section is empty.
Functions ¶
func CloseAllConnections ¶
func CloseAllConnections()
CloseAllConnections closes the current database connections
func NewTx ¶
NewTx creates a new TX
func OpenConnection ¶
func OpenConnection() (err error)
OpenConnection opens the database connection (read / write)
func SetConfiguration ¶
func SetConfiguration(conf Configuration)
SetConfiguration sets the configuration
Types ¶
type ApiDatabase ¶
type ApiDatabase struct { *sql.DB // calls are passed through by default to me // contains filtered or unexported fields }
ApiDatabase Extends sql.DB
var ( ReadDatabase *ApiDatabase WriteDatabase *ApiDatabase )
Global database instances
func NewApiDatabase ¶
func NewApiDatabase(read, write *sql.DB) *ApiDatabase
NewApiDatabase creates a new database connection
func (*ApiDatabase) GetReadDatabase ¶
func (d *ApiDatabase) GetReadDatabase() *sql.DB
GetReadDatabase gets the read database connection these are needed for testing because for some reason it can't determine that DeliveryDudesDB extends sql.DB
func (*ApiDatabase) GetWriteDatabase ¶
func (d *ApiDatabase) GetWriteDatabase() *sql.DB
GetWriteDatabase gets the write database connection
func (*ApiDatabase) StopWorker ¶
func (d *ApiDatabase) StopWorker()
StopWorker will wait for the queue to empty and then shutdown the worker
type Configuration ¶
type Configuration struct { DatabaseRead ConnectionConfig `json:"database_read" mapstructure:"database_read"` // Read database connection DatabaseWrite ConnectionConfig `json:"database_write" mapstructure:"database_write"` // Write database connection }
Configuration is the database configuration
type ConnectionConfig ¶
type ConnectionConfig struct { Driver string `json:"driver" mapstructure:"driver"` // mysql or postgresql Host string `json:"host" mapstructure:"host"` // localhost MaxConnectionTime int `json:"max_connection_time" mapstructure:"max_connection_time"` // 60 MaxIdleConnections int `json:"max_idle_connections" mapstructure:"max_idle_connections"` // 5 MaxOpenConnections int `json:"max_open_connections" mapstructure:"max_open_connections"` // 5 Name string `json:"name" mapstructure:"name"` // database-name Password string `json:"password" mapstructure:"password"` // user-password Port string `json:"port" mapstructure:"port"` // 3306 User string `json:"user" mapstructure:"user"` // username }
ConnectionConfig is a configuration for a SQL connection
Source Files
¶
- database.go