Relations

Community

Foreign keys for SpacetimeDB: restrict, cascade or set-null deletes with previews, multi-column unique constraints, orphan check and repair, and cursor and live pagination.

    npm i @pogly/spacetimedb-relations

    Referential integrity for SpacetimeDB tables. Declare once how your tables reference each other, and checked writes refuse rows that point nowhere. Deletes then cascade, set the reference to null, or are refused (restrict), all or nothing.

    Before deleting, you can ask what would happen: "this also deletes 3 lists, 12 cards and 30 comments, and unassigns 2 cards". It also adds multi-column unique constraints, a check and repair pass for orphans left behind by older code, and pagination as keyset cursors or live per-client pages.

    • Any module with parent/child data where a dangling reference is a bug: boards, lists and cards; guilds and members; orders and line items; posts and comments.
    • It's especially useful for deletes, where the alternative is hand-written cleanup code in every reducer that removes something.

    Register your tables with relations.table({...}), which hands back a checked handle, and declare rules with relations.reference({ child, column, parent, onDelete }) and relations.unique({...}).

    Inserts, updates and deletes made through the handles enforce the rules inside the same transaction. A violation throws and rolls everything back.

    previewDelete returns the full delete plan without changing anything. The relationsCheck / relationsRepair procedures find and fix what slipped through raw writes. The client-facing names match the Rust and C# versions.

    Related submodules

    History

    An audit log, per-person undo/redo and point-in-time reads for your tables. Every change is recorded in the same transaction: who made it, the action, and the row before and after.

    Lethalchip0/wkCommunity

    Authz

    Roles, scopes and grants for multi-user modules: wildcard permissions, role inheritance, scope trees, expiring grants, invite links, an audit log and row-level security, with no privilege escalation.

    Lethalchip0/wkCommunity

    Cron

    Schedules recurring tasks in a SpacetimeDB module using calendar expressions or fixed intervals. Supports time zones, per-job arguments, failure limits, and runtime schedule changes.

    SpacetimeDB0/wk
    Submodule

    Edit details

    One short paragraph describing the submodule.

    A few bullets for scenarios where this is a good fit.

    A few short paragraphs at the conceptual level.