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/trade_result.go

55 lines
795 B
Go

package postgres
import (
"git.kevincotugno.com/kcotugno/tacitus"
"database/sql"
"errors"
)
type TradeResults struct {
rows *sql.Rows
trade tacitus.Trade
err error
}
func (r *TradeResults) Next() bool {
var t tacitus.Trade
if r.rows == nil {
r.err = errors.New("No query results")
return false
}
if r.rows.Next() {
r.err = r.rows.Scan(&t.Id, &t.TradeId, &t.Product, &t.Price, &t.Size,
&t.Buy, &t.Sell, &t.Timestamp)
r.trade = t
} else {
r.err = r.rows.Err()
return false
}
if r.err == nil {
return true
} else {
return false
}
}
func (r *TradeResults) Value() interface{} {
return r.trade
}
func (r *TradeResults) Error() error {
return r.err
}
func (r *TradeResults) Close() error {
if r.rows != nil {
return r.rows.Close()
}
return nil
}