GetSince attempts to return a channel of snapshots for the asset with the given name since the given date.
(name string, date time.Time)
| 115 | |
| 116 | // GetSince attempts to return a channel of snapshots for the asset with the given name since the given date. |
| 117 | func (s *SQLRepository) GetSince(name string, date time.Time) (<-chan *Snapshot, error) { |
| 118 | rows, err := s.getSinceQuery.Query(name, date) |
| 119 | if err != nil { |
| 120 | return nil, fmt.Errorf("unable to get since: %w", err) |
| 121 | } |
| 122 | |
| 123 | snapshots := make(chan *Snapshot) |
| 124 | |
| 125 | go func() { |
| 126 | defer helper.CloseDatabaseRows(rows) |
| 127 | defer close(snapshots) |
| 128 | |
| 129 | for rows.Next() { |
| 130 | snapshot := &Snapshot{} |
| 131 | |
| 132 | err := rows.Scan( |
| 133 | &snapshot.Date, |
| 134 | &snapshot.Open, |
| 135 | &snapshot.High, |
| 136 | &snapshot.Low, |
| 137 | &snapshot.Close, |
| 138 | &snapshot.Volume, |
| 139 | ) |
| 140 | if err != nil { |
| 141 | log.Printf("unable to scan row: %v", err) |
| 142 | } |
| 143 | |
| 144 | snapshots <- snapshot |
| 145 | } |
| 146 | }() |
| 147 | |
| 148 | return snapshots, nil |
| 149 | } |
| 150 | |
| 151 | // LastDate returns the date of the last snapshot for the asset with the given name. |
| 152 | func (s *SQLRepository) LastDate(name string) (time.Time, error) { |
no test coverage detected