diff options
Diffstat (limited to 'sinksh/syntax_modules/sink_inspect.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 457ad12..0d2ea00 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -43,7 +43,7 @@ namespace SinkInspect | |||
43 | bool inspect(const QStringList &args, State &state) | 43 | bool inspect(const QStringList &args, State &state) |
44 | { | 44 | { |
45 | if (args.isEmpty()) { | 45 | if (args.isEmpty()) { |
46 | state.printError(QObject::tr("Options: $type [--resource $resource] [--db $db] [--filter $id]")); | 46 | state.printError(QObject::tr("Options: $type [--resource $resource] [--db $db] [--filter $id] [--showinternal]")); |
47 | } | 47 | } |
48 | auto options = SyntaxTree::parseOptions(args); | 48 | auto options = SyntaxTree::parseOptions(args); |
49 | auto resource = options.options.value("resource").value(0); | 49 | auto resource = options.options.value("resource").value(0); |
@@ -53,6 +53,7 @@ bool inspect(const QStringList &args, State &state) | |||
53 | 53 | ||
54 | auto dbs = options.options.value("db"); | 54 | auto dbs = options.options.value("db"); |
55 | auto idFilter = options.options.value("filter"); | 55 | auto idFilter = options.options.value("filter"); |
56 | bool showInternal = options.options.contains("showinternal"); | ||
56 | 57 | ||
57 | auto databases = transaction.getDatabaseNames(); | 58 | auto databases = transaction.getDatabaseNames(); |
58 | if (dbs.isEmpty()) { | 59 | if (dbs.isEmpty()) { |
@@ -71,31 +72,46 @@ bool inspect(const QStringList &args, State &state) | |||
71 | Q_ASSERT(false); | 72 | Q_ASSERT(false); |
72 | state.printError(e.message); | 73 | state.printError(e.message); |
73 | }, false); | 74 | }, false); |
74 | QByteArray filter; | 75 | |
75 | if (!idFilter.isEmpty()) { | 76 | if (showInternal) { |
76 | filter = idFilter.first().toUtf8(); | 77 | //Print internal keys |
77 | } | 78 | db.scan("__internal", [&] (const QByteArray &key, const QByteArray &data) { |
78 | bool findSubstringKeys = !filter.isEmpty(); | 79 | state.printLine("Internal: " + key + " Value: " + QString::fromUtf8(data)); |
79 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { | ||
80 | if (isMainDb) { | ||
81 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | ||
82 | if (!buffer.isValid()) { | ||
83 | state.printError("Read invalid buffer from disk: " + key); | ||
84 | } else { | ||
85 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); | ||
86 | state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation())); | ||
87 | } | ||
88 | } else { | ||
89 | state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); | ||
90 | } | ||
91 | return true; | 80 | return true; |
92 | }, | 81 | }, |
93 | [&](const Sink::Storage::DataStore::Error &e) { | 82 | [&](const Sink::Storage::DataStore::Error &e) { |
94 | state.printError(e.message); | 83 | state.printError(e.message); |
95 | }, | 84 | }, |
96 | findSubstringKeys); | 85 | true, false); |
86 | } else { | ||
87 | QByteArray filter; | ||
88 | if (!idFilter.isEmpty()) { | ||
89 | filter = idFilter.first().toUtf8(); | ||
90 | } | ||
97 | 91 | ||
98 | state.printLine("Found " + QString::number(count) + " entries"); | 92 | //Print rest of db |
93 | bool findSubstringKeys = !filter.isEmpty(); | ||
94 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { | ||
95 | if (isMainDb) { | ||
96 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | ||
97 | if (!buffer.isValid()) { | ||
98 | state.printError("Read invalid buffer from disk: " + key); | ||
99 | } else { | ||
100 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); | ||
101 | state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation())); | ||
102 | } | ||
103 | } else { | ||
104 | state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); | ||
105 | } | ||
106 | return true; | ||
107 | }, | ||
108 | [&](const Sink::Storage::DataStore::Error &e) { | ||
109 | state.printError(e.message); | ||
110 | }, | ||
111 | findSubstringKeys); | ||
112 | |||
113 | state.printLine("Found " + QString::number(count) + " entries"); | ||
114 | } | ||
99 | return false; | 115 | return false; |
100 | } | 116 | } |
101 | 117 | ||