db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 Database

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

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

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

Jump to

Keyboard shortcuts

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