Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

feat(windows): add row-relationship extension points to DataGridView + DatabaseAdapter

DangHuynhfd84906fa7e3
diff --git a/windows/Gridex/DataGridView.cpp b/windows/Gridex/DataGridView.cpp
index fdc1416..97aa671 100644
--- a/windows/Gridex/DataGridView.cpp
+++ b/windows/Gridex/DataGridView.cpp
@@ -115,11 +115,35 @@ namespace winrt::Gridex::implementation
});
contextMenu.Items().Append(deleteItem);
- // Gate Delete on read-only mode + row selection at open time so
- // the menu reflects the grid's actual state each right-click.
- contextMenu.Opening([this, deleteItem](auto&&, auto&&)
+ // "View Relationship" is an opt-in item: stays Collapsed until a
+ // host wires OnViewRelationshipsRequested. OSS builds never set
+ // it, so the menu only shows Refresh + Delete there. Enterprise
+ // builds wire it per connection (relational DBs only).
+ auto viewRelSeparator = muxc::MenuFlyoutSeparator{};
+ contextMenu.Items().Append(viewRelSeparator);
+
+ muxc::MenuFlyoutItem viewRelItem;
+ viewRelItem.Text(L"View Relationship");
+ muxc::FontIcon viewRelIcon;
+ viewRelIcon.Glyph(L"\xE71B"); // Link
+ viewRelItem.Icon(viewRelIcon);
+ viewRelItem.Click([this](auto&&, auto&&)
+ {
+ if (OnViewRelationshipsRequested) OnViewRelationshipsRequested();
+ });
+ contextMenu.Items().Append(viewRelItem);
+
+ // Gate Delete + View Relationship at flyout open time so the
+ // menu reflects the grid's actual state each right-click.
+ contextMenu.Opening([this, deleteItem, viewRelItem, viewRelSeparator](auto&&, auto&&)
{
deleteItem.IsEnabled(!readOnly_ && selectedRow_ >= 0);
+ bool showViewRel = static_cast<bool>(OnViewRelationshipsRequested);
+ auto vis = showViewRel ? mux::Visibility::Visible
+ : mux::Visibility::Collapsed;
+ viewRelSeparator.Visibility(vis);
+ viewRelItem.Visibility(vis);
+ viewRelItem.IsEnabled(showViewRel && selectedRow_ >= 0);
});
this->ContextFlyout(contextMenu);
diff --git a/windows/Gridex/DataGridView.h b/windows/Gridex/DataGridView.h
index 341ffcd..a038531 100644
--- a/windows/Gridex/DataGridView.h
+++ b/windows/Gridex/DataGridView.h
@@ -52,6 +52,13 @@ namespace winrt::Gridex::implementation
std::function<void(const std::wstring& refTable,
const std::wstring& refSchema)> OnForeignKeyClicked;
+ // Callback when user picks "View Relationship" from the context
+ // menu. Opt-in extension point — the menu item stays Collapsed
+ // until a host wires this, so OSS builds see no visible item.
+ // Host (WorkspacePage) resolves current table/schema + selected
+ // row's PK from its own state and opens the relationship dialog.
+ std::function<void()> OnViewRelationshipsRequested;
+
// Get selected row data for copy
const DBModels::TableRow* GetSelectedRow() const;
diff --git a/windows/Gridex/MSSQLAdapter.cpp b/windows/Gridex/MSSQLAdapter.cpp
index 79dd74d..7f11cc6 100644
--- a/windows/Gridex/MSSQLAdapter.cpp
+++ b/windows/Gridex/MSSQLAdapter.cpp
@@ -71,6 +71,17 @@ namespace DBModels
return escaped;
}
+ // Public wrappers — wstring in, wstring out. Delegate to utf8 helpers.
+ std::wstring MSSQLAdapter::quoteSqlLiteral(const std::wstring& value) const
+ {
+ return fromUtf8(quoteLiteral(value));
+ }
+
+ std::wstring MSSQLAdapter::quoteSqlIdentifier(const std::wstring& name) const
+ {
+ return fromUtf8(quoteIdentifier(name));
+ }
+
void MSSQLAdapter::ensureConnected() const
{
if (!connected_ || !hDbc_)
diff --git a/windows/Gridex/Models/DatabaseAdapter.h b/windows/Gridex/Models/DatabaseAdapter.h
index 11a2065..8ae4c6a 100644
--- a/windows/Gridex/Models/DatabaseAdapter.h
+++ b/windows/Gridex/Models/DatabaseAdapter.h
@@ -93,6 +93,29 @@ namespace DBModels
virtual std::wstring serverVersion() = 0;
virtual std::wstring currentDatabase() = 0;
+ // ── SQL string assembly helpers ─────────────
+ // Quote a literal value for this DB engine's SQL grammar, e.g.
+ // O'Brien → 'O''Brien'. Used by callers that assemble ad-hoc
+ // WHERE clauses outside the adapter's own CRUD path (enterprise
+ // row-relationship graph builds SELECT ... WHERE col IN (...)).
+ // Default throws — non-SQL adapters (Mongo, Redis) inherit the
+ // default so accidental calls fail loudly instead of silently
+ // producing wrong SQL.
+ virtual std::wstring quoteSqlLiteral(const std::wstring& /*value*/) const
+ {
+ throw DatabaseError(DatabaseError::Code::Unknown,
+ "quoteSqlLiteral not supported on this adapter");
+ }
+
+ // Quote an identifier (table / column / schema) for this engine's
+ // grammar: PostgreSQL/SQLite "name", MySQL `name`, MSSQL [name].
+ // Same rationale and default-throw semantics as quoteSqlLiteral.
+ virtual std::wstring quoteSqlIdentifier(const std::wstring& /*name*/) const
+ {
+ throw DatabaseError(DatabaseError::Code::Unknown,
+ "quoteSqlIdentifier not supported on this adapter");
+ }
+
// ── Adapter-specific tuning (default: no-op) ───
// Redis uses this to set the SCAN MATCH pattern for fetchRows.
// SQL adapters ignore it. Pass "*" or empty to disable filtering.
diff --git a/windows/Gridex/Models/MSSQLAdapter.h b/windows/Gridex/Models/MSSQLAdapter.h
index e40fc3c..fdb6a76 100644
--- a/windows/Gridex/Models/MSSQLAdapter.h
+++ b/windows/Gridex/Models/MSSQLAdapter.h
@@ -78,6 +78,10 @@ namespace DBModels
std::wstring serverVersion() override;
std::wstring currentDatabase() override;
+ // ── SQL string assembly ─────────────────────
+ std::wstring quoteSqlLiteral(const std::wstring& value) const override;
+ std::wstring quoteSqlIdentifier(const std::wstring& name) const override;
+
private:
SQLHENV hEnv_ = nullptr;
SQLHDBC hDbc_ = nullptr;
diff --git a/windows/Gridex/Models/MySQLAdapter.h b/windows/Gridex/Models/MySQLAdapter.h
index dbd5bee..6d5139f 100644
--- a/windows/Gridex/Models/MySQLAdapter.h
+++ b/windows/Gridex/Models/MySQLAdapter.h
@@ -64,6 +64,10 @@ namespace DBModels
std::wstring serverVersion() override;
std::wstring currentDatabase() override;
+ // SQL string assembly
+ std::wstring quoteSqlLiteral(const std::wstring& value) const override;
+ std::wstring quoteSqlIdentifier(const std::wstring& name) const override;
+
private:
MYSQL* conn_ = nullptr;
bool connected_ = false;
diff --git a/windows/Gridex/Models/PostgreSQLAdapter.h b/windows/Gridex/Models/PostgreSQLAdapter.h
index 2b0e8cd..e0ab5a7 100644
--- a/windows/Gridex/Models/PostgreSQLAdapter.h
+++ b/windows/Gridex/Models/PostgreSQLAdapter.h
@@ -64,6 +64,10 @@ namespace DBModels
std::wstring serverVersion() override;
std::wstring currentDatabase() override;
+ // ── SQL string assembly ─────────────────────
+ std::wstring quoteSqlLiteral(const std::wstring& value) const override;
+ std::wstring quoteSqlIdentifier(const std::wstring& name) const override;
+
private:
PGconn* conn_ = nullptr;
bool connected_ = false;
diff --git a/windows/Gridex/Models/SQLiteAdapter.h b/windows/Gridex/Models/SQLiteAdapter.h
index 2bd65bf..c4c64c7 100644
--- a/windows/Gridex/Models/SQLiteAdapter.h
+++ b/windows/Gridex/Models/SQLiteAdapter.h
@@ -63,6 +63,10 @@ namespace DBModels
std::wstring serverVersion() override;
std::wstring currentDatabase() override;
+ // SQL string assembly
+ std::wstring quoteSqlLiteral(const std::wstring& value) const override;
+ std::wstring quoteSqlIdentifier(const std::wstring& name) const override;
+
private:
sqlite3* db_ = nullptr;
bool connected_ = false;
diff --git a/windows/Gridex/MySQLAdapter.cpp b/windows/Gridex/MySQLAdapter.cpp
index c5a248b..977ba8e 100644
--- a/windows/Gridex/MySQLAdapter.cpp
+++ b/windows/Gridex/MySQLAdapter.cpp
@@ -49,6 +49,17 @@ namespace DBModels
return escaped;
}
+ // Public wrappers — wstring in, wstring out. Delegate to utf8 helpers.
+ std::wstring MySQLAdapter::quoteSqlLiteral(const std::wstring& value) const
+ {
+ return fromUtf8(quoteLiteral(value));
+ }
+
+ std::wstring MySQLAdapter::quoteSqlIdentifier(const std::wstring& name) const
+ {
+ return fromUtf8(quoteIdentifier(name));
+ }
+
void MySQLAdapter::ensureConnected() const
{
if (!connected_ || !conn_)
diff --git a/windows/Gridex/PostgreSQLAdapter.cpp b/windows/Gridex/PostgreSQLAdapter.cpp
index 487e351..eea2fb4 100644
--- a/windows/Gridex/PostgreSQLAdapter.cpp
+++ b/windows/Gridex/PostgreSQLAdapter.cpp
@@ -51,6 +51,19 @@ namespace DBModels
return escaped;
}
+ // Public wrappers over the existing utf8 helpers. Return wstring so
+ // callers that assemble wide SQL (enterprise row graph) don't have
+ // to UTF-8 round-trip themselves.
+ std::wstring PostgreSQLAdapter::quoteSqlLiteral(const std::wstring& value) const
+ {
+ return fromUtf8(quoteLiteral(value));
+ }
+
+ std::wstring PostgreSQLAdapter::quoteSqlIdentifier(const std::wstring& name) const
+ {
+ return fromUtf8(quoteIdentifier(name));
+ }
+
void PostgreSQLAdapter::ensureConnected() const
{
if (!connected_ || !conn_)
diff --git a/windows/Gridex/SQLiteAdapter.cpp b/windows/Gridex/SQLiteAdapter.cpp
index f056cbf..fc3ac1c 100644
--- a/windows/Gridex/SQLiteAdapter.cpp
+++ b/windows/Gridex/SQLiteAdapter.cpp
@@ -48,6 +48,17 @@ namespace DBModels
return escaped;
}
+ // Public wrappers — wstring in, wstring out. Delegate to utf8 helpers.
+ std::wstring SQLiteAdapter::quoteSqlLiteral(const std::wstring& value) const
+ {
+ return fromUtf8(quoteLiteral(value));
+ }
+
+ std::wstring SQLiteAdapter::quoteSqlIdentifier(const std::wstring& name) const
+ {
+ return fromUtf8(quoteIdentifier(name));
+ }
+
void SQLiteAdapter::ensureConnected() const
{
if (!connected_ || !db_)