Skip to content

feat: Export events to JSON Lines#451

Open
Anshumancanrock wants to merge 3 commits intocameri:mainfrom
Anshumancanrock:export-events
Open

feat: Export events to JSON Lines#451
Anshumancanrock wants to merge 3 commits intocameri:mainfrom
Anshumancanrock:export-events

Conversation

@Anshumancanrock
Copy link
Copy Markdown
Contributor

@Anshumancanrock Anshumancanrock commented Apr 10, 2026

Description

This PR adds npm run export [filename.jsonl] , a streaming CLI command that writes all stored events to a .jsonl file in NIP-01 format.

  • Uses pg-query-stream to read rows via cursor (no full dataset in RAM)
  • Each line is a JSON object with the 7 NIP-01 fields: id, pubkey, created_at, kind, tags, content, sig
  • Skips soft-deleted events
  • Logs progress every 10k rows
  • Cleans up DB connection on exit

Related Issue

Closes #405

Motivation and Context

Relay operators currently have no built-in way to export events in a portable format. pg_dump works but is Postgres-specific and not useful for migrating between relay implementations or doing data analysis. This gives them a single command that outputs standard NIP-01 JSON Lines.

How Has This Been Tested?

  • tsc --noEmit ( compiles clean )
  • eslint ( no warnings )
  • Ran npm run export against a local Postgres seeded with 3 million events
  • Validated every line in the output is parseable JSON with exactly the 7 NIP-01 fields
  • Tested custom filename: npm run export -- backup.jsonl
  • Verified both runs produce identical output

Screenshots (if appropriate):

image

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • All new and existing tests passed.

@Anshumancanrock
Copy link
Copy Markdown
Contributor Author

Hi @cameri , Tested the exporter with the same events you sent :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Export events to JSON Lines

1 participant