> For the complete documentation index, see [llms.txt](https://docs-lunar.earthly.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-lunar.earthly.dev/sql-api/views/components.md).

# components

Schema reference for the components and components\_latest SQL views — time series of tracked components with merged collector metadata per commit.

```
components
components_latest
```

The `components` view is a time series representation of the collection of components that Lunar monitors.

A subset of this data is available in the `components_latest` view, which contains only the latest `git_sha` for each `pr`, in each component. To get the latest row for the default branch, you can filter this view by `pr IS NULL`.

## Schema

| Column              | Type          | Description                                                                                                                    |
| ------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `component_id`      | `TEXT`        | The identifier for the component - e.g. `github.com/foo/bar/buz`                                                               |
| `timestamp`         | `TIMESTAMP`   | The "committed at" UTC timestamp of the `git_sha`                                                                              |
| `git_sha`           | `VARCHAR(40)` | The requested repository commit                                                                                                |
| `processed_git_sha` | `VARCHAR(40)` | The commit selected for code processing; `NULL` when unknown                                                                   |
| `pr`                | `BIGINT`      | The pull request number if the commit is part of a pull request. Set to `NULL` for the default branch                          |
| `domain`            | `TEXT`        | The domain of the component in dotted path format (e.g. `payments.analytics.backend`)                                          |
| `owner`             | `TEXT`        | The owner of the component                                                                                                     |
| `tags`              | `TEXT[]`      | The tags associated with the component                                                                                         |
| `branch`            | `TEXT`        | The component branch context                                                                                                   |
| `component_json`    | `JSONB`       | The component JSON object resulting from merging component JSON deltas of the different collectors that ran for this component |

## Notes

* To get the component data for a given component version, you need to filter by `component_id`, and `git_sha`. Include `pr` to distinguish branch and pull-request rows.
* For repeated updates to the same commit SHA, the `component_json` is updated with the latest JSON object. Individual updates (or "deltas") can be accessed through the [`component_deltas` view](/sql-api/views/component-deltas.md).

## Usage examples

Find the latest data for a particular component on the default branch. This query is guaranteed to return at most one row.

```sql
SELECT *
FROM components_latest
WHERE component_id = 'github.com/foo/bar/buz'
  AND pr IS NULL;
```

Code coverage of a component over time.

```sql
SELECT timestamp,
       component_json->'codecov'->'report'->'result'->'coverage'->>'total' AS coverage
FROM components
WHERE component_id = 'github.com/foo/bar/buz'
  AND pr IS NULL
  AND jsonb_path_exists(component_json, '$.codecov.report.result.coverage.total')
ORDER BY timestamp ASC;
```

Histogram of Go versions used across all components within a domain.

```sql
SELECT component_json->'go'->>'version' AS go_version,
       COUNT(*) AS count
FROM components_latest
WHERE jsonb_path_exists(component_json, '$.go.version')
  AND (domain = 'analytics' OR domain LIKE 'analytics.%')
  AND pr IS NULL
GROUP BY go_version
ORDER BY count DESC;
```

## Processed commits

In a monorepo, commit Y may leave a component unchanged. Its `processed_git_sha` points to X, the commit selected for that component's processing, so clients can locate those results. It equals `git_sha` for processing at the requested commit, or is `NULL` when unknown. `component_json` stays tied to `git_sha`; the reference does not indicate completion or success.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-lunar.earthly.dev/sql-api/views/components.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
