func (fii *FIIParser) Dividends(code, monthYear string) (*[]rapina.Dividend, error) {
	const s = `SELECT trading_code, base_date, value
	FROM fii_dividends 
	WHERE trading_code=$1 
	AND base_date LIKE $2;`
	rows, err := fii.db.Query(s, code, monthYear+"%")
	if err != nil {
		return nil, errors.Wrap(err, "lendo dividendos do bd")
	}
	defer rows.Close()
	dividends := []rapina.Dividend{}
	var (
		tradingCode, baseDate string
		value                 float64
	)
	for rows.Next() {
		err := rows.Scan(&tradingCode, &baseDate, &value)
		if err != nil {
			return nil, err
		}
		dividends = append(dividends, rapina.Dividend{
			Code: tradingCode,
			Date: baseDate,
			Val:  value,
		})
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	if len(dividends) == 0 {
		return nil, errors.New("dividendos não encontrados")
	}
	return &dividends, nil
}
Dividends returns the dividend from the db.
package parsers
import (
	"database/sql"
	"encoding/json"
	"fmt"
	"strconv"
	"strings"
	"sync"
	"github.com/dude333/rapina"
	"github.com/dude333/rapina/progress"
	"github.com/pkg/errors"
)
var (
	ErrDBUnset  = errors.New("database not set")
	ErrNotFound = errors.New("not found")
)
type FIIParser struct {
	db  *sql.DB
	log rapina.Logger
	mu  sync.Mutex  
}
func NewFII(db *sql.DB, log rapina.Logger) (*FIIParser, error) {
	err := createAllTables(db)
	return &FIIParser{
		db:  db,
		log: log,
	}, err
}
func (fii *FIIParser) SaveDetails(stream []byte) error {
	if !hasTable(fii.db, "fii_details") {
		if err := createTable(fii.db, "fii_details"); err != nil {
			return err
		}
	}
	var fiiDetails rapina.FIIDetails
	if err := json.Unmarshal(stream, &fiiDetails); err != nil {
		return errors.Wrap(err, "json unmarshal")
	}
	trimFIIDetails(&fiiDetails)
	x := fiiDetails.DetailFund
	if x.CNPJ == "" {
		return errors.New("CNPJ não encontrado")
	}
	fii.mu.Lock()
	defer fii.mu.Unlock()
	insert := `INSERT OR IGNORE INTO fii_details 
		(cnpj, acronym, trading_code, json) 
		VALUES (?,?,?,?);`
	_, err := fii.db.Exec(insert,
		x.CNPJ, x.Acronym, x.TradingCode, stream)
	return err
}
func (fii *FIIParser) Details(code string) (*rapina.FIIDetails, error) {
	details := rapina.FIIDetails{}
	if fii.db == nil {
		return nil, ErrDBUnset
	}
	var query string
	if len(code) == 4 {
		query = `SELECT json FROM fii_details WHERE acronym=?`
	} else if len(code) == 6 {
		query = `SELECT json FROM fii_details WHERE trading_code=?`
	} else {
		return nil, fmt.Errorf("invalid code '%s'", code)
	}
	var jsonStr []byte
	row := fii.db.QueryRow(query, code)
	err := row.Scan(&jsonStr)
	if err != nil {
		return nil, err
	}
	if err := json.Unmarshal(jsonStr, &details); err != nil {
		progress.ErrorMsg("FII details [%v]: %s\n", err, string(jsonStr))
		return nil, errors.Wrap(err, "json unmarshal")
	}
	return &details, nil
}