Query queries the Chain Core for txfeeds matching the query.
(ctx context.Context, after string, limit int)
| 10 | |
| 11 | // Query queries the Chain Core for txfeeds matching the query. |
| 12 | func (t *Tracker) Query(ctx context.Context, after string, limit int) ([]*TxFeed, string, error) { |
| 13 | const baseQ = ` |
| 14 | SELECT id, alias, filter, after FROM txfeeds |
| 15 | WHERE ($1='' OR id < $1) ORDER BY id DESC LIMIT %d |
| 16 | ` |
| 17 | rows, err := t.DB.Query(ctx, fmt.Sprintf(baseQ, limit), after) |
| 18 | if err != nil { |
| 19 | return nil, "", errors.Wrap(err, "executing txfeeds query") |
| 20 | } |
| 21 | defer rows.Close() |
| 22 | |
| 23 | txfeeds := make([]*TxFeed, 0, limit) |
| 24 | for rows.Next() { |
| 25 | var ( |
| 26 | feed TxFeed |
| 27 | alias sql.NullString |
| 28 | ) |
| 29 | err := rows.Scan(&feed.ID, &alias, &feed.Filter, &feed.After) |
| 30 | if err != nil { |
| 31 | return nil, "", errors.Wrap(err, "scanning txfeed row") |
| 32 | } |
| 33 | |
| 34 | if alias.Valid { |
| 35 | feed.Alias = &alias.String |
| 36 | } |
| 37 | after = feed.ID |
| 38 | txfeeds = append(txfeeds, &feed) |
| 39 | } |
| 40 | err = rows.Err() |
| 41 | if err != nil { |
| 42 | return nil, "", errors.Wrap(err) |
| 43 | } |
| 44 | return txfeeds, after, nil |
| 45 | } |