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

59 lines
1.3 KiB
Go
Raw Normal View History

2017-09-23 10:19:43 -07:00
package postgres
import (
"database/sql"
"github.com/kcotugno/tacitus"
)
2017-09-23 10:59:13 -07:00
const (
conf_columns = `product, last_trade_id`
conf_insert = `INSERT INTO confirmations (` + conf_columns +
`) VALUES ($1, $2) RETURNING id, ` + conf_columns + `;`
conf_find_product = `SELECT id, ` + conf_columns + ` FROM confirmations` +
`WHERE product = $1`
conf_update = `UPDATE confirmation SET last_trade_id = $1 WHERE product = $2`
)
2017-09-23 10:19:43 -07:00
type ConfirmationService struct {
logger tacitus.Logger
client *client
}
2017-09-23 10:59:13 -07:00
func (s *ConfirmationService) Confirmation(product string) (Confirmation, error) {
var conf Confirmation
res, err := s.client.QueryRow(conf_find_product, product)
if err != nil {
return conf, err
}
err = row.Scan(&conf.Id, &conf.Product, &conf.LastTradeId)
if err != nil {
return conf, err
}
return conf, nil
2017-09-23 10:19:43 -07:00
}
2017-09-23 10:59:13 -07:00
func (s *ConfirmationService) CreateConfirmation(c Confirmation) (Confirmation, error) {
var conf Confirmation
res, err := s.client.QueryRow(conf_insert, c.Product, c.LastTradeId)
if err != nil {
return conf, err
}
err = row.Scan(&conf.Id, &conf.Product, &conf.LastTradeId)
if err != nil {
return conf, err
}
return conf, nil
2017-09-23 10:19:43 -07:00
}
2017-09-23 10:59:13 -07:00
func (s *ConfirmationService) UpdateConfirmation(c Confirmation) (Confirmation, error) {
res, err := s.client.Exec(conf_update, c.LastTradeId, c.Product)
return c, err
2017-09-23 10:19:43 -07:00
}