db

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverSQLServer = "mssql"
	DriverMySQL     = "mysql"
)

Defines all possible sql drivers

View Source
const DefaultConnectionName = "default"

DefaultConnectionName - default connection key

Variables

This section is empty.

Functions

func DriverName

func DriverName() string

DriverName - Returns default driver name

func DriverNameByKey added in v1.5.1

func DriverNameByKey(key string) (string, error)

DriverNameByKey - Returns driver name for the connection key provided

func GetSQLXFromSQLConnector added in v1.3.1

func GetSQLXFromSQLConnector(db SQLConnector) *sqlx.DB

GetSQLXFromSQLConnector - Returns a ptr of sqlx.DB from a SQLConnector

func InitConnection

func InitConnection(drvName string, connection string)

InitConnection - Initialize the connection with driver and connection string

func InitConnectionWithKey added in v1.5.1

func InitConnectionWithKey(key string, drvName string, connection string)

InitConnectionWithKey - Initialize the connection for specific key with driver and connection string

func Query

func Query(query string, args ...interface{}) (*sqlx.Rows, error)

Query - Executes the query and return a *Rows instance

func QueryOrPanic

func QueryOrPanic(query string, args ...interface{}) *sqlx.Rows

QueryOrPanic - Executes the query and return a *Rows instance, panics if error occurs

func QueryOrPanicWithKey added in v1.5.1

func QueryOrPanicWithKey(key string, query string, args ...interface{}) *sqlx.Rows

QueryOrPanicWithKey - Executes the query for a specific connection key and return a *Rows instance, panics if error occurs

func QueryWithKey added in v1.5.1

func QueryWithKey(key string, query string, args ...interface{}) (*sqlx.Rows, error)

QueryWithKey - Executes the query for a specific connection key and return a *Rows instance

func TableExists

func TableExists(tableName string) bool

TableExists - Returns true if table exists otherwise false

func TableExistsWithKey added in v1.5.1

func TableExistsWithKey(key string, tableName string) bool

TableExistsWithKey - Returns true if table exists otherwise false for a specific connection key

Types

type InvalidConnectionKeyError added in v1.5.1

type InvalidConnectionKeyError struct {
	// contains filtered or unexported fields
}

InvalidConnectionKeyError - Defines the error for an invalid key provided to retrive or use a connection instance

func NewInvalidConnectionKeyError added in v1.5.1

func NewInvalidConnectionKeyError(msg string) *InvalidConnectionKeyError

NewInvalidConnectionKeyError - Returns a new InvalidConnectionKeyError instance

func (*InvalidConnectionKeyError) Error added in v1.5.1

func (e *InvalidConnectionKeyError) Error() string

Error - Implements error interface

type SQLConnector

type SQLConnector interface {
	DriverName() string
	Exec(string, ...interface{}) (sql.Result, error)
	Prepare(string) (*sql.Stmt, error)
	Preparex(string) (*sqlx.Stmt, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	Queryx(string, ...interface{}) (*sqlx.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	QueryRowx(string, ...interface{}) *sqlx.Row
}

SQLConnector - Generalizes a sql connection

func GetConnection

func GetConnection() SQLConnector

GetConnection - Returns the default instance of db connection

func GetConnectionWithKey added in v1.5.1

func GetConnectionWithKey(key string) (SQLConnector, error)

GetConnectionWithKey - Returns an istance of the db connection by connection key (for multiple connections)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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