Corsair
PluginsPostHog

PostHog Database Schema

Database entities and querying synced PostHog data

The PostHog plugin automatically syncs data from PostHog to your database. This allows you to query PostHog data without making API calls, providing faster access and offline capabilities.

New to Corsair? Learn about core concepts like database operations, data synchronization, and multi-tenancy before working with the database.

Full Implementation: For the complete, up-to-date database schema and implementations, see the PostHog plugin source code on GitHub.

Synced Entities

The PostHog plugin syncs the following entities to your database:

  • events - Tracked events

Database API

Access synced data through the db property:

const events = await corsair.posthog.db.events.search({
    data: { event: "purchase" },
});

Events

Schema

{
    id: string;
    event: string;
    distinct_id: string;
    timestamp?: string;
    uuid?: string;
    properties?: Record<string, any>;
    createdAt?: Date | null;
}

Querying Events

Search by event name:

const events = await corsair.posthog.db.events.search({
    data: { event: "purchase" },
});

Search by user:

const userEvents = await corsair.posthog.db.events.search({
    data: { distinct_id: "user-123" },
});

See Database for more information about database concepts and querying patterns.