Your First Event
Send an event to DeltaBase in a few minutes
You signed up. Let’s put one fact in the log and read it back. No manifesto,
just append, then readStream.
You will:
- Create an event store (name it something you will type in
getEventStore, something cool likethe-best-event-store-in-the-world, or keep it simple likemy-event-store). - Create an API key and export
DELTABASE_API_KEY. - Save
index.ts, run it, peek at the dashboard or Studio.
Step 1: Create an event store
Section titled “Step 1: Create an event store”In the dashboard, Create Event Store. Use a name like my-event-store so it
lines up with the code below, or change the string in getEventStore('…') to
whatever you picked.
Step 2: Get an API key
Section titled “Step 2: Get an API key”Dashboard → API Keys → Create.
Copy the key once, then:
export DELTABASE_API_KEY='paste-your-key-here'Step 3: Send an event
Section titled “Step 3: Send an event”Install the SDK:
pnpm add @delta-base/servernpm install @delta-base/serverSave as index.ts (same as onboarding):
import { DeltaBase } from '@delta-base/server';
const client = new DeltaBase({ apiKey: process.env.DELTABASE_API_KEY, baseUrl: 'https://api.delta-base.com',});
async function main() { const eventStore = client.getEventStore('my-event-store');
// Append your first event await eventStore.appendToStream('my-first-stream', [ { type: 'user.created', data: { name: 'Alice', email: 'alice@example.com' }, }, ]);
// Read events back const { events } = await eventStore.readStream('my-first-stream'); console.log('Events:', events);}
main().catch(console.error);For a local stack, point baseUrl at your dev API (see
Local development) instead of
https://api.delta-base.com.
Install a runner if you need one, then execute:
pnpm add -D tsxpnpm dlx tsx index.tsnpm install -D tsxnpx tsx index.tsStep 4: See it
Section titled “Step 4: See it”Dashboard → your event store → Events. You should see user.created on
stream my-first-stream.
What that was
Section titled “What that was”One append, one read. The stream id is just a string you choose; the event
type and data are your fact. Everything else in event sourcing grows out of
that loop.
Next stops: Event sourcing fundamentals for the mental model, or Banking system for a full tutorial.
When it breaks
Section titled “When it breaks”Unauthorized: Check echo $DELTABASE_API_KEY.
Event store not found: getEventStore('my-event-store') must match the store
name in the dashboard exactly.
Wrong API host: Use https://api.delta-base.com for production, or your
local base URL for dev.
Append errors on a second run: The stream my-first-stream may already
exist. Use a new stream id, or learn optimistic concurrency with
expectedStreamVersion when you move past the first demo.