# 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](https://docs-lunar.earthly.dev/sql-api/views/domains)
* [components](https://docs-lunar.earthly.dev/sql-api/views/components)
* [component\_deltas](https://docs-lunar.earthly.dev/sql-api/views/component-deltas)
* [initiatives](https://docs-lunar.earthly.dev/sql-api/views/initiatives)
* [policies](https://docs-lunar.earthly.dev/sql-api/views/policies)
* [checks](https://docs-lunar.earthly.dev/sql-api/views/checks)
* [prs](https://docs-lunar.earthly.dev/sql-api/views/prs)
* [catalog](https://docs-lunar.earthly.dev/sql-api/views/catalog)

## 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](https://docs-lunar.earthly.dev/install/skills) for setup instructions.
