List returns all instructions (without installs) ordered by name.
(ctx context.Context)
| 110 | |
| 111 | // List returns all instructions (without installs) ordered by name. |
| 112 | func (s *Store) List(ctx context.Context) ([]Instruction, error) { |
| 113 | if err := s.Init(ctx); err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | db, err := s.open() |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | defer db.Close() |
| 121 | rows, err := db.QueryContext(ctx, `SELECT id, name, description, content, created_at, updated_at FROM instructions ORDER BY name`) |
| 122 | if err != nil { |
| 123 | return nil, fmt.Errorf("instructions: list: %w", err) |
| 124 | } |
| 125 | defer rows.Close() |
| 126 | var out []Instruction |
| 127 | for rows.Next() { |
| 128 | var in Instruction |
| 129 | var created, updated string |
| 130 | if err := rows.Scan(&in.ID, &in.Name, &in.Description, &in.Content, &created, &updated); err != nil { |
| 131 | return nil, fmt.Errorf("instructions: scan: %w", err) |
| 132 | } |
| 133 | in.CreatedAt = parseTime(created) |
| 134 | in.UpdatedAt = parseTime(updated) |
| 135 | out = append(out, in) |
| 136 | } |
| 137 | return out, rows.Err() |
| 138 | } |
| 139 | |
| 140 | // ListWithInstalls returns all instructions with their installs populated. |
| 141 | func (s *Store) ListWithInstalls(ctx context.Context) ([]Instruction, error) { |