| 50 | } |
| 51 | |
| 52 | func (s *SQLiteStore) FindAll(ctx context.Context, opts event.FindOptions) ([]event.Event, error) { |
| 53 | query := `SELECT uuid, type, payload, timestamp, project, is_pinned FROM events` |
| 54 | var args []any |
| 55 | var conditions []string |
| 56 | |
| 57 | if opts.Type != "" { |
| 58 | conditions = append(conditions, "type = ?") |
| 59 | args = append(args, opts.Type) |
| 60 | } |
| 61 | if opts.Project != "" { |
| 62 | conditions = append(conditions, "project = ?") |
| 63 | args = append(args, opts.Project) |
| 64 | } |
| 65 | if len(conditions) > 0 { |
| 66 | query += " WHERE " + strings.Join(conditions, " AND ") |
| 67 | } |
| 68 | |
| 69 | query += " ORDER BY timestamp DESC" |
| 70 | |
| 71 | if opts.Limit > 0 { |
| 72 | query += fmt.Sprintf(" LIMIT %d", opts.Limit) |
| 73 | } |
| 74 | if opts.Offset > 0 { |
| 75 | query += fmt.Sprintf(" OFFSET %d", opts.Offset) |
| 76 | } |
| 77 | |
| 78 | rows, err := s.db.QueryContext(ctx, query, args...) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | defer rows.Close() |
| 83 | |
| 84 | var events []event.Event |
| 85 | for rows.Next() { |
| 86 | ev, err := scanEventRows(rows) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | events = append(events, *ev) |
| 91 | } |
| 92 | return events, rows.Err() |
| 93 | } |
| 94 | |
| 95 | func (s *SQLiteStore) Delete(ctx context.Context, uuid string) error { |
| 96 | _, err := s.db.ExecContext(ctx, `DELETE FROM events WHERE uuid = ?`, uuid) |