data

package
v0.0.0-...-7c18459 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotFound is returned when the no records where matched by the query
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type Config

type Config interface {
	// DataDSN returns the data source name
	DataDSN() string
}

Config is the configuration for the data package

type DAO

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

DAO is a data access object that provides an abstraction over our database interactions.

func NewDAO

func NewDAO(cfg Config) *DAO

NewDAO will initialize the database connection pool (if not already done) and return a data access object which can be used to interact with the database

func (*DAO) Load

func (d *DAO) Load(ctx context.Context, ID int) (*Person, error)

Load will attempt to load and return a person. It will return ErrNotFound when the requested person does not exist. Any other errors returned are caused by the underlying database or our connection to it.

func (*DAO) LoadAll

func (d *DAO) LoadAll(ctx context.Context) ([]*Person, error)

LoadAll will attempt to load all people in the database It will return ErrNotFound when there are not people in the database Any other errors returned are caused by the underlying database or our connection to it.

func (*DAO) Save

func (d *DAO) Save(ctx context.Context, in *Person) (int, error)

Save will save the supplied person and return the ID of the newly created person or an error. Errors returned are caused by the underlying database or our connection to it.

type Database

type Database interface {
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
}

type DatabaseImpl

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

func (*DatabaseImpl) ExecContext

func (c *DatabaseImpl) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

func (*DatabaseImpl) QueryContext

func (c *DatabaseImpl) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

func (*DatabaseImpl) QueryRowContext

func (c *DatabaseImpl) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

type Person

type Person struct {
	// ID is the unique ID for this person
	ID int
	// FullName is the name of this person
	FullName string
	// Phone is the phone for this person
	Phone string
	// Currency is the currency this person has paid in
	Currency string
	// Price is the amount (in the above currency) paid by this person
	Price float64
}

Person is the data transfer object (DTO) for this package

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type ResultImpl

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

func (*ResultImpl) LastInsertId

func (r *ResultImpl) LastInsertId() (int64, error)

func (*ResultImpl) RowsAffected

func (r *ResultImpl) RowsAffected() (int64, error)

type Row

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

type RowImpl

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

func (*RowImpl) Scan

func (r *RowImpl) Scan(dest ...interface{}) error

type Rows

type Rows interface {
	Scan(dest ...interface{}) error
	Close() error
	Next() bool
}

type RowsImpl

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

func (RowsImpl) Close

func (r RowsImpl) Close() error

func (RowsImpl) Next

func (r RowsImpl) Next() bool

func (RowsImpl) Scan

func (r RowsImpl) Scan(dest ...interface{}) error

Jump to

Keyboard shortcuts

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