onedb

package module
v0.0.0-...-7e563ae Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: MIT Imports: 13 Imported by: 1

README

OneDb

Build Status Coverage Status

OneDB offers a single GO access layer for SQL, LDAP, Redis, etc. Input a query and it outputs a slice of structs or JSON

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueryIsNil = errors.New("invalid query")
View Source
var ErrRowScannerInvalidData = errors.New("data must be a ptr to a struct")
View Source
var ErrRowsScannerInvalidData = errors.New("data must be a slice of structs")

Functions

func DialTCP

func DialTCP(network, addr string) (net.Conn, error)

DialTCP is a helper function that will dial a TCP port and set a 2 minute time period

func IsPointer

func IsPointer(item reflect.Type) bool

IsPointer is used to determine if a reflect.Type is a pointer

func IsSlice

func IsSlice(item reflect.Type) bool

IsSlice is used to determine if a reflect.Type is a slice

func IsStruct

func IsStruct(item reflect.Type) bool

IsStruct is used to determine if a reflect.Type is a struct

func QueryJSON

func QueryJSON(backend Backender, query string, args ...interface{}) (string, error)

QueryJSON runs a query against the provided Backender and returns the JSON result

func QueryJSONRow

func QueryJSONRow(backend Backender, query string, args ...interface{}) (string, error)

QueryJSONRow runs a query against the provided Backender and returns the JSON result

func QueryStruct

func QueryStruct(backend Backender, result interface{}, query string, args ...interface{}) error

QueryStruct runs a query against the provided Backender and populates the provided result

func QueryStructRow

func QueryStructRow(backend Backender, result interface{}, query string, args ...interface{}) error

QueryStructRow runs a query against the provided Backender and populates the provided result

func QueryValues

func QueryValues(backend Backender, query *Query, result ...interface{}) error

QueryValues runs a query against the provided Backender and populates result values

func QueryWriteCSV

func QueryWriteCSV(w io.Writer, options CSVOptions, backend Backender, query string, args ...interface{}) error

QueryWriteCSV runs a query against the provided Backender and saves the response to the specified file in CSV format

Types

type Backender

type Backender interface {
	Query(query string, args ...interface{}) (RowsScanner, error)
	QueryRow(query string, args ...interface{}) Scanner
}

Backender is the db interface needed by onedb to enable QueryStruct and QueryJSON capability

type CSVOptions

type CSVOptions struct {
	DateOnly bool
}

CSVOptions contains specifications for how text should be formatted in a CSV file

type DBer

type DBer interface {
	QueryValues(query *Query, result ...interface{}) error
	QueryJSON(query string, args ...interface{}) (string, error)
	QueryJSONRow(query string, args ...interface{}) (string, error)
	QueryStruct(result interface{}, query string, args ...interface{}) error
	QueryStructRow(result interface{}, query string, args ...interface{}) error
	QueryWriteCSV(w io.Writer, options CSVOptions, query string, args ...interface{}) error
}

DBer is the added interface that onedb can enable for database querying

type DialFunc

type DialFunc func(network, addr string) (net.Conn, error)

DialFunc is the shape of the function used to dial a TCP connection

func NewMockDialer

func NewMockDialer(err error) DialFunc

NewMockDialer returns a onedb.DialFunc for testing purposes

type MethodsRun

type MethodsRun struct {
	MethodName string
	Arguments  []interface{}
}

MethodsRun contains the name of the method run and a slice of arguments

type Mocker

type Mocker interface {
	DBer
	Query(query string, args ...interface{}) (RowsScanner, error)
	QueryRow(query string, args ...interface{}) Scanner
	QueriesRun() []MethodsRun
	SaveMethodCall(name string, arguments []interface{})
	VerifyNextCommand(t *testing.T, name string, expected ...interface{})
}

Mocker is a fake database that can be used in place of a pgx or sql lib database for testing

func NewMock

func NewMock(closeErr, execErr error, data ...interface{}) Mocker

NewMock will create an instance that implements the Mocker interface

type Query

type Query struct {
	Query string
	Args  []interface{}
}

Query is a generic struct that houses a query string and arguments used to construct a query

func NewQuery

func NewQuery(query string, args ...interface{}) *Query

NewQuery is tne constructor for a Query struct

type RowsScanner

type RowsScanner interface {
	Close() error
	Columns() ([]string, error)
	Next() bool
	Err() error
	Scanner
}

RowsScanner is the rows interface needed by onedb to enable QueryStruct and QueryJSON capability

func NewRowsScanner

func NewRowsScanner(data interface{}) RowsScanner

NewRowsScanner returns a RowsScanner that can scan through a slice of data

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

Scanner is the row interface needed by onedb to enable QueryStruct and QueryJSON capability

func NewScanner

func NewScanner(data interface{}) Scanner

NewScanner returns a Scanner that can run Scan on a struct or pointer to struct

Directories

Path Synopsis
pgx module

Jump to

Keyboard shortcuts

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