nostrdb/add "import -"

Closes: https://github.com/damus-io/nostrdb/pull/21
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Yasuhiro Matsumoto
2023-12-03 23:33:57 +09:00
committed by Daniel D’Aquino
parent 4ca156fd83
commit cc95d5df6e
2 changed files with 19 additions and 0 deletions

View File

@@ -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);

View File

@@ -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 *);