DocumentationCore Protocol

@painda/persistence (Enterprise)

Bridge the gap between ultra-fast in-memory processing and cold database storage.

Overview

Standard WebSocket servers force you to bloat your message handlers with manual database inserts. The @painda/persistence middleware automates this. You define the message types you want persisted, and it handles the batching and writing in the background.

apps/server/index.ts

import { PPServer } from "@painda/core";
import { PPPersistenceMiddleware } from "@painda/persistence";
import { PostgresAdapter } from "@painda/persistence/adapters/postgres";

const server = new PPServer({ port: 7000 });

// Automatically sync "chat-message" to Postgres asynchronously
new PPPersistenceMiddleware(server, {
  adapter: new PostgresAdapter(process.env.DATABASE_URL),
  syncTypes: ["chat-message", "game-state-snapshot"]
});

Supported Adapters

  • PostgreSQL / Prisma: Relational bridging.
  • Redis: Key-value persistence for ultra-hot state that needs to survive server reboots.
  • MongoDB: Document storage for nested JSON payloads.