lbug 0.12.3-dev.10 → 0.12.3-dev.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lbug-source/CMakeLists.txt +1 -1
- package/lbug-source/tools/shell/embedded_shell.cpp +51 -3
- package/lbug-source/tools/shell/include/embedded_shell.h +2 -0
- package/lbug-source/tools/shell/test/test_shell_commands.py +19 -0
- package/package.json +1 -1
- package/prebuilt/lbugjs-darwin-arm64.node +0 -0
- package/prebuilt/lbugjs-linux-arm64.node +0 -0
- package/prebuilt/lbugjs-linux-x64.node +0 -0
- package/prebuilt/lbugjs-win32-x64.node +0 -0
|
@@ -17,7 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
#include "binder/binder.h"
|
|
19
19
|
#include "catalog/catalog.h"
|
|
20
|
+
#include "catalog/catalog_entry/catalog_entry.h"
|
|
21
|
+
#include "catalog/catalog_entry/index_catalog_entry.h"
|
|
22
|
+
#include "catalog/catalog_entry/node_table_catalog_entry.h"
|
|
23
|
+
#include "catalog/catalog_entry/rel_group_catalog_entry.h"
|
|
24
|
+
#include "catalog/catalog_entry/scalar_macro_catalog_entry.h"
|
|
25
|
+
#include "catalog/catalog_entry/sequence_catalog_entry.h"
|
|
20
26
|
#include "common/exception/parser.h"
|
|
27
|
+
#include "extension/extension_manager.h"
|
|
21
28
|
#include "keywords.h"
|
|
22
29
|
#include "parser/parser.h"
|
|
23
30
|
#include "printer/json_printer.h"
|
|
@@ -62,8 +69,9 @@ struct ShellCommand {
|
|
|
62
69
|
const char* HIGHLIGHT = ":highlight";
|
|
63
70
|
const char* ERRORS = ":render_errors";
|
|
64
71
|
const char* COMPLETE = ":render_completion";
|
|
65
|
-
const
|
|
66
|
-
|
|
72
|
+
const char* SCHEMA = ":schema";
|
|
73
|
+
const std::array<const char*, 13> commandList = {HELP, CLEAR, QUIT, MAX_ROWS, MAX_WIDTH, MODE,
|
|
74
|
+
STATS, MULTI, SINGLE, HIGHLIGHT, ERRORS, COMPLETE, SCHEMA};
|
|
67
75
|
} shellCommand;
|
|
68
76
|
|
|
69
77
|
const char* TAB = " ";
|
|
@@ -413,6 +421,8 @@ int EmbeddedShell::processShellCommands(std::string lineStr) {
|
|
|
413
421
|
setErrors(arg);
|
|
414
422
|
} else if (command == shellCommand.COMPLETE) {
|
|
415
423
|
setComplete(arg);
|
|
424
|
+
} else if (command == shellCommand.SCHEMA) {
|
|
425
|
+
printSchema();
|
|
416
426
|
} else {
|
|
417
427
|
printf("Error: Unknown command: \"%s\". Enter \":help\" for help\n", lineStr.c_str());
|
|
418
428
|
printf("Did you mean: \"%s\"?\n", findClosestCommand(lineStr).c_str());
|
|
@@ -811,7 +821,6 @@ void EmbeddedShell::setComplete(const std::string& completeString) {
|
|
|
811
821
|
} else {
|
|
812
822
|
printf("Cannot parse '%s' to toggle completion highlighting. Expect 'on' or 'off'.\n",
|
|
813
823
|
completeStringLower.c_str());
|
|
814
|
-
return;
|
|
815
824
|
}
|
|
816
825
|
}
|
|
817
826
|
|
|
@@ -832,6 +841,7 @@ void EmbeddedShell::printHelp() {
|
|
|
832
841
|
printf("%s%s [on|off] %stoggle error highlighting on or off\n", TAB, shellCommand.ERRORS, TAB);
|
|
833
842
|
printf("%s%s [on|off] %stoggle completion highlighting on or off\n", TAB, shellCommand.COMPLETE,
|
|
834
843
|
TAB);
|
|
844
|
+
printf("%s%s %sprint database schema\n", TAB, shellCommand.SCHEMA, TAB);
|
|
835
845
|
printf("\n");
|
|
836
846
|
printf("%sNote: you can change and see several system configurations, such as num-threads, \n",
|
|
837
847
|
TAB);
|
|
@@ -1561,5 +1571,43 @@ void EmbeddedShell::printTruncatedExecutionResult(QueryResult& queryResult) cons
|
|
|
1561
1571
|
}
|
|
1562
1572
|
}
|
|
1563
1573
|
|
|
1574
|
+
void EmbeddedShell::printSchema() {
|
|
1575
|
+
std::stringstream ss;
|
|
1576
|
+
auto clientContext = conn->getClientContext();
|
|
1577
|
+
bool transactionStarted = false;
|
|
1578
|
+
if (transaction::Transaction::Get(*clientContext) == NULL) {
|
|
1579
|
+
transaction::TransactionContext::Get(*clientContext)
|
|
1580
|
+
->beginReadTransaction(); // start transaction to get schema
|
|
1581
|
+
transactionStarted = true;
|
|
1582
|
+
}
|
|
1583
|
+
auto extensionCypher = extension::ExtensionManager::Get(*clientContext)->toCypher();
|
|
1584
|
+
if (!extensionCypher.empty()) {
|
|
1585
|
+
ss << extensionCypher << std::endl;
|
|
1586
|
+
}
|
|
1587
|
+
const auto catalog = catalog::Catalog::Get(*clientContext);
|
|
1588
|
+
auto transaction = transaction::Transaction::Get(*clientContext);
|
|
1589
|
+
catalog::ToCypherInfo toCypherInfo;
|
|
1590
|
+
for (const auto& nodeTableEntry :
|
|
1591
|
+
catalog->getNodeTableEntries(transaction, false /* useInternal */)) {
|
|
1592
|
+
ss << nodeTableEntry->toCypher(toCypherInfo) << std::endl;
|
|
1593
|
+
}
|
|
1594
|
+
catalog::RelGroupToCypherInfo relTableToCypherInfo(clientContext);
|
|
1595
|
+
for (const auto& entry : catalog->getRelGroupEntries(transaction, false /* useInternal */)) {
|
|
1596
|
+
ss << entry->toCypher(relTableToCypherInfo) << std::endl;
|
|
1597
|
+
}
|
|
1598
|
+
catalog::RelGroupToCypherInfo relGroupToCypherInfo(clientContext);
|
|
1599
|
+
for (const auto sequenceEntry : catalog->getSequenceEntries(transaction)) {
|
|
1600
|
+
ss << sequenceEntry->toCypher(relGroupToCypherInfo) << std::endl;
|
|
1601
|
+
}
|
|
1602
|
+
for (auto macroName : catalog->getMacroNames(transaction)) {
|
|
1603
|
+
ss << catalog->getScalarMacroFunction(transaction, macroName)->toCypher(macroName)
|
|
1604
|
+
<< std::endl;
|
|
1605
|
+
}
|
|
1606
|
+
if (transactionStarted) {
|
|
1607
|
+
transaction::TransactionContext::Get(*clientContext)->commit();
|
|
1608
|
+
}
|
|
1609
|
+
printf("%s", ss.str().c_str());
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1564
1612
|
} // namespace main
|
|
1565
1613
|
} // namespace lbug
|
|
@@ -18,6 +18,7 @@ def test_help(temp_db) -> None:
|
|
|
18
18
|
" :highlight [on|off] toggle syntax highlighting on or off",
|
|
19
19
|
" :render_errors [on|off] toggle error highlighting on or off",
|
|
20
20
|
" :render_completion [on|off] toggle completion highlighting on or off",
|
|
21
|
+
" :schema print database schema",
|
|
21
22
|
"",
|
|
22
23
|
" Note: you can change and see several system configurations, such as num-threads, ",
|
|
23
24
|
" timeout, and progress_bar using Cypher CALL statements.",
|
|
@@ -636,6 +637,24 @@ def test_completion_highlighting(temp_db) -> None:
|
|
|
636
637
|
)
|
|
637
638
|
|
|
638
639
|
|
|
640
|
+
def test_schema_with_tables(temp_db) -> None:
|
|
641
|
+
test = (
|
|
642
|
+
ShellTest()
|
|
643
|
+
.add_argument(temp_db)
|
|
644
|
+
.statement("CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name));")
|
|
645
|
+
.statement("CREATE NODE TABLE City(name STRING, population INT64, PRIMARY KEY (name));")
|
|
646
|
+
.statement("CREATE REL TABLE Follows(FROM User TO User, since INT64);")
|
|
647
|
+
.statement("CREATE REL TABLE LivesIn(FROM User TO City);")
|
|
648
|
+
.statement(":schema")
|
|
649
|
+
)
|
|
650
|
+
result = test.run()
|
|
651
|
+
# Check that the schema output includes the created tables
|
|
652
|
+
result.check_stdout("CREATE NODE TABLE `User` (`name` STRING,`age` INT64, PRIMARY KEY(`name`));")
|
|
653
|
+
result.check_stdout("CREATE NODE TABLE `City` (`name` STRING,`population` INT64, PRIMARY KEY(`name`));")
|
|
654
|
+
result.check_stdout("CREATE REL TABLE `Follows` (FROM `User` TO `User`, `since` INT64,MANY_MANY);")
|
|
655
|
+
result.check_stdout("CREATE REL TABLE `LivesIn` (FROM `User` TO `City`, MANY_MANY);")
|
|
656
|
+
|
|
657
|
+
|
|
639
658
|
def test_bad_command(temp_db) -> None:
|
|
640
659
|
test = (
|
|
641
660
|
ShellTest()
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|