db

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestMongoDBConnection

func TestMongoDBConnection(config *Config) error

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

NewMySqlConnectionManager inicia uma conexão com o banco de dados mysql instanciando um *ConnectionManager

func NewPgSqlConnectionManager

func NewPgSqlConnectionManager(config Config) *ConnectionManager

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

type Database struct {
	ConnectionLine string
	Conn           *sql.DB
	Driver         string
	CacheConfig    cache.Config
}

func NewCachedMySQL

func NewCachedMySQL(config Config, cacheConfig cache.Config) *Database

NewCachedMySQL makes a new instance of Database and connect to a MySQL database and Redis.

func NewCachedPgSQL

func NewCachedPgSQL(config Config, cacheConfig cache.Config) *Database

NewPgSQL makes a new instance of PgSQL and connect to PostgresSQL database and Redis.

func NewMySQL

func NewMySQL(config Config) *Database

NewMySQL makes a new instance of Database and connect to a MySQL database.

func NewPgSQL

func NewPgSQL(config Config) *Database

NewPgSQL makes a new instance of PgSQL and connect to PostgresSQL database.

func (*Database) BasicMapScan

func (d *Database) BasicMapScan(query string, args ...interface{}) (map[string]interface{}, error)
 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) Connect

func (d *Database) Connect() error

func (*Database) Execute

func (d *Database) Execute(query string, args ...interface{}) (sql.Result, error)

Execute executes the query received with the given parameters.

func (*Database) ExecuteWithTx

func (d *Database) ExecuteWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecuteWithTx executes the received query with the parameters provided within a transaction.

func (*Database) GetJSON

func (d *Database) GetJSON(sqlString string) (map[string]interface{}, error)

GetJSON Get first row in JSON format.

func (*Database) GetJSONList

func (d *Database) GetJSONList(sqlString string) ([]map[string]interface{}, error)

GetJSONList Fetch all lines of given select

func (*Database) MapScan

func (d *Database) MapScan(query string, args ...interface{}) (map[string]interface{}, error)

MapScan Get the result of a query in this format: map[string]interface{}

func (*Database) MapScanRedis

func (d *Database) MapScanRedis(query string, duration time.Duration, args ...interface{}) (map[string]interface{}, error)

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) Ping

func (d *Database) Ping() error

Ping Tests the connection.

func (*Database) QueryRow

func (d *Database) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow Get the next Query Row.

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

func (d *Database) SliceMapScanRedis(query string, duration time.Duration, args ...interface{}) ([]map[string]interface{}, error)

func (*Database) SliceMapScanWithTx added in v1.0.34

func (d *Database) SliceMapScanWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

SliceMapScanWithTx Fetch all lines of given select into a Tx

func (*Database) StartTransaction

func (d *Database) StartTransaction() (*sql.Tx, error)

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

func NewMongoDB(config *Config) *MongoDB

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) Close

func (m *MongoDB) Close()

Close closes the database connection

func (*MongoDB) Copy

func (m *MongoDB) Copy() *MongoDB

Copy copies the current database object

func (*MongoDB) GetCollection

func (m *MongoDB) GetCollection(name string) *mgo.Collection

GetCollection exposes the collection property with its specific methods

Jump to

Keyboard shortcuts

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