commit d30774796355cf8324d5857ee6601f5d98ba7252
parent 0780af9125d8766929101a9775cb7c5f843b89e9
Author: William Casarin <jb55@jb55.com>
Date: Sat, 6 Jan 2024 09:05:40 -0800
cli/ndb: allow multiple kind values in query
Diffstat:
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -39,6 +39,7 @@ commands
stat
search [--oldest-first] [--limit 42] <fulltext query>
+ query [-k 42] [-k 1337] [-l 42]
import <line-delimited json file>
settings
diff --git a/ndb.c b/ndb.c
@@ -16,7 +16,7 @@ static int usage()
printf("commands\n\n");
printf(" stat\n");
printf(" search [--oldest-first] [--limit 42] <fulltext query>\n");
- printf(" query [-k 1] [-l 42]\n");
+ printf(" query [-k 42] [-k 1337] [-l 42]\n");
printf(" import <line-delimited json file>\n\n");
printf("settings\n\n");
printf(" --skip-verification skip signature validation\n");
@@ -106,7 +106,7 @@ static void print_note(struct ndb_note *note)
int main(int argc, char *argv[])
{
struct ndb *ndb;
- int i, flags, limit, count;
+ int i, flags, limit, count, current_field;
long nanos;
struct ndb_stat stat;
struct ndb_txn txn;
@@ -186,22 +186,33 @@ int main(int argc, char *argv[])
argv += 2;
argc -= 2;
+ current_field = 0;
for (i = 0; argc && i < 3; i++) {
if (!strcmp(argv[0], "-k")) {
- ndb_filter_start_field(f, NDB_FILTER_KINDS);
+ if (current_field != NDB_FILTER_KINDS)
+ ndb_filter_start_field(f, NDB_FILTER_KINDS);
+ current_field = NDB_FILTER_KINDS;
ndb_filter_add_int_element(f, atoll(argv[1]));
- ndb_filter_end_field(f);
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "-l")) {
limit = atol(argv[1]);
+ if (current_field) {
+ ndb_filter_end_field(f);
+ current_field = 0;
+ }
ndb_filter_start_field(f, NDB_FILTER_LIMIT);
+ current_field = NDB_FILTER_LIMIT;
ndb_filter_add_int_element(f, limit);
ndb_filter_end_field(f);
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "-u")) {
+ if (current_field) {
+ ndb_filter_end_field(f);
+ current_field = 0;
+ }
ndb_filter_start_field(f, NDB_FILTER_UNTIL);
ndb_filter_add_int_element(f, atoll(argv[1]));
ndb_filter_end_field(f);
@@ -210,6 +221,11 @@ int main(int argc, char *argv[])
}
}
+ if (current_field) {
+ ndb_filter_end_field(f);
+ current_field = 0;
+ }
+
struct ndb_query_result results[10000];
ndb_begin_query(ndb, &txn);