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++
v0.1.12: Create Database flow + scrollable picker with sticky New button (#68)
haidang1810f3d76039ffce
diff --git a/windows/Gridex/ConnectionManager.cpp b/windows/Gridex/ConnectionManager.cppindex 74f951b..5d2cc0a 100644--- a/windows/Gridex/ConnectionManager.cpp+++ b/windows/Gridex/ConnectionManager.cpp@@ -113,10 +113,18 @@ namespace DBModelstry{adapter->connect(effectiveConfig, password);- auto result = adapter->execute(L"SELECT 1");- adapter->disconnect();- ok = result.success;- if (!ok) outError = result.error;+ if (config.databaseType == DatabaseType::MongoDB)+ {+ adapter->disconnect();+ ok = true;+ }+ else+ {+ auto result = adapter->execute(L"SELECT 1");+ adapter->disconnect();+ ok = result.success;+ if (!ok) outError = result.error;+ }}catch (const std::exception& e){diff --git a/windows/Gridex/Gridex.vcxproj b/windows/Gridex/Gridex.vcxprojindex 3fe6a0b..b2df240 100644--- a/windows/Gridex/Gridex.vcxproj+++ b/windows/Gridex/Gridex.vcxproj@@ -286,6 +286,11 @@<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory><DeploymentContent>true</DeploymentContent></Content>+ <Content Include="C:\vcpkg\installed\x64-windows\debug\bin\libssh2.dll" Condition="'$(Configuration)'=='Debug'">+ <Link>libssh2.dll</Link>+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ <DeploymentContent>true</DeploymentContent>+ </Content><Content Include="C:\vcpkg\installed\x64-windows\debug\bin\utf8proc.dll" Condition="'$(Configuration)'=='Debug'"><Link>utf8proc.dll</Link><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>@@ -392,4 +397,4 @@<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.BuildTools.10.0.28000.1721\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.BuildTools.10.0.28000.1721\build\Microsoft.Windows.SDK.BuildTools.targets'))" /><Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.260126.7\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.260126.7\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /></Target>-</Project>\ No newline at end of file+</Project>diff --git a/windows/Gridex/WorkspacePage.cpp b/windows/Gridex/WorkspacePage.cppindex a8733e7..eee3b86 100644--- a/windows/Gridex/WorkspacePage.cpp+++ b/windows/Gridex/WorkspacePage.cpp@@ -1424,6 +1424,17 @@ namespace winrt::Gridex::implementationLoadSidebarFromDB();LoadDatabasePicker();+ // Wire the sticky New-database button at the bottom of the+ // DbPicker flyout. LoadDatabasePicker only manages+ // visibility; the click handler is permanent.+ NewDatabaseBtn().Click([this](+ winrt::Windows::Foundation::IInspectable const&,+ mux::RoutedEventArgs const&)+ {+ DbPickerFlyout().Hide();+ ShowCreateDatabaseDialogAsync();+ });+auto adapter = connMgr_.getActiveAdapter();if (adapter){@@ -2456,31 +2467,167 @@ namespace winrt::Gridex::implementationauto adapter = connMgr_.getActiveAdapter();if (!adapter) return;+ const auto dbType = state_.connection.databaseType;+ const bool supportsCreate =+ dbType == DBModels::DatabaseType::PostgreSQL ||+ dbType == DBModels::DatabaseType::MySQL ||+ dbType == DBModels::DatabaseType::MSSQLServer ||+ dbType == DBModels::DatabaseType::ClickHouse ||+ dbType == DBModels::DatabaseType::MongoDB;+try{auto dbs = adapter->listDatabases();- DbPickerFlyout().Items().Clear();+ auto panel = DbPickerItemsPanel();+ panel.Children().Clear();for (auto& dbName : dbs){- muxc::MenuFlyoutItem item;- item.Text(winrt::hstring(dbName));-- // Highlight current+ // Render each DB as a flat Button styled like a menu+ // item -- Flyout does not accept MenuFlyoutItem children.+ muxc::Button item;+ item.HorizontalAlignment(mux::HorizontalAlignment::Stretch);+ item.HorizontalContentAlignment(mux::HorizontalAlignment::Left);+ item.Background(muxm::SolidColorBrush(+ winrt::Windows::UI::Colors::Transparent()));+ item.BorderThickness(mux::Thickness{0,0,0,0});+ item.Padding(mux::Thickness{12,6,12,6});++ muxc::TextBlock lbl;+ lbl.Text(winrt::hstring(dbName));+ lbl.FontSize(13);if (dbName == state_.connection.database)- item.FontWeight(winrt::Windows::UI::Text::FontWeights::Bold());+ lbl.FontWeight(winrt::Windows::UI::Text::FontWeights::Bold());+ item.Content(lbl);- item.Click([this, dbName](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)+ item.Click([this, dbName]+ (winrt::Windows::Foundation::IInspectable const&,+ mux::RoutedEventArgs const&){+ DbPickerFlyout().Hide();SwitchDatabase(dbName);});- DbPickerFlyout().Items().Append(item);+ panel.Children().Append(item);}++ // Sticky New-database button lives OUTSIDE the scroll+ // region (defined in XAML). Toggle visibility -- engines+ // without DB-level DDL (SQLite, Redis) hide it entirely+ // so we do not surface a guaranteed failure.+ NewDatabaseBtn().Visibility(supportsCreate+ ? mux::Visibility::Visible+ : mux::Visibility::Collapsed);}catch (...) {}}+ winrt::fire_and_forget WorkspacePage::ShowCreateDatabaseDialogAsync()+ {+ auto self = get_strong();+ const auto dbType = state_.connection.databaseType;++ muxc::TextBox nameBox;+ nameBox.PlaceholderText(L"new_database");+ nameBox.Width(300);++ muxc::StackPanel content;+ content.Spacing(8);+ content.Children().Append(nameBox);++ muxc::TextBlock note;+ note.FontSize(11);+ note.Opacity(0.6);+ note.TextWrapping(mux::TextWrapping::Wrap);+ note.Text(L"Issues `CREATE DATABASE \"<name>\"`. Identifier is "+ L"quoted automatically — no need to escape it yourself.");+ content.Children().Append(note);++ muxc::ContentDialog dlg;+ dlg.Title(winrt::box_value(winrt::hstring(L"New database")));+ dlg.Content(content);+ dlg.PrimaryButtonText(L"Create");+ dlg.CloseButtonText(L"Cancel");+ dlg.DefaultButton(muxc::ContentDialogButton::Primary);+ dlg.XamlRoot(this->XamlRoot());++ muxc::ContentDialogResult result{ muxc::ContentDialogResult::None };+ try { result = co_await dlg.ShowAsync(); } catch (...) { co_return; }+ if (result != muxc::ContentDialogResult::Primary) co_return;++ std::wstring dbName = std::wstring(nameBox.Text());+ // Trim — pasted names often carry trailing spaces.+ while (!dbName.empty() && (dbName.front() == L' ' || dbName.front() == L'\t')) dbName.erase(0, 1);+ while (!dbName.empty() && (dbName.back() == L' ' || dbName.back() == L'\t')) dbName.pop_back();+ if (dbName.empty()) co_return;++ // Quote identifier per dialect. PostgreSQL / SQLite / MSSQL use+ // double quotes (MSSQL also accepts [name]); MySQL / ClickHouse+ // use backticks. MongoDB has no DDL — adapter::execute on a+ // CREATE DATABASE there will fail, so we'd want a dedicated+ // path; left as a follow-up.+ wchar_t qOpen, qClose;+ if (dbType == DBModels::DatabaseType::MySQL ||+ dbType == DBModels::DatabaseType::ClickHouse)+ {+ qOpen = qClose = L'`';+ }+ else+ {+ qOpen = qClose = L'"';+ }++ std::wstring quoted;+ quoted.reserve(dbName.size() + 4);+ quoted.push_back(qOpen);+ for (wchar_t c : dbName)+ {+ // Defense-in-depth: escape any embedded quote chars even+ // though the dialog should never produce them.+ if (c == qClose) quoted.push_back(qClose);+ quoted.push_back(c);+ }+ quoted.push_back(qClose);++ std::wstring sql = L"CREATE DATABASE " + quoted;++ try+ {+ auto adapter = connMgr_.getActiveAdapter();+ if (!adapter) co_return;+ auto r = adapter->execute(sql);+ LogQuery(r);+ if (!r.success)+ {+ muxc::ContentDialog err;+ err.Title(winrt::box_value(winrt::hstring(L"Create database failed")));+ err.Content(winrt::box_value(winrt::hstring(r.error)));+ err.CloseButtonText(L"OK");+ err.XamlRoot(this->XamlRoot());+ err.ShowAsync();+ co_return;+ }+ }+ catch (const std::exception& ex)+ {+ muxc::ContentDialog err;+ err.Title(winrt::box_value(winrt::hstring(L"Create database failed")));+ int sz = MultiByteToWideChar(CP_UTF8, 0, ex.what(), -1, nullptr, 0);+ std::wstring msg(sz, L'\0');+ MultiByteToWideChar(CP_UTF8, 0, ex.what(), -1, &msg[0], sz);+ err.Content(winrt::box_value(winrt::hstring(msg)));+ err.CloseButtonText(L"OK");+ err.XamlRoot(this->XamlRoot());+ err.ShowAsync();+ co_return;+ }++ // Refresh the picker so the new database shows up, then switch+ // to it so the sidebar / breadcrumb reflect the new context.+ LoadDatabasePicker();+ SwitchDatabase(dbName);+ }+void WorkspacePage::SwitchDatabase(const std::wstring& dbName){if (dbName == state_.connection.database) return;diff --git a/windows/Gridex/WorkspacePage.h b/windows/Gridex/WorkspacePage.hindex cdb8189..c5e671b 100644--- a/windows/Gridex/WorkspacePage.h+++ b/windows/Gridex/WorkspacePage.h@@ -153,6 +153,11 @@ namespace winrt::Gridex::implementation// ── Database/Schema Picker ──────────────────void LoadDatabasePicker();void SwitchDatabase(const std::wstring& dbName);+ // Show "New database" ContentDialog → execute CREATE DATABASE+ // on the active adapter. Refreshes the picker and switches to+ // the new DB on success. Engines without DB-level DDL (SQLite,+ // Redis) hide the menu entry entirely.+ winrt::fire_and_forget ShowCreateDatabaseDialogAsync();// ── Filter ──────────────────────────────────void ApplyFilter(const std::wstring& column, const std::wstring& op, const std::wstring& value);diff --git a/windows/Gridex/WorkspacePage.xaml b/windows/Gridex/WorkspacePage.xamlindex 93f77c4..2a20dea 100644--- a/windows/Gridex/WorkspacePage.xaml+++ b/windows/Gridex/WorkspacePage.xaml@@ -46,7 +46,49 @@<TextBlock x:Name="DbPickerText" Text="app_db" FontSize="12" /></StackPanel><DropDownButton.Flyout>- <MenuFlyout x:Name="DbPickerFlyout" />+ <!-- Custom Flyout instead of MenuFlyout so the+ "+ New database" button can stay pinned below+ a scrollable database list rather than living+ inside the scroll region. -->+ <Flyout x:Name="DbPickerFlyout" Placement="Bottom">+ <Flyout.FlyoutPresenterStyle>+ <Style TargetType="FlyoutPresenter">+ <Setter Property="Padding" Value="0" />+ <Setter Property="MinWidth" Value="220" />+ </Style>+ </Flyout.FlyoutPresenterStyle>+ <Grid>+ <Grid.RowDefinitions>+ <RowDefinition Height="*" MaxHeight="380" />+ <RowDefinition Height="Auto" />+ </Grid.RowDefinitions>++ <!-- Database list — populated programmatically -->+ <ScrollViewer Grid.Row="0"+ VerticalScrollBarVisibility="Auto"+ HorizontalScrollMode="Disabled">+ <StackPanel x:Name="DbPickerItemsPanel"+ Padding="4" Spacing="0" />+ </ScrollViewer>++ <!-- Sticky bottom: New database button -->+ <Border Grid.Row="1"+ BorderThickness="0,1,0,0"+ BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}">+ <Button x:Name="NewDatabaseBtn"+ HorizontalAlignment="Stretch"+ HorizontalContentAlignment="Left"+ Background="Transparent"+ BorderThickness="0"+ Padding="12,8">+ <StackPanel Orientation="Horizontal" Spacing="8">+ <FontIcon Glyph="" FontSize="12" />+ <TextBlock Text="New database…" FontSize="13" />+ </StackPanel>+ </Button>+ </Border>+ </Grid>+ </Flyout></DropDownButton.Flyout></DropDownButton></StackPanel>diff --git a/windows/README.md b/windows/README.mdindex 9eee7ab..657386e 100644--- a/windows/README.md+++ b/windows/README.md@@ -20,7 +20,7 @@ Project link các lib native qua vcpkg. Cài 1 lần:**Git Bash / MSYS2**:```bash/c/vcpkg/vcpkg.exe install \- sqlite3 libpq libmariadb openssl hiredis \+ sqlite3 libpq libmariadb openssl hiredis libssh2 \nlohmann-json cpp-httplib \--triplet x64-windows```@@ -28,7 +28,7 @@ Project link các lib native qua vcpkg. Cài 1 lần:**PowerShell**:```powershellC:\vcpkg\vcpkg.exe install `- sqlite3 libpq libmariadb openssl hiredis `+ sqlite3 libpq libmariadb openssl hiredis libssh2 `nlohmann-json cpp-httplib `--triplet x64-windows```@@ -36,7 +36,7 @@ C:\vcpkg\vcpkg.exe install `**CMD**:```cmdC:\vcpkg\vcpkg.exe install ^- sqlite3 libpq libmariadb openssl hiredis ^+ sqlite3 libpq libmariadb openssl hiredis libssh2 ^nlohmann-json cpp-httplib ^--triplet x64-windows```@@ -66,29 +66,29 @@ windows/scripts/**Git Bash / MSYS2**:```bashcd /e/dev/be/vura-powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-and-pack.ps1 -Version "0.1.10"+powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-and-pack.ps1 -Version "0.1.12"```**PowerShell (5.1 / 7+)**:```powershellcd E:\dev\be\vura-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.10"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.12"```**CMD**:```cmdcd /d E:\dev\be\vura-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.10"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.12"```Script sẽ:1. Cài/update `vpk` global tool (skip nếu đã có)-2. Build `Gridex.exe` unpackaged, stamp version `0.1.10` vào About section-3. Pack thành `Setup.exe` qua Velopack với metadata version `0.1.10`+2. Build `Gridex.exe` unpackaged, stamp version `0.1.12` vào About section+3. Pack thành `Setup.exe` qua Velopack với metadata version `0.1.12`**Output**: `windows/Releases/`- `Gridex-stable-Setup.exe` — installer user-facing-- `Gridex-0.1.10-stable-full.nupkg` — package Velopack+- `Gridex-0.1.12-stable-full.nupkg` — package Velopack- `releases.stable.json`, `RELEASES-stable` — feed manifests- `Gridex-stable-Portable.zip` — bản portable@@ -140,7 +140,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\install-vppowershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-unpackaged.ps1# Build với version cụ thể — About section hiện đúng string-powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-unpackaged.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-unpackaged.ps1 -Version "0.1.12-test"```**PowerShell**:@@ -149,7 +149,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-unpapowershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1# Build với version cụ thể — About section hiện đúng string-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1 -Version "0.1.12-test"```**CMD**:@@ -158,7 +158,7 @@ REM Dev build — About section hiện "0.0.0-dev"powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1REM Build với version cụ thể — About section hiện đúng string-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-unpackaged.ps1 -Version "0.1.12-test"```Chạy trực tiếp exe để test nhanh mà không cần cài installer:@@ -177,17 +177,17 @@ Chạy trực tiếp exe để test nhanh mà không cần cài installer:**Git Bash / MSYS2**:```bash-powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/pack-velopack.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/pack-velopack.ps1 -Version "0.1.12-test"```**PowerShell**:```powershell-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\pack-velopack.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\pack-velopack.ps1 -Version "0.1.12-test"```**CMD**:```cmd-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\pack-velopack.ps1 -Version "0.1.10-test"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\pack-velopack.ps1 -Version "0.1.12-test"```**Lưu ý**: `-Version` truyền vào `pack-velopack.ps1` **phải khớp** với `-Version` truyền vào `build-unpackaged.ps1`, nếu không thì Velopack sẽ in một số, còn About section của app sẽ in số khác. Dùng `build-and-pack.ps1` ở trên để tránh trường hợp này.@@ -196,10 +196,10 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\pack-velop- `windows/Gridex/GridexVersion.h` — include unconditional file generated- `windows/Gridex/GridexVersion.generated.h` — **auto-generated, gitignored**, do `build-unpackaged.ps1` ghi mỗi lần chạy- - Có `-Version` → `#define GRIDEX_VERSION L"0.1.10"`+ - Có `-Version` → `#define GRIDEX_VERSION L"0.1.12"`- Không `-Version` → `#define GRIDEX_VERSION L"0.0.0-dev"`- `windows/Gridex/SettingsPage.xaml.cpp` — đọc `GRIDEX_VERSION` và set vào `VersionText` text block-- CI workflow `.github/workflows/windows-release.yml` tự parse version từ git tag (`v0.1.10` → `0.1.10`) và forward sang script+- CI workflow `.github/workflows/windows-release.yml` tự parse version từ git tag (`v0.1.12` → `0.1.12`) và forward sang scriptBuild script chỉ rewrite `GridexVersion.generated.h` khi nội dung khác → không force recompile vô ích.@@ -209,17 +209,17 @@ Mặc định Velopack dùng channel `stable`. Nếu muốn phát hành kênh ri**Git Bash / MSYS2**:```bash-powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-and-pack.ps1 -Version "0.1.10-beta.1" -Channel "beta"+powershell -NoProfile -ExecutionPolicy Bypass -File ./windows/scripts/build-and-pack.ps1 -Version "0.1.12-beta.1" -Channel "beta"```**PowerShell**:```powershell-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.10-beta.1" -Channel "beta"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.12-beta.1" -Channel "beta"```**CMD**:```cmd-powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.10-beta.1" -Channel "beta"+powershell -NoProfile -ExecutionPolicy Bypass -File .\windows\scripts\build-and-pack.ps1 -Version "0.1.12-beta.1" -Channel "beta"```Output sẽ là `Gridex-beta-Setup.exe` + `releases.beta.json` — auto-updater phân luồng theo channel.@@ -253,7 +253,7 @@ Chưa cài đủ vcpkg deps. Xem section "Cài vcpkg deps" ở đầu file.### Gridex.exe crash ngay khi khởi động với `MSVCP140.dll not found`Máy thiếu VC++ 2015-2022 Redistributable. Script `build-unpackaged.ps1` tự copy CRT DLLs vào output folder → nếu vẫn lỗi thì check VS install path / logs script.-### Setup.exe cài xong nhưng About hiện `0.0.0-dev` dù pack với `-Version 0.1.10`+### Setup.exe cài xong nhưng About hiện `0.0.0-dev` dù pack với `-Version 0.1.12`Dùng `build-and-pack.ps1` thay vì gọi `pack-velopack.ps1` trực tiếp. Trường hợp chạy `pack-velopack.ps1` với version khác version lúc build `Gridex.exe` → xóa `windows\Gridex\x64\Release\` rồi build lại đúng thứ tự.### Lỗi `pwsh.exe exited with code 9009` trong vcpkg applocal step@@ -288,8 +288,8 @@ del /q .\windows\Gridex\GridexVersion.generated.hCI tự chạy khi push tag matching `v*.*.*`:```bash-git tag v0.1.10-git push origin v0.1.10+git tag v0.1.12+git push origin v0.1.12```GitHub Actions workflow `windows-release.yml` sẽ tự build + pack + upload assets lên GitHub Release. Xem chi tiết ở `.github/workflows/windows-release.yml`.