GetItem returns a single item by kind and install_key.
(ctx context.Context, kind, installKey string)
| 264 | |
| 265 | // GetItem returns a single item by kind and install_key. |
| 266 | func (s *Store) GetItem(ctx context.Context, kind, installKey string) (Item, error) { |
| 267 | if err := s.Init(ctx); err != nil { |
| 268 | return Item{}, err |
| 269 | } |
| 270 | db, err := s.open() |
| 271 | if err != nil { |
| 272 | return Item{}, err |
| 273 | } |
| 274 | defer db.Close() |
| 275 | |
| 276 | var it Item |
| 277 | var installed int |
| 278 | err = db.QueryRowContext(ctx, ` |
| 279 | SELECT id, kind, name, description, source_id, repo_owner, repo_name, repo_branch, |
| 280 | item_path, install_key, target_apps, metadata_json, installed, installed_targets, |
| 281 | last_seen_at, created_at, updated_at |
| 282 | FROM metadata_items WHERE kind = ? AND install_key = ?`, kind, installKey). |
| 283 | Scan(&it.ID, &it.Kind, &it.Name, &it.Description, &it.SourceID, |
| 284 | &it.RepoOwner, &it.RepoName, &it.RepoBranch, &it.ItemPath, &it.InstallKey, |
| 285 | &it.TargetApps, &it.MetadataJSON, &installed, &it.InstalledTargets, |
| 286 | &it.LastSeenAt, &it.CreatedAt, &it.UpdatedAt) |
| 287 | if err != nil { |
| 288 | return Item{}, fmt.Errorf("metadata: get item: %w", err) |
| 289 | } |
| 290 | it.Installed = installed != 0 |
| 291 | return it, nil |
| 292 | } |
| 293 | |
| 294 | // MarkInstalled sets the installed flag and records the target app. |
| 295 | func (s *Store) MarkInstalled(ctx context.Context, kind, installKey, targetApp string) error { |