package postgres
import (
"database/sql"
"github.com/kcotugno/tacitus"
)
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`
type ConfirmationService struct {
logger tacitus.Logger
client *client
}
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)
return conf, nil
func (s *ConfirmationService) CreateConfirmation(c Confirmation) (Confirmation, error) {
res, err := s.client.QueryRow(conf_insert, c.Product, c.LastTradeId)
func (s *ConfirmationService) UpdateConfirmation(c Confirmation) (Confirmation, error) {
res, err := s.client.Exec(conf_update, c.LastTradeId, c.Product)
return c, err