> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiparlance.org/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL emitter

> @aiparlance/sql — role schema, score 15/23, pass/partial/fail objectives

# PostgreSQL emitter

|           |                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Package   | `@aiparlance/sql`                                                                                                                 |
| CLI       | `aip emit sql`                                                                                                                    |
| Role      | `schema`                                                                                                                          |
| **Score** | **15/23** (65%)                                                                                                                   |
| Band      | Strong slice                                                                                                                      |
| Scorecard | [transpilers/sql/EMITTER\_OBJECTIVES.md](https://github.com/eudameron/aiparlance/blob/main/transpilers/sql/EMITTER_OBJECTIVES.md) |

Scored against the master checklist ([55 IDs](https://github.com/eudameron/aiparlance/blob/main/EMITTER_OBJECTIVES.md), v2 · 2026-08-06).

## Summary

| ✅ Pass | ⚠️ Partial | ❌ Fail | ➖ N/A |
| ------ | ---------- | ------ | ----- |
| 15     | 1          | 7      | 32    |

N/A items are outside the `schema` role and do not affect the score denominator.

## What it produces

PostgreSQL DDL: `CREATE TABLE`, indexes, seeds. Primary SQL target.

## ✅ Passed

| ID   | Objective                                                             |
| ---- | --------------------------------------------------------------------- |
| `A1` | Emit entity shapes (types / structs / schemas / tables) from `entity` |
| `A4` | Emit enums / constrained variants from `enum(…)`                      |
| `A5` | Emit `belongs_to` as FKs or refs                                      |
| `A6` | Emit implicit `id` primary key                                        |
| `A7` | Emit `timestamps` (`created_at` / `updated_at`)                       |
| `A8` | Emit `soft_delete` field/column (`deleted_at`)                        |
| `B1` | Honor `required` / `optional`                                         |
| `B2` | Honor `unique`                                                        |
| `C1` | Durable schema (DDL or ORM / query models)                            |
| `C2` | Indexes from `index { }`                                              |
| `C3` | Seeds from `seed { }`                                                 |
| `C6` | Respect `app.database` target                                         |
| `H3` | Golden / CI for `minimal.aip` (or matching twin)                      |
| `H4` | Emit succeeds on matching full-tier examples without crash            |
| `H5` | Naming aligned with docs (plural tables, `*_id`, snake\_case)         |

## ⚠️ Partial

| ID   | Objective                                           |
| ---- | --------------------------------------------------- |
| `B4` | Map semantic types (`email`, `phone`, …) distinctly |

## ❌ Still failing (applicable)

| ID   | Objective                                                     |
| ---- | ------------------------------------------------------------- |
| `A9` | Soft-delete **semantics** (default reads filter deleted rows) |
| `B3` | Apply `validation { }` beyond required folding                |
| `C4` | Versioned migrations (ordered **up**)                         |
| `C5` | Migration **down** / rollback                                 |
| `C7` | Transactions for multi-statement / workflow writes            |
| `H1` | Human-readable API / domain documentation                     |
| `H2` | Automated test fixtures or scaffolds                          |

Full ID-by-ID scorecard (including ➖ N/A): [transpilers/sql/EMITTER\_OBJECTIVES.md](https://github.com/eudameron/aiparlance/blob/main/transpilers/sql/EMITTER_OBJECTIVES.md).

## Tests

Package Vitest + golden `transpilers/sql/fixtures/minimal.sql`. Repo CI asserts SQL for `minimal.aip` and seeds/indexes on richer examples.

```bash theme={null}
npm test
node packages/cli/dist/cli.js emit sql examples/blog-crud.aip
```

## Related

* [Emitters overview](/en/emitters)
* [Master EMITTER\_OBJECTIVES](https://github.com/eudameron/aiparlance/blob/main/EMITTER_OBJECTIVES.md)
* [First emitters](/en/first-transpiler)
* [Get started here](/en/getting-started)
