Files
nostrlib/eventstore/cmd/eventstore
fiatjaf 7289da9c72 improve/refactor websocket connections hoping this will fix the undetected disconnections we're seeing.
this commit also remove all the sonic envelope parsing and reintroduces filters in REQ as a slice instead of as a singleton.

why? well, the sonic stuff wasn't really that fast, it was a little bit but only got fast enough once I introduced unsafe conversions between []byte and string and did weird unsafe reuse of []byte in order to save the values of tags, which would definitely cause issues in the future if the caller wasn't aware of it (and even if they were, like myself).

and the filters stuff is because we abandoned the idea of changing NIP-01 to only accept one filter per REQ.
2025-07-10 22:58:37 -03:00
..
2025-04-15 08:49:28 -03:00
2025-04-16 02:59:47 -03:00
2025-04-15 18:40:56 -03:00
2025-04-15 08:51:25 -03:00

eventstore command-line tool

go install fiatjaf.com/nostr/eventstore/cmd/eventstore@latest

Usage

This should be pretty straightforward. You pipe events or filters, as JSON, to the eventstore command, and they yield something. You can use nak to generate these events or filters easily.

Querying the last 100 events of kind 1

~> nak req -k 1 -l 100 --bare | eventstore -d /path/to/store query
~> # or
~> echo '{"kinds":[1],"limit":100}' | eventstore -d /path/to/store query

This will automatically determine the storage type being used at /path/to/store, but you can also specify it manually using the -t option (-t lmdb, -t sqlite etc).

Saving an event to the store

~> nak event -k 1 -c hello | eventstore -d /path/to/store save
~> # or
~> echo '{"id":"35369e6bae5f77c4e1745c2eb5db84c4493e87f6e449aee62a261bbc1fea2788","pubkey":"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","created_at":1701193836,"kind":1,"tags":[],"content":"hello","sig":"ef08d559e042d9af4cdc3328a064f737603d86ec4f929f193d5a3ce9ea22a3fb8afc1923ee3c3742fd01856065352c5632e91f633528c80e9c5711fa1266824c"}' | eventstore -d /path/to/store save

You can also create a database from scratch if it's a disk database, but then you have to specify -t to sqlite, badger or lmdb.

Connecting to Postgres, MySQL and other remote databases

You should be able to connect by just passing the database connection URI to -d:

~> eventstore -d 'postgres://myrelay:38yg4o83yf48a3s7g@localhost:5432/myrelay?sslmode=disable' <query|save|delete>

That should be prefixed with postgres:// for Postgres, mysql:// for MySQL and https:// for ElasticSearch.