data

package
v0.0.0-...-0471c36 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
)

Define a custom ErrRecordNotFound error.

Functions

This section is empty.

Types

type Currency

type Currency struct {
	Id        int64           `json:"id"`
	Code      string          `json:"code"`
	Rate      decimal.Decimal `json:"rate"`
	CreatedAt time.Time       `json:"created_at"`
}

type CurrencyModel

type CurrencyModel struct {
	DB *sql.DB
}

Define a CurrencyModel struct type which wraps a sql.DB connection pool.

func (CurrencyModel) Convert

func (c CurrencyModel) Convert(base string, currencies []*Currency) []*Currency

func (CurrencyModel) Get

func (c CurrencyModel) Get(id int64) (*Currency, error)

Get for fetching currency with the given id from the database.

func (CurrencyModel) GetRates

func (c CurrencyModel) GetRates(date time.Time, codes []string) ([]*Currency, error)

GetRates method returns a slice of rates available in the database and date for which they are relevant. Rates can be filtered by date and ISO codes. The date of the rates may be different than requested one, because rates are not available e.g for holidays, weekends, etc. If that is the case then this method will return rates for the date that is the closest date in the past to the requested one.

func (*CurrencyModel) Insert

func (c *CurrencyModel) Insert(currency *Currency) error

Insert for inserting new currency into the database.

type Models

type Models struct {
	Currencies CurrencyModel
}

Create a Models struct which wraps the CurrencyModel.

func NewModels

func NewModels(db *sql.DB) Models

For ease of use, we also add a New() method which returns a Models struct containing the initialized models.

Jump to

Keyboard shortcuts

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