Documentation
¶
Index ¶
- func TestMongoDBConnection(config *Config) error
- type Config
- type ConnectionManager
- type Database
- func (d *Database) BasicMapScan(query string, args ...interface{}) (map[string]interface{}, error)
- func (d *Database) BasicSliceMapScan(query string, args ...interface{}) ([]map[string]interface{}, error)
- func (d *Database) Close()
- func (d *Database) Connect() error
- func (d *Database) Execute(query string, args ...interface{}) (sql.Result, error)
- func (d *Database) ExecuteWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)
- func (d *Database) GetJSON(sqlString string) (map[string]interface{}, error)
- func (d *Database) GetJSONList(sqlString string) ([]map[string]interface{}, error)
- func (d *Database) MapScan(query string, args ...interface{}) (map[string]interface{}, error)
- func (d *Database) MapScanRedis(query string, duration time.Duration, args ...interface{}) (map[string]interface{}, error)
- func (d *Database) MapScanWithTx(tx *sql.Tx, query string, args ...interface{}) (map[string]interface{}, error)
- func (d *Database) Ping() error
- func (d *Database) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *Database) SliceMapScan(query string, args ...interface{}) ([]map[string]interface{}, error)
- func (d *Database) SliceMapScanRedis(query string, duration time.Duration, args ...interface{}) ([]map[string]interface{}, error)
- func (d *Database) SliceMapScanWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)
- func (d *Database) StartTransaction() (*sql.Tx, error)
- type DatabaseInterface
- type MongoDB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestMongoDBConnection ¶
TestMongoDBConnection tries to connect to specified mongodb database
Types ¶
type Config ¶
type Config interface {
GetHost() string
GetPort() int
GetUser() string
GetPassword() string
GetDatabase() string
}
Config Interface With Methods to be a database config
type ConnectionManager ¶
type ConnectionManager struct {
// contains filtered or unexported fields
}
func NewMySqlConnectionManager ¶
func NewMySqlConnectionManager(config Config) (*ConnectionManager, error)
NewMySqlConnectionManager inicia uma conexão com o banco de dados mysql instanciando um *ConnectionManager
func NewPgSqlConnectionManager ¶
func NewPgSqlConnectionManager(config Config) (*ConnectionManager, error)
NewPgSqlConnectionManager inicia uma conexão com o banco de dados postgres instanciando um *ConnectionManager
func (*ConnectionManager) Close ¶
func (c *ConnectionManager) Close()
Close encerra a conexão com o banco de dados
func (*ConnectionManager) GetConnection ¶
func (c *ConnectionManager) GetConnection() *sql.DB
GetConnection retorna uma conexão pré-estabelecida com o banco de dados
func (*ConnectionManager) HandleTransaction ¶ added in v1.0.35
func (c *ConnectionManager) HandleTransaction(tx *sql.Tx, err *error) error
HandleTransaction gerencia o estado da conexão efetivando o commit ou o rollback de uma transação de acordo com o erro recebido
tx *sql.Tx é a transação que está sendo trabalhada pela conexão err *error passar ponteiro do erro para ser analisado
func (*ConnectionManager) StartTransaction ¶
func (c *ConnectionManager) StartTransaction() (*sql.Tx, error)
StartTransaction inicia uma transação com o banco de dados
type Database ¶
func NewCachedMySQL ¶
NewCachedMySQL makes a new instance of Database and connect to a MySQL database and Redis.
func NewCachedPgSQL ¶
NewPgSQL makes a new instance of PgSQL and connect to PostgresSQL database and Redis.
func (*Database) BasicMapScan ¶
BasicMapScan Get the result of a query in this format: map[string]interface{}
Individual types:
bool, for booleans
float64, for numbers
string, for strings
[]interface{}, for arrays
func (*Database) BasicSliceMapScan ¶
func (d *Database) BasicSliceMapScan(query string, args ...interface{}) ([]map[string]interface{}, error)
BasicSliceMapScan Fetch all lines of given select
Individual types:
bool, for booleans
float64, for numbers
string, for strings
[]interface{}, for arrays
func (*Database) Close ¶
func (d *Database) Close()
Close is responsible for closing database connection
func (*Database) ExecuteWithTx ¶
ExecuteWithTx executes the received query with the parameters provided within a transaction.
func (*Database) GetJSONList ¶
GetJSONList Fetch all lines of given select
func (*Database) MapScanRedis ¶
func (*Database) MapScanWithTx ¶ added in v1.0.34
func (d *Database) MapScanWithTx(tx *sql.Tx, query string, args ...interface{}) (map[string]interface{}, error)
MapScanWithTx Get the result of a query in this format: map[string]interface{} into the transaction
func (*Database) SliceMapScan ¶
func (d *Database) SliceMapScan(query string, args ...interface{}) ([]map[string]interface{}, error)
SliceMapScan Fetch all lines of given select
func (*Database) SliceMapScanRedis ¶
type DatabaseInterface ¶
type DatabaseInterface interface {
Connect() error
Ping() error
Execute(query string, args ...interface{}) (sql.Result, error)
QueryRow(query string, args ...interface{}) *sql.Row
GetJSON(sqlString string) (map[string]interface{}, error)
MapScan(sqlString string, args ...interface{}) (map[string]interface{}, error)
GetJSONList(sqlString string) ([]map[string]interface{}, error)
Close()
}
Database Interface With Methods to be a database handler
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MongoDB connection and operations handler
func NewMongoDB ¶
NewMongoDB creates a new instance of MongoDB and connect to specified database
func (*MongoDB) C ¶
func (m *MongoDB) C(name string) *mgo.Collection
C exposes the collection property with its specific methods
func (*MongoDB) GetCollection ¶
func (m *MongoDB) GetCollection(name string) *mgo.Collection
GetCollection exposes the collection property with its specific methods