Querying with nostrdb-rust

3 views
Skip to first unread message

William Casarin

unread,
Apr 12, 2024, 1:02:34 PM4/12/24
to kernelkind, d...@damus.io
On Fri, Apr 12, 2024 at 09:24:43AM GMT, kernelkind wrote:
>> as for bookmarks and relays, we can just use notes in nostrdb for this (relay list, bookmarks list)
>
>do we have rust bindings for this currently?

yes Damus/notedeck is powered entirely by nostrdb. Every note you see on
screen was put there by the nostrdb query engine. The UI only talks to
nostrdb, all the network code does is dump data into it.

You can execute a query like so:

```rust
let limit = 100;
let txn = Transaction::new(&app.ndb)?;
let filter = nostrdb::Filter::new()
.authors(vec![our_pk])
.kinds(vec![42])
.limit(limit)
.build();

let results = ndb.query(&txn, vec![filter], limit)?;
for result in results {
let note = result.note;
let note_key = result.note_key;
// ..
}
```

Subscriptions:

```rust
let subid = ndb.subscribe(vec![filter])

// poll for notes:
let new_note_ids = ndb.poll_for_notes(&sub, 100);
```

---
https://github.com/damus-io/android/issues/111
Reply all
Reply to author
Forward
0 new messages