alepha@docs:~/docs/reference/primitives$
cat $entity.md | pretty1 min read
#$entity
#Import
typescript
1import { $entity } from "alepha/orm";
#Overview
Creates a database entity primitive that defines table structure using Zod schemas.
#Options
| Option | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | The database table name that will be created for this entity |
schema |
T |
Yes | Zod schema defining the table structure and column types. |
indexes |
Object |
No | Database indexes to create for query optimization. |
foreignKeys |
Array<{ |
No | Foreign key constraints to maintain referential integrity. |
constraints |
Array<{ |
No | Additional table constraints for data validation |
config |
Object |
No | Advanced Drizzle ORM configuration for complex table setups. |
#Examples
ts
1import { z } from "alepha"; 2import { $entity, db } from "alepha/orm"; 3 4const userEntity = $entity({ 5 name: "users", 6 schema: z.object({ 7 id: db.primaryKey(), 8 name: z.text(), 9 email: z.email(),10 }),11});