nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit f9784f8754c2258a28a17f2e178a36255bfa9c4d
parent 3283fc4531f5b7ebac9a3b02c2b6c10c9a94470e
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 30 Apr 2024 23:22:30 +0200

ndb: dump json in filters and fulltext queries

This is much more useful

Diffstat:
Mndb.c | 31+++++++++++++++++++++++++------
Msrc/print_util.h | 24++++++------------------
2 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/ndb.c b/ndb.c @@ -101,14 +101,33 @@ int ndb_print_tag_keys(struct ndb_txn *txn); static void print_note(struct ndb_note *note) { - printf("%d\t%d\t%s", - ndb_note_kind(note), - ndb_note_created_at(note), - ndb_note_content(note)); + static char buf[5000000]; + if (!ndb_note_json(note, buf, sizeof(buf))) { + print_hex_stream(stderr, ndb_note_id(note), 32); + fprintf(stderr, " is too big to print! >5mb"); + return; + } + puts(buf); +} + +static void ndb_print_text_search_result(struct ndb_txn *txn, + struct ndb_text_search_result *r) +{ + size_t len; + struct ndb_note *note; - printf("\n"); + //ndb_print_text_search_key(&r->key); + + if (!(note = ndb_get_note_by_key(txn, r->key.note_id, &len))) { + fprintf(stderr,": note not found"); + return; + } + + //fprintf(stderr,"\n"); + print_note(note); } + int main(int argc, char *argv[]) { struct ndb *ndb; @@ -190,7 +209,7 @@ int main(int argc, char *argv[]) // print results for now for (i = 0; i < results.num_results; i++) { result = &results.results[i]; - printf("[%02d] ", i+1); + //fprintf(stderr, "[%02d] ", i+1); ndb_print_text_search_result(&txn, result); } diff --git a/src/print_util.h b/src/print_util.h @@ -1,7 +1,7 @@ static void ndb_print_text_search_key(struct ndb_text_search_key *key) { - printf("K<'%.*s' %" PRIu64 " %" PRIu64 " note_id:%" PRIu64 ">", key->str_len, key->str, + fprintf(stderr,"K<'%.*s' %" PRIu64 " %" PRIu64 " note_id:%" PRIu64 ">", key->str_len, key->str, key->word_index, key->timestamp, key->note_id); @@ -14,23 +14,11 @@ static void print_hex(unsigned char* data, size_t size) { } } - -static void ndb_print_text_search_result(struct ndb_txn *txn, - struct ndb_text_search_result *r) -{ - size_t len; - struct ndb_note *note; - - ndb_print_text_search_key(&r->key); - - if (!(note = ndb_get_note_by_key(txn, r->key.note_id, &len))) { - printf(": note not found"); - return; +static void print_hex_stream(FILE *stream, unsigned char* data, size_t size) { + size_t i; + for (i = 0; i < size; i++) { + fprintf(stream, "%02x", data[i]); } - - printf(" "); - print_hex(ndb_note_id(note), 32); - - printf("\n%s\n\n---\n", ndb_note_content(note)); } +