# Alepha - Orm

## Installation

Part of the `alepha` package. Import from `alepha/orm`.

```bash
npm install alepha
```

## Overview

Type-safe data layer over Drizzle ORM.

**Features:**

- `$entity` schema definitions with Zod + `db` column helpers
- `Repository` CRUD, pagination, joins, and optimistic locking
- Introspection-based dev schema sync, file-based production migrations
- SQLite by default; Postgres via `alepha/orm/postgres`

## API Reference

### Primitives

- [`$entity`](https://latest.alepha.dev/docs/reference-primitives-$entity.md) - Creates a database entity primitive that defines table structure using Zod schemas.
- [`$relations`](https://latest.alepha.dev/docs/reference-primitives-$relations.md) - Declares how entities relate to one another.
- [`$repositories`](https://latest.alepha.dev/docs/reference-primitives-$repositories.md) - One relation-aware repository per entity, in a single binding.
- [`$repository`](https://latest.alepha.dev/docs/reference-primitives-$repository.md) - Get the repository for the given entity.
- [`$sequence`](https://latest.alepha.dev/docs/reference-primitives-$sequence.md) - Declare a portable, scoped numeric sequence.
- [`$transactional`](https://latest.alepha.dev/docs/reference-primitives-$transactional.md) - Middleware that wraps handler execution in a database transaction.

### Providers

- [`DbCacheProvider`](https://latest.alepha.dev/docs/reference-providers-dbcacheprovider.md) - Database query cache using a simple in-memory Map.
- [`SequenceProvider`](https://latest.alepha.dev/docs/reference-providers-sequenceprovider.md) - Portable, scoped numeric sequence provider - works identically on Postgres,
- [`SqlExpressionProvider`](https://latest.alepha.dev/docs/reference-providers-sqlexpressionprovider.md) - Dialect-neutral SQL expression builder.
