This repository has been archived on 2022-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
tacitus/postgres/aggregation_results.go

90 lines
1.6 KiB
Go
Raw Normal View History

2017-10-17 07:12:24 -07:00
package postgres
import (
"git.kevincotugno.com/kcotugno/tacitus"
2017-10-17 07:12:24 -07:00
"github.com/shopspring/decimal"
"database/sql"
"errors"
"time"
)
type AggregationResults struct {
2017-10-17 22:12:46 -07:00
rows *sql.Rows
2017-10-17 07:12:24 -07:00
aggregation tacitus.Aggregation
2017-10-17 22:12:46 -07:00
err error
2017-10-17 07:12:24 -07:00
}
func (r *AggregationResults) Next() bool {
var a tacitus.Aggregation
var id, interval, buyTransactions, sellTransactions *int
var product *string
var price, buyVolume, sellVolume *decimal.Decimal
var timestamp *time.Time
if r.rows == nil {
r.err = errors.New("No query results")
return false
}
if r.rows.Next() {
r.err = r.rows.Scan(&id, &interval, &product, &price, &buyVolume,
&sellVolume, &buyTransactions, &sellTransactions, &timestamp)
if id != nil {
a.Id = *id
}
if interval != nil {
a.Interval = *interval
}
if product != nil {
a.Product = *product
}
if price != nil {
a.Price = *price
}
if buyVolume != nil {
a.BuyVolume = *buyVolume
}
if sellVolume != nil {
a.SellVolume = *sellVolume
}
if buyTransactions != nil {
a.BuyTransactions = *buyTransactions
}
if sellTransactions != nil {
a.SellTransactions = *sellTransactions
}
if timestamp != nil {
a.Timestamp = *timestamp
}
r.aggregation = a
} else {
r.err = r.rows.Err()
return false
}
if r.err == nil {
return true
} else {
return false
}
}
func (r *AggregationResults) Value() interface{} {
return r.aggregation
}
func (r *AggregationResults) Error() error {
return r.err
}
func (r *AggregationResults) Close() error {
if r.rows != nil {
return r.rows.Close()
}
return nil
}