alepha@docs:~/docs/reference/primitives$
cat $sequence.md | pretty1 min read
#$sequence
#Import
typescript
1import { $sequence } from "alepha/orm";
#Overview
Declare a portable, scoped numeric sequence.
Works identically on Postgres, SQLite, and Cloudflare D1 — backed by the
shared alepha_sequences table managed by {@link SequenceProvider}.
#Options
| Option | Type | Required | Description |
|---|---|---|---|
name |
string |
No | Sequence name |
startWith |
number |
No | Starting value used on the very first .next() for a (name, scope) pair |
incrementBy |
number |
No | Amount added on every call to .next() |
#Examples
ts
1class Quests { 2 // Sequence name defaults to the property key — here "shortId". 3 shortId = $sequence(); 4 5 async create(campaignId: number, data: ...) { 6 // Global counter — same primitive, one shared "default" scope. 7 const n = await this.shortId.next(); 8 9 // Scoped counter — one independent sequence per campaign.10 const perCampaign = await this.shortId.next(String(campaignId));11 }12}