sql

package
v0.0.0-...-df570b3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToValueString

func ToValueString(val interface{}) (string, error)

ToValueString returns the string representation of a basic go core data type for usage in a db call.

Types

type Config

type Config struct {
	User         string `json:"user"`
	UserPassword string `json:"user_password"`
	DBPort       string `json:"db_port"`
	DBIP         string `json:"dp_ip"`
	DBName       string `json:"db_name"`
	DBDriver     string `json:"db_driver"`
}

Config is a configuration struct for the DB connection for DBMaker.

type DB

type DB interface {
	New() (*sqlx.DB, error)
}

DB defines an interface which exposes a method to return a new underline sql.Database.

func NewDB

func NewDB(config Config, metrics metrics.Metrics) DB

NewDB returns a new instance of a DB.

type SQL

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

SQL defines an struct which implements the db.Provider which allows us execute CRUD ops.

func New

func New(s metrics.Metrics, d DB, ts ...tables.TableMigration) *SQL

New returns a new instance of SQL.

func (*SQL) Count

func (sq *SQL) Count(table db.TableIdentity) (int, error)

Count retrieves the total number of records from the specific table from the db.

func (*SQL) Delete

func (sq *SQL) Delete(table db.TableIdentity, index string, indexValue interface{}) error

Delete removes the giving data from the specific db with the specific index and value.

func (*SQL) Get

func (sq *SQL) Get(table db.TableIdentity, consumer db.TableConsumer, index string, indexValue interface{}) error

Get retrieves the giving data from the specific db with the specific index and value.

func (*SQL) GetAll

func (sq *SQL) GetAll(table db.TableIdentity, order string, orderBy string) ([]map[string]interface{}, error)

GetAll retrieves the giving data from the specific db with the specific index and value.

func (*SQL) GetAllBy

func (sq *SQL) GetAllBy(table db.TableIdentity, order string, orderBy string, mx func(*sqlx.Rows) error) error

GetAllBy retrieves the giving data from the specific db with the specific index and value.

func (*SQL) GetAllPerPage

func (sq *SQL) GetAllPerPage(table db.TableIdentity, order string, orderBy string, page int, responsePerPage int) ([]map[string]interface{}, int, error)

GetAllPerPage retrieves the giving data from the specific db with the specific index and value.

func (*SQL) GetAllPerPageBy

func (sq *SQL) GetAllPerPageBy(table db.TableIdentity, order string, orderBy string, page int, responsePerPage int, mx func(*sqlx.Rows) error) (int, error)

GetAllPerPageBy retrieves the giving data from the specific db with the specific index and value.

func (*SQL) GetBy

func (sq *SQL) GetBy(table db.TableIdentity, consumer func(*sqlx.Row) error, index string, indexValue interface{}) error

GetBy retrieves the giving data from the specific db with the specific index and value.

func (*SQL) Save

func (sq *SQL) Save(identity db.TableIdentity, table db.TableFields) error

Save takes the giving table name with the giving fields and attempts to save this giving data appropriately into the giving db.

func (*SQL) Update

func (sq *SQL) Update(identity db.TableIdentity, table db.TableFields, index string, indexValue interface{}) error

Update takes the giving table name with the giving fields and attempts to update this giving data appropriately into the giving db. index - defines the string which should identify the key to be retrieved from the fields to target the data to be updated in the db.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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