> 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/sql-api.md).

# Overview

The SQL API provides programmatic access to Lunar's data through SQL queries. Through this interface, you can access and analyze information about your components, domains, policies, and more.

## Accessing the SQL API

To access the SQL API, use the Lunar CLI command `lunar sql connection-string` to get a PostgreSQL connection string that can be used with any PostgreSQL client:

```bash
# Get the connection string
lunar sql connection-string

# Connect using psql (interactive)
psql $(lunar sql connection-string)

# Execute a query directly
psql $(lunar sql connection-string) -c "SELECT * FROM components LIMIT 5"
```

The access is **read-only** and restricted to only the views described in this documentation.

## Available Views

For detailed information about available views, explore these pages:

* [domains](/sql-api/views/domains.md)
* [components](/sql-api/views/components.md)
* [component\_deltas](/sql-api/views/component-deltas.md)
* [initiatives](/sql-api/views/initiatives.md)
* [policies](/sql-api/views/policies.md)
* [checks](/sql-api/views/checks.md)
* [prs](/sql-api/views/prs.md)
* [catalog](/sql-api/views/catalog.md) -- Coming Soon

## AI Skill

An AI skill is available to help you craft SQL queries against the Lunar data model. The [lunar-sql](https://github.com/earthly/skills/tree/main/skills/lunar-sql) skill provides your AI assistant with knowledge of the view schemas, JSONB query patterns, and common query examples.

See [Installing AI Skills](/install/skills.md) for setup instructions.


---

# 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/sql-api.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.
