MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / bindFunc

Function bindFunc

src/function/table/show_tables.cpp:59–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59static std::unique_ptr<TableFuncBindData> bindFunc(const main::ClientContext* context,
60 const TableFuncBindInput* input) {
61 std::vector<std::string> columnNames;
62 std::vector<LogicalType> columnTypes;
63 columnNames.emplace_back("id");
64 columnTypes.emplace_back(LogicalType::UINT64());
65 columnNames.emplace_back("name");
66 columnTypes.emplace_back(LogicalType::STRING());
67 columnNames.emplace_back("type");
68 columnTypes.emplace_back(LogicalType::STRING());
69 columnNames.emplace_back("database name");
70 columnTypes.emplace_back(LogicalType::STRING());
71 columnNames.emplace_back("comment");
72 columnTypes.emplace_back(LogicalType::STRING());
73 std::vector<TableInfo> tableInfos;
74 auto transaction = transaction::Transaction::Get(*context);
75 auto dbManager = main::DatabaseManager::Get(*context);
76
77 // Show tables from the main database (local) - always show these separately from graphs
78 if (!context->hasDefaultDatabase()) {
79 auto catalog = context->getDatabase()->getCatalog();
80 for (auto& entry :
81 catalog->getTableEntries(transaction, context->useInternalCatalogEntry())) {
82 std::string dbName = LOCAL_DB_NAME;
83 // For foreign-backed rel tables, use the foreign database name
84 if (entry->getType() == CatalogEntryType::REL_GROUP_ENTRY) {
85 auto relEntry = entry->constPtrCast<RelGroupCatalogEntry>();
86 if (!relEntry->getForeignDatabaseName().empty()) {
87 dbName = relEntry->getForeignDatabaseName();
88 }
89 }
90 // For shadow node tables, use shadow db name
91 if (entry->getType() == CatalogEntryType::NODE_TABLE_ENTRY) {
92 auto nodeEntry = entry->constPtrCast<NodeTableCatalogEntry>();
93 if (!nodeEntry->getForeignDatabaseName().empty()) {
94 dbName = SHADOW_DB_NAME;
95 }
96 }
97 tableInfos.emplace_back(entry->getName(), entry->getTableID(),
98 TableTypeUtils::toString(entry->getTableType()), dbName, entry->getComment());
99 }
100 }
101
102 // Show tables from all graphs
103 for (auto& graph : dbManager->getGraphs()) {
104 auto graphName = graph->getCatalogName();
105 for (auto& entry :
106 graph->getTableEntries(transaction, context->useInternalCatalogEntry())) {
107 tableInfos.emplace_back(entry->getName(), entry->getTableID(),
108 TableTypeUtils::toString(entry->getTableType()),
109 std::format("{}(graph)", graphName), entry->getComment());
110 }
111 }
112
113 // Show tables from attached databases
114 for (auto attachedDatabase : dbManager->getAttachedDatabases()) {
115 auto databaseName = attachedDatabase->getDBName();
116 auto databaseType = attachedDatabase->getDBType();

Callers

nothing calls this directly

Calls 15

emplace_backMethod · 0.80
getCatalogMethod · 0.80
getTableEntriesMethod · 0.80
getGraphsMethod · 0.80
getAttachedDatabasesMethod · 0.80
createVariablesMethod · 0.80
toStringFunction · 0.50
hasDefaultDatabaseMethod · 0.45
getDatabaseMethod · 0.45
getTypeMethod · 0.45
emptyMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected