commit cc95d5df6e1ca9c69c3d556c6e23645676e3416d
parent 4ca156fd833622b99adebef1953199d688233107
Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Date: Sun, 3 Dec 2023 23:33:57 +0900
nostrdb/add "import -"
Closes: https://github.com/damus-io/nostrdb/pull/21
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c
@@ -3244,6 +3244,24 @@ int _ndb_process_events(struct ndb *ndb, const char *ldjson, size_t json_len, in
return 1;
}
+int ndb_process_events_stream(struct ndb *ndb, FILE* fp)
+{
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t nread;
+
+ while ((nread = getline(&line, &len, stdin)) != -1) {
+ if (line == NULL)
+ break;
+ ndb_process_event(ndb, line, len);
+ }
+
+ if (line)
+ free(line);
+
+ return 1;
+}
+
int ndb_process_client_events(struct ndb *ndb, const char *ldjson, size_t json_len)
{
return _ndb_process_events(ndb, ldjson, json_len, 1);
diff --git a/nostrdb/nostrdb.h b/nostrdb/nostrdb.h
@@ -341,6 +341,7 @@ int ndb_init(struct ndb **ndb, const char *dbdir, struct ndb_config *);
int ndb_db_version(struct ndb *ndb);
int ndb_process_event(struct ndb *, const char *json, int len);
int ndb_process_events(struct ndb *, const char *ldjson, size_t len);
+int ndb_process_events_stream(struct ndb *, FILE* fp);
int ndb_process_client_event(struct ndb *, const char *json, int len);
int ndb_process_client_events(struct ndb *, const char *json, size_t len);
int ndb_begin_query(struct ndb *, struct ndb_txn *);