Compare commits
165 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8236078ace | |||
| 4e084b914f | |||
| fc9965d757 | |||
| ff315a8e1c | |||
| f4863923a5 | |||
| 7fe5fa02f6 | |||
| 18139ee11b | |||
| daa79bf0d6 | |||
| 541fe5b0a8 | |||
| 6cc8213490 | |||
| 5bf36d70c5 | |||
| 593df7abba | |||
| 5776226130 | |||
| fab96d4602 | |||
| abfa27d20e | |||
| 104456049d | |||
| 9ea060fda7 | |||
| d568b75530 | |||
| c0a11d936a | |||
| 994cef8357 | |||
| 82ddab1431 | |||
| d1b0b4986e | |||
| 25d1609220 | |||
| 2609223ea6 | |||
| 8be4c79556 | |||
| 5006ac6e91 | |||
| e2eb81da77 | |||
| 0f5bf963ba | |||
| 8612ad630e | |||
| 0dc90a546b | |||
| 5c9ad3bd9d | |||
| d6c6dd594c | |||
| 12fb79bb8b | |||
| 9003982da8 | |||
| 548f3dc68c | |||
| 43f334331b | |||
| cccb06caf0 | |||
| f257901965 | |||
| 8e36e00460 | |||
| 07a749bb03 | |||
| fb069ed3b2 | |||
| f5d2e69007 | |||
| 35c2b01843 | |||
| 858af50136 | |||
| 13647edc0d | |||
| 8b2c09d859 | |||
| 03c3a142df | |||
| 318e634d9b | |||
| a51d568a87 | |||
| 99c20e76de | |||
| bc09478278 | |||
| 18d782e7e5 | |||
| 4e6a359b10 | |||
| f42bdf219b | |||
| 2f2972f97e | |||
| 5cf6a838ae | |||
| 8e5e80af79 | |||
| 49890599ea | |||
| c541e8b941 | |||
| 877f291a1f | |||
| 6145320858 | |||
| 8296a2fec9 | |||
| 223d13be58 | |||
| eca27dcd4f | |||
| 0f2a3e021a | |||
| 90259fb2b9 | |||
| 7573cf0453 | |||
| 6dd0635c9e | |||
| ce3d08740f | |||
| 8f5e1054fb | |||
| 1ac96eb133 | |||
| 53e9b6555e | |||
| e1a9f187cb | |||
| ee3110162b | |||
| 35a83eb483 | |||
| 60add3be86 | |||
| 2f65ffdd70 | |||
| aad92d27e9 | |||
| 21151be8a3 | |||
| f78eec1872 | |||
| 8af27f8834 | |||
| 0d3b90b879 | |||
| 2b59efc410 | |||
| 7fbf2ef1ed | |||
| d7e3363173 | |||
| cecfc338d4 | |||
| 35f09fc072 | |||
| 2163b46907 | |||
| 81b6b08e7b | |||
| f31724a110 | |||
| 063a8ca837 | |||
| 1cfc94a42b | |||
| 053e07c319 | |||
| 0b91c379b8 | |||
| 7b4cc885f5 | |||
| 3b17ddd8a4 | |||
| 8d051a14e5 | |||
| 4735c391bd | |||
| 0866e5edac | |||
| 5c44dc5f54 | |||
| a7dd1ca340 | |||
| abcf7dbfe5 | |||
| d359f42b24 | |||
| 7cec5cee4c | |||
| be91cd54c6 | |||
| b141aaaa6c | |||
| 493ab846b9 | |||
| d3ebcb4666 | |||
| 50cf207eae | |||
| e5cbbb6822 | |||
| 18674568dd | |||
| 748dd96267 | |||
| c5578daa9f | |||
| 3bc7f539ad | |||
| 52677224c1 | |||
| 0a31eab9f2 | |||
| 011063597d | |||
| 71c182692a | |||
| e15af5a544 | |||
| ba7228ad44 | |||
| 650c9e7183 | |||
| 471737f421 | |||
| d2b9618da0 | |||
| f0f0ff7904 | |||
| 639da11ab3 | |||
| fc084d7190 | |||
| e2111017eb | |||
| ef70e5825a | |||
| 15b29b32ce | |||
| 975e120530 | |||
| 5b8883d31a | |||
| ce43f5765c | |||
| feffa67677 | |||
| a14e58297a | |||
| 2b309fbda7 | |||
| 70db402cdf | |||
| a82d5e6b26 | |||
| 28570b0b96 | |||
| 9bf84fa140 | |||
| eb34221620 | |||
| cc3ba4d9f0 | |||
| f79d17afed | |||
| d7c2282335 | |||
| 43002a9fde | |||
| bc33d26cfd | |||
| 38d9e6238f | |||
| a653ef8ca4 | |||
| cc336366c9 | |||
| 8f105183eb | |||
| b45faa2e73 | |||
| 7e5d17100d | |||
| a817e5fa21 | |||
| 3d185033f3 | |||
| 924957d00d | |||
| d674078071 | |||
| 5992d19906 | |||
| 8cac46e9f2 | |||
| db5f6816c5 | |||
| 3a4bdbde94 | |||
| 0363bc65f4 | |||
| a47898e099 | |||
| 1487b18a3a | |||
| 04ef53720f | |||
| bc82aacd57 | |||
| 6dcc1afd6b |
6
.gitignore
vendored
@@ -1,4 +1,8 @@
|
|||||||
testdata/
|
testdata/
|
||||||
liblcl*
|
liblcl-*.zip
|
||||||
|
liblcl.so
|
||||||
|
liblcl.dll
|
||||||
yvbolt
|
yvbolt
|
||||||
yvbolt.exe
|
yvbolt.exe
|
||||||
|
yvbolt.linux64.tar.xz
|
||||||
|
yvbolt.win64.zip
|
||||||
40
Makefile
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
SHELL:=/bin/bash
|
||||||
|
SOURCES=$(find . -name '*.go' -type f)
|
||||||
|
.DEFAULT_GOAL := dist
|
||||||
|
|
||||||
|
.PHONY: generate
|
||||||
|
generate:
|
||||||
|
~/go/bin/miqt-uic -InFile mainwindow.ui -OutFile mainwindow.go -Qt6
|
||||||
|
~/go/bin/miqt-uic -InFile connectionDialog.ui -OutFile connectionDialog.go -Qt6
|
||||||
|
~/go/bin/miqt-rcc -Input embed.qrc -Qt6
|
||||||
|
|
||||||
|
.PHONY: designer
|
||||||
|
designer:
|
||||||
|
/usr/lib/qt6/bin/designer &
|
||||||
|
|
||||||
|
yvbolt: $(SOURCES)
|
||||||
|
~/go/bin/miqt-docker native -minify-build
|
||||||
|
chmod 755 yvbolt
|
||||||
|
upx --lzma yvbolt
|
||||||
|
|
||||||
|
yvbolt.exe: $(SOURCES)
|
||||||
|
~/go/bin/miqt-docker win64-cross-go1.24-qt6.5-static -windows-build --tags=windowsqtstatic
|
||||||
|
upx --lzma yvbolt.exe
|
||||||
|
|
||||||
|
yvbolt.apk: $(SOURCES)
|
||||||
|
~/go/bin/miqt-docker android-armv8a-go1.23-qt6.6-dynamic -android-build
|
||||||
|
|
||||||
|
yvbolt.linux64.tar.xz: yvbolt
|
||||||
|
rm -f yvbolt.linux64.tar.xz
|
||||||
|
XZ_OPT='-T0 -9' tar caf yvbolt.linux64.tar.xz --owner=0 --group=0 yvbolt
|
||||||
|
|
||||||
|
yvbolt.win64.zip: yvbolt.exe
|
||||||
|
rm -f yvbolt.win64.zip
|
||||||
|
zip -9 yvbolt.win64.zip yvbolt.exe
|
||||||
|
|
||||||
|
.PHONY: dist
|
||||||
|
dist: yvbolt.linux64.tar.xz yvbolt.win64.zip
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -f yvbolt.exe yvbolt yvbolt.linux64.tar.xz yvbolt.win64.zip
|
||||||
138
README.md
@@ -1,23 +1,30 @@
|
|||||||
# yvbolt
|
# yvbolt
|
||||||
|
|
||||||
A graphical browser for multiple databases using [GoVCL](https://z-kit.cc/en/).
|
A graphical interface for multiple databases.
|
||||||
|
|
||||||
This is an experimental application and you should generally prefer to use [qbolt](https://code.ivysaur.me/qbolt).
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Native desktop application, running on Linux, Windows, and macOS
|
- Native desktop application, running on Linux, Windows, macOS, and Android
|
||||||
- Connect to multiple databases
|
- Connect to multiple databases at once
|
||||||
- Browse table/bucket content
|
- Browse table/bucket content
|
||||||
|
- Use context menu to perform special table/bucket actions
|
||||||
- Run custom SQL queries
|
- Run custom SQL queries
|
||||||
|
- Select text to run partial query
|
||||||
- Safe handling for non-UTF8 key and data fields
|
- Safe handling for non-UTF8 key and data fields
|
||||||
- Supported databases:
|
|
||||||
- Bolt
|
See also [qbolt](https://code.ivysaur.me/qbolt) for more/different functionality.
|
||||||
- Full compatibility via the upstream [etcd-io/bbolt](https://github.com/etcd-io/bbolt) library
|
|
||||||
- Recursive bucket support
|
## Supported databases
|
||||||
- SQLite
|
|
||||||
- Uses CGo if available or modernc.org if not
|
Database |Read |Editing |Connection options |Context menu actions
|
||||||
- Badger v4
|
-------------|------|---------|--------------------|--------
|
||||||
|
Badger v4 |Yes |No |Encrypted, readonly, in-memory |Backup, restore, compact
|
||||||
|
Bolt |Yes |Yes |Readonly |Create/delete child buckets
|
||||||
|
Debconf |Yes |No | |
|
||||||
|
LevelDB |Yes |No |Readonly |
|
||||||
|
Pebble |Yes |No |Readonly, in-memory |
|
||||||
|
Redis |Yes |No |SSH tunnel, RESP v3 |
|
||||||
|
SQLite |Yes |Yes |CLI driver, in-memory |Vacuum, export
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
@@ -25,29 +32,106 @@ The code in this project is licensed under the ISC license (see `LICENSE` file f
|
|||||||
|
|
||||||
This project redistributes images from the famfamfam/silk icon set under the [CC-BY 2.5 license](http://creativecommons.org/licenses/by/2.5/).
|
This project redistributes images from the famfamfam/silk icon set under the [CC-BY 2.5 license](http://creativecommons.org/licenses/by/2.5/).
|
||||||
|
|
||||||
## Usage
|
This project includes trademarked logo images for each supported database type.
|
||||||
|
|
||||||
1. `CGO_ENABLED=1 go build`
|
|
||||||
2. [Download liblcl](https://github.com/ying32/govcl/releases/download/v2.2.3/liblcl-2.2.3.zip) for your platform, or [compile it yourself](https://github.com/ying32/liblcl) (tested with v2.2.3)
|
|
||||||
3. Place the liblcl library file in the same directory as `yvbolt`
|
|
||||||
4. Run `yvbolt` and use the main menu to open a database
|
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
2025-11-23 v0.8.0
|
||||||
|
|
||||||
|
- Port from [liblcl](https://github.com/ying32/liblcl) to [MIQT Qt 6](https://github.com/mappu/miqt)
|
||||||
|
- Badger: Upgrade v4.2.0 -> v4.8.0
|
||||||
|
- Pebble: Upgrade v1.0.0 -> v1.1.5
|
||||||
|
- SQLite: Upgrade v1.14.22 -> v1.14.32
|
||||||
|
- Redis: Upgrade v9.5.3 -> v9.16.0
|
||||||
|
- Bolt: Upgrade v1.4.0-alpha.1 -> v1.4.3
|
||||||
|
- Bolt: Fix child buckets appearing in data area
|
||||||
|
- Badger, Pebble, Debconf: Remove redundant "Data" navigation layer
|
||||||
|
- Badger: Support encrypted databases
|
||||||
|
- Badger: Support readonly databases
|
||||||
|
- Badger: Add context-menu actions for backup, restore, and compact
|
||||||
|
- Pebble: Support readonly databases
|
||||||
|
- LevelDB: Add LevelDB database integration
|
||||||
|
- Redis: Support SSH tunnel
|
||||||
|
- SQLite: Allow editing the primary key column
|
||||||
|
- App: New style connection dialog
|
||||||
|
- App: Updated keyboard shortcuts (Ctrl+O to open new connection, F5 to refresh, F9 to execute query)
|
||||||
|
- App: Add confirmation when refreshing the data table if there are uncommitted changes
|
||||||
|
|
||||||
|
[⬇️ Download for Windows x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.8.0/yvbolt.win64.zip)
|
||||||
|
|
||||||
|
[⬇️ Download for Linux x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.8.0/yvbolt.linux64.tar.xz)
|
||||||
|
|
||||||
|
2024-07-18 v0.7.0
|
||||||
|
|
||||||
|
- SQLite, Bolt: Initial support for editing data (insert, per-cell update, delete)
|
||||||
|
- SQLite: Add context menu actions for compact (vacuum), export, and drop table
|
||||||
|
- App: New grid widget
|
||||||
|
- App: Add refresh button
|
||||||
|
- App: Bigger window size, use icons for toolbars, better UI colours for Windows
|
||||||
|
- App: Prevent submitting blank queries to database
|
||||||
|
- Refactor database interface and error handling
|
||||||
|
|
||||||
|
[⬇️ Download for Windows x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.7.0/yvbolt.win64.zip)
|
||||||
|
|
||||||
|
[⬇️ Download for Linux x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.7.0/yvbolt.linux64.tar.xz)
|
||||||
|
|
||||||
|
2024-06-30 v0.6.0
|
||||||
|
|
||||||
|
- Debconf: Add as supported database
|
||||||
|
- SQLite: Support table names containing special characters
|
||||||
|
- SQLite: Improvements for experimental command-line driver
|
||||||
|
- Redis: Improve connection dialog window position
|
||||||
|
- App: Cosmetic fixes for frame borders, help dialog, and Windows fonts+colours
|
||||||
|
- Build: Change compression parameters for release builds
|
||||||
|
- Build: Compile CGO with -O2 for release builds
|
||||||
|
|
||||||
|
[⬇️ Download for Windows x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.6.0/yvbolt.win64.zip)
|
||||||
|
|
||||||
|
[⬇️ Download for Linux x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.6.0/yvbolt.linux64.tar.xz)
|
||||||
|
|
||||||
|
2024-06-29 v0.5.0
|
||||||
|
|
||||||
|
- Pebble: Add as supported database
|
||||||
|
- Bolt: Support opening as readonly
|
||||||
|
- Bolt: Support creating new databases
|
||||||
|
- Bolt: Support adding/removing recursive child buckets
|
||||||
|
- SQLite: Support custom CLI driver that parses `/usr/bin/sqlite3 -json` output (experimental)
|
||||||
|
- Redis: Improve query parser to support quoted strings
|
||||||
|
- App: Support refreshing elements in nav tree
|
||||||
|
- App: Help menu option to show driver versions
|
||||||
|
- App: Add image icons for refresh and close context menu actions
|
||||||
|
- Build: Add makefile for cross-compiling release binaries
|
||||||
|
|
||||||
|
[⬇️ Download for Windows x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.5.0/yvbolt.win64.zip)
|
||||||
|
|
||||||
|
[⬇️ Download for Linux x86_64](https://git.ivysaur.me/code.ivysaur.me/yvbolt/releases/download/v0.5.0/yvbolt.linux64.tar.xz)
|
||||||
|
|
||||||
|
2024-06-23 v0.4.0
|
||||||
|
|
||||||
|
- Redis: Add as supported database
|
||||||
|
- Badger: Allow creating in-memory databases
|
||||||
|
- App: Allow selecting partial query text to execute
|
||||||
|
- App: Allow closing database connections from context menu
|
||||||
|
- App: Allow scrolling large content on Properties pane
|
||||||
|
- App: Preload recursive navigation
|
||||||
|
- App: Automatically switch to selected database when new connection is created
|
||||||
|
- App: Add help website link
|
||||||
|
- App: Add database logo images
|
||||||
|
|
||||||
2024-06-25 v0.3.0
|
2024-06-25 v0.3.0
|
||||||
|
|
||||||
- Add support for running custom queries
|
- Badger: Add BadgerDB v4 as supported database
|
||||||
- Add BadgerDB v4 as supported database
|
- SQLite: Add support for CGo-free SQLite driver under cross-compilation
|
||||||
- Add support for CGo-free SQLite driver under cross-compilation
|
- Bolt: Update Bolt to v1.4.0-alpha.1
|
||||||
- Add status bar showing currently selected DB
|
- App: Add support for running custom queries
|
||||||
- Update Bolt to v1.4.0-alpha.1
|
- App: Add status bar showing currently selected DB
|
||||||
- Fix missing icons in nav when selecting items
|
- App: Fix missing icons in nav when selecting items
|
||||||
- Fix extra quotemarks when browsing string content of database
|
- App: Fix extra quotemarks when browsing string content of database
|
||||||
|
|
||||||
2024-06-08 v0.2.0
|
2024-06-08 v0.2.0
|
||||||
|
|
||||||
- Add SQLite support (now requires CGo)
|
- SQLite: Add SQLite support (now requires CGo)
|
||||||
- Add images for menu and navigation items
|
- App: Add images for menu and navigation items
|
||||||
|
|
||||||
2024-06-03 v0.1.0
|
2024-06-03 v0.1.0
|
||||||
|
|
||||||
|
|||||||
60
TODO
@@ -1,23 +1,53 @@
|
|||||||
- Insert
|
- Syntax highlighting in editor
|
||||||
- Update cell
|
- Mutation
|
||||||
- Delete row(s)
|
- Badger: Support insert/update/delete
|
||||||
|
- Pebble: Support insert/update/delete
|
||||||
|
- Debconf: Support insert/update/delete
|
||||||
|
- Redis: Support insert/update/delete
|
||||||
- Binary data viewer
|
- Binary data viewer
|
||||||
- Detect jpg/png and show as image
|
- Detect jpg/png and show as image
|
||||||
- Warning if data table is filtered to 1000 rows, or add pagination
|
|
||||||
- More DB types
|
- More DB types
|
||||||
- MySQL
|
- MySQL
|
||||||
- Postgres
|
- Postgres
|
||||||
- Redis
|
- CLI using psql
|
||||||
- MSSQL (recursive navigation for instances)
|
- MSSQL (recursive navigation for instances)
|
||||||
- SSH tunnels
|
- Other K/V stores from https://github.com/smallnest/kvbench
|
||||||
- Special actions
|
- Windows registry
|
||||||
- Refresh tables
|
- LDAP
|
||||||
- Per-db actions e.g. compact, export backup
|
- LotusDB https://github.com/lotusdblabs/lotusdb
|
||||||
- Per-table actions e.g. drop table
|
- Bitcask https://git.mills.io/prologic/bitcask
|
||||||
- Sqlite cli driver for ssh tunnel
|
- Related: Rosedb https://github.com/rosedblabs/rosedb
|
||||||
|
- Dolt
|
||||||
|
- Memcache
|
||||||
|
- Listing all keys is not well supported, needs hacks
|
||||||
|
- DBus SecretStore
|
||||||
|
- Starskey https://github.com/starskey-io/starskey
|
||||||
|
- Chai (built on Pebble) - https://github.com/chaisql/chai
|
||||||
|
- APCu - need some sort of hook into the storage engine
|
||||||
|
- Etcd
|
||||||
|
- Connection dialog
|
||||||
|
- Saved connections w/ storage encryption
|
||||||
|
- SSH over Cockpit
|
||||||
|
- SQLite CLI driver:
|
||||||
|
- Context support
|
||||||
|
- Attach to SSH tunnel
|
||||||
|
- Configure binary path
|
||||||
- https://ricardoanderegg.com/posts/sqlite-remote-explorer-gui/
|
- https://ricardoanderegg.com/posts/sqlite-remote-explorer-gui/
|
||||||
- https://github.com/litements/litexplore
|
- https://github.com/litements/litexplore
|
||||||
- Badger encryption key dialog
|
- Badger:
|
||||||
- Badger in-memory
|
- v1/v2/v3 support
|
||||||
- Makefile to cross-compile release binaries in docker
|
- option to use namespace separators for virtual buckets
|
||||||
- Win32 icon resource
|
- Debconf: separate groups by first slash in name
|
||||||
|
- SQLite: drop table doesn't autorefresh nav since callback is late
|
||||||
|
- Build
|
||||||
|
- Win32 icon resource
|
||||||
|
- Performance
|
||||||
|
- Warning if data table is filtered to 1000 rows, or add pagination
|
||||||
|
- Context/interrupt slow queries
|
||||||
|
- Faster virtual rendering
|
||||||
|
- Query history
|
||||||
|
- Test suite
|
||||||
|
- `CREATE TABLE foo (id integer primary key, aaa text not null, bbb text not null);`
|
||||||
|
- Ability to convert database types
|
||||||
|
- Export all data from grid
|
||||||
|
- Export all data from all buckets within a DB
|
||||||
BIN
assets/add.png
Normal file
|
After Width: | Height: | Size: 733 B |
BIN
assets/arrow_refresh.png
Normal file
|
After Width: | Height: | Size: 685 B |
BIN
assets/delete.png
Normal file
|
After Width: | Height: | Size: 715 B |
BIN
assets/lightning_go.png
Normal file
|
After Width: | Height: | Size: 739 B |
BIN
assets/pencil.png
Normal file
|
After Width: | Height: | Size: 444 B |
BIN
assets/pencil_add.png
Normal file
|
After Width: | Height: | Size: 589 B |
BIN
assets/pencil_delete.png
Normal file
|
After Width: | Height: | Size: 603 B |
BIN
assets/pencil_go.png
Normal file
|
After Width: | Height: | Size: 666 B |
BIN
assets/resultset_next.png
Normal file
|
After Width: | Height: | Size: 395 B |
BIN
assets/vendor_cockroach.png
Normal file
|
After Width: | Height: | Size: 752 B |
BIN
assets/vendor_debian.png
Normal file
|
After Width: | Height: | Size: 831 B |
BIN
assets/vendor_dgraph.png
Normal file
|
After Width: | Height: | Size: 948 B |
BIN
assets/vendor_github.png
Normal file
|
After Width: | Height: | Size: 704 B |
BIN
assets/vendor_leveldb.png
Normal file
|
After Width: | Height: | Size: 597 B |
BIN
assets/vendor_mysql.png
Normal file
|
After Width: | Height: | Size: 824 B |
BIN
assets/vendor_redis.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
assets/vendor_sqlite.png
Normal file
|
After Width: | Height: | Size: 919 B |
143
badger.go
@@ -1,143 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/dgraph-io/badger/v4"
|
|
||||||
"github.com/ying32/govcl/vcl"
|
|
||||||
"github.com/ying32/govcl/vcl/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type badgerLoadedDatabase struct {
|
|
||||||
displayName string
|
|
||||||
path string
|
|
||||||
db *badger.DB
|
|
||||||
nav *vcl.TTreeNode
|
|
||||||
|
|
||||||
arena []*navData // keepalive
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) DisplayName() string {
|
|
||||||
return ld.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) DriverName() string {
|
|
||||||
return "Badger v4"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) RootElement() *vcl.TTreeNode {
|
|
||||||
return ld.nav
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) Keepalive(ndata *navData) {
|
|
||||||
ld.arena = append(ld.arena, ndata)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
|
||||||
|
|
||||||
// Load properties
|
|
||||||
|
|
||||||
content := fmt.Sprintf("Table statistics: %#v", ld.db.Tables())
|
|
||||||
f.propertiesBox.SetText(content)
|
|
||||||
|
|
||||||
// Load data
|
|
||||||
|
|
||||||
f.contentBox.SetEnabled(false)
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
// Badger always uses Key + Value as the columns
|
|
||||||
|
|
||||||
f.contentBox.Columns().Clear()
|
|
||||||
colKey := f.contentBox.Columns().Add()
|
|
||||||
colKey.SetCaption("Key")
|
|
||||||
colKey.SetWidth(MY_WIDTH)
|
|
||||||
colKey.SetAlignment(types.TaLeftJustify)
|
|
||||||
colVal := f.contentBox.Columns().Add()
|
|
||||||
colVal.SetCaption("Value")
|
|
||||||
|
|
||||||
err := ld.db.View(func(txn *badger.Txn) error {
|
|
||||||
|
|
||||||
// Valid
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
// Create iterator
|
|
||||||
opts := badger.DefaultIteratorOptions
|
|
||||||
opts.PrefetchSize = 64
|
|
||||||
it := txn.NewIterator(opts)
|
|
||||||
defer it.Close()
|
|
||||||
|
|
||||||
for it.Rewind(); it.Valid(); it.Next() {
|
|
||||||
item := it.Item()
|
|
||||||
k := item.Key()
|
|
||||||
err := item.Value(func(v []byte) error {
|
|
||||||
dataEntry := f.contentBox.Items().Add()
|
|
||||||
dataEntry.SetCaption(formatUtf8(k))
|
|
||||||
dataEntry.SubItems().Add(formatUtf8(v))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to load data: %s", err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valid
|
|
||||||
f.contentBox.SetEnabled(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
|
||||||
// In the Badger implementation, there is only one child: "Data"
|
|
||||||
if len(ndata.bucketPath) == 0 {
|
|
||||||
return []string{"Data"}, nil
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// No children deeper than that
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
|
||||||
vcl.ShowMessage("Badger doesn't support querying")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ loadedDatabase = &badgerLoadedDatabase{} // interface assertion
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
func (f *TMainForm) badgerAddDatabaseFromDirectory(path string) {
|
|
||||||
// TODO load in background thread to stop blocking the UI
|
|
||||||
db, err := badger.Open(badger.DefaultOptions(path))
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to load database '%s': %s", path, err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ld := &badgerLoadedDatabase{
|
|
||||||
path: path,
|
|
||||||
displayName: filepath.Base(path),
|
|
||||||
db: db,
|
|
||||||
}
|
|
||||||
|
|
||||||
ld.nav = f.Buckets.Items().Add(nil, ld.displayName)
|
|
||||||
ld.nav.SetHasChildren(true) // dynamically populate in OnNavExpanding
|
|
||||||
ld.nav.SetImageIndex(imgDatabase)
|
|
||||||
ld.nav.SetSelectedIndex(imgDatabase)
|
|
||||||
navData := &navData{
|
|
||||||
ld: ld,
|
|
||||||
childrenLoaded: false, // will be loaded dynamically
|
|
||||||
bucketPath: []string{}, // empty = root
|
|
||||||
}
|
|
||||||
ld.nav.SetData(unsafe.Pointer(navData))
|
|
||||||
|
|
||||||
f.dbs = append(f.dbs, ld)
|
|
||||||
|
|
||||||
ld.Keepalive(navData)
|
|
||||||
}
|
|
||||||
200
bolt.go
@@ -1,200 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/ying32/govcl/vcl"
|
|
||||||
"github.com/ying32/govcl/vcl/types"
|
|
||||||
"go.etcd.io/bbolt"
|
|
||||||
"go.etcd.io/bbolt/version"
|
|
||||||
)
|
|
||||||
|
|
||||||
type boltLoadedDatabase struct {
|
|
||||||
displayName string
|
|
||||||
path string
|
|
||||||
db *bbolt.DB
|
|
||||||
nav *vcl.TTreeNode
|
|
||||||
|
|
||||||
arena []*navData // keepalive
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) DisplayName() string {
|
|
||||||
return ld.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) DriverName() string {
|
|
||||||
return "Bolt " + version.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) RootElement() *vcl.TTreeNode {
|
|
||||||
return ld.nav
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) Keepalive(ndata *navData) {
|
|
||||||
ld.arena = append(ld.arena, ndata)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
|
||||||
|
|
||||||
// Load properties
|
|
||||||
|
|
||||||
bucketDisplayName := strings.Join(ndata.bucketPath, `/`)
|
|
||||||
content := fmt.Sprintf("Selected database: %#v\n\n\nSelected bucket: %q\n", ld.db.Stats(), bucketDisplayName)
|
|
||||||
f.propertiesBox.SetText(content)
|
|
||||||
|
|
||||||
// Load data
|
|
||||||
|
|
||||||
f.contentBox.SetEnabled(false)
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
// Bolt always uses Key + Value as the columns
|
|
||||||
|
|
||||||
f.contentBox.Columns().Clear()
|
|
||||||
colKey := f.contentBox.Columns().Add()
|
|
||||||
colKey.SetCaption("Key")
|
|
||||||
colKey.SetWidth(MY_WIDTH)
|
|
||||||
colKey.SetAlignment(types.TaLeftJustify)
|
|
||||||
colVal := f.contentBox.Columns().Add()
|
|
||||||
colVal.SetCaption("Value")
|
|
||||||
|
|
||||||
err := ld.db.View(func(tx *bbolt.Tx) error {
|
|
||||||
b := boltTargetBucket(tx, ndata.bucketPath)
|
|
||||||
if b == nil {
|
|
||||||
// no such bucket
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valid
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
c := b.Cursor()
|
|
||||||
for k, v := c.First(); k != nil; k, v = c.Next() {
|
|
||||||
dataEntry := f.contentBox.Items().Add()
|
|
||||||
dataEntry.SetCaption(formatUtf8(k))
|
|
||||||
dataEntry.SubItems().Add(formatUtf8(v))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to load data for bucket %q: %s", bucketDisplayName, err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valid
|
|
||||||
f.contentBox.SetEnabled(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
|
||||||
// In the bolt implementation, the nav is a recursive tree of child buckets
|
|
||||||
return boltChildBucketNames(ld.db, ndata.bucketPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
|
||||||
vcl.ShowMessage("Bolt doesn't support querying")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ loadedDatabase = &boltLoadedDatabase{} // interface assertion
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
func (f *TMainForm) boltAddDatabaseFromFile(path string) {
|
|
||||||
// TODO load in background thread to stop blocking the UI
|
|
||||||
db, err := bbolt.Open(path, 0644, &bbolt.Options{Timeout: 1 * time.Second})
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to load database '%s': %s", path, err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ld := &boltLoadedDatabase{
|
|
||||||
path: path,
|
|
||||||
displayName: filepath.Base(path),
|
|
||||||
db: db,
|
|
||||||
}
|
|
||||||
|
|
||||||
ld.nav = f.Buckets.Items().Add(nil, ld.displayName)
|
|
||||||
ld.nav.SetHasChildren(true) // dynamically populate in OnNavExpanding
|
|
||||||
ld.nav.SetImageIndex(imgDatabase)
|
|
||||||
ld.nav.SetSelectedIndex(imgDatabase)
|
|
||||||
navData := &navData{
|
|
||||||
ld: ld,
|
|
||||||
childrenLoaded: false, // will be loaded dynamically
|
|
||||||
bucketPath: []string{}, // empty = root
|
|
||||||
}
|
|
||||||
ld.nav.SetData(unsafe.Pointer(navData))
|
|
||||||
|
|
||||||
f.dbs = append(f.dbs, ld)
|
|
||||||
|
|
||||||
ld.Keepalive(navData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func boltTargetBucket(tx *bbolt.Tx, path []string) *bbolt.Bucket {
|
|
||||||
|
|
||||||
// If we are already deep in buckets, go directly there to find children
|
|
||||||
if len(path) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
b := tx.Bucket([]byte(path[0]))
|
|
||||||
if b == nil {
|
|
||||||
return nil // unexpectedly missing
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 1; i < len(path); i += 1 {
|
|
||||||
b = b.Bucket([]byte(path[i]))
|
|
||||||
if b == nil {
|
|
||||||
return nil // unexpectedly missing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return b // OK
|
|
||||||
}
|
|
||||||
|
|
||||||
func boltChildBucketNames(db *bbolt.DB, path []string) ([]string, error) {
|
|
||||||
var nextBucketNames []string
|
|
||||||
|
|
||||||
err := db.View(func(tx *bbolt.Tx) error {
|
|
||||||
|
|
||||||
// If we are already deep in buckets, go directly there to find children
|
|
||||||
if len(path) > 0 {
|
|
||||||
b := tx.Bucket([]byte(path[0]))
|
|
||||||
if b == nil {
|
|
||||||
return fmt.Errorf("Unexpected missing root bucket %q", path[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 1; i < len(path); i += 1 {
|
|
||||||
b = b.Bucket([]byte(path[i]))
|
|
||||||
if b == nil {
|
|
||||||
return fmt.Errorf("Unexpected missing bucket %q", strings.Join(path[0:i], `/`))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find child buckets of this bucket
|
|
||||||
b.ForEachBucket(func(bucketName []byte) error {
|
|
||||||
nextBucketNames = append(nextBucketNames, string(bucketName))
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Find root bucket names
|
|
||||||
return tx.ForEach(func(bucketName []byte, _ *bbolt.Bucket) error {
|
|
||||||
nextBucketNames = append(nextBucketNames, string(bucketName))
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(nextBucketNames)
|
|
||||||
|
|
||||||
return nextBucketNames, nil
|
|
||||||
}
|
|
||||||
94
config.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DBConnector interface {
|
||||||
|
Connect(context.Context) (loadedDatabase, string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type registeredDatabase struct {
|
||||||
|
label string
|
||||||
|
iconPath string
|
||||||
|
conn DBConnector
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
registeredDatabases []registeredDatabase
|
||||||
|
)
|
||||||
|
|
||||||
|
func registerDatabase(conn DBConnector, label, iconPath string) {
|
||||||
|
registeredDatabases = append(registeredDatabases, registeredDatabase{
|
||||||
|
label: label,
|
||||||
|
iconPath: iconPath,
|
||||||
|
conn: conn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnMnuConnectClick() {
|
||||||
|
dlg := NewConnectDialogUi()
|
||||||
|
dlg.ConnectDialog.SetParent2(f.ui.MainWindow.QWidget, qt.Dialog)
|
||||||
|
dlg.ConnectDialog.SetModal(true)
|
||||||
|
dlg.ConnectDialog.SetAttribute(qt.WA_DeleteOnClose)
|
||||||
|
|
||||||
|
var resultingConfigs []DBConnector
|
||||||
|
var getters []func()
|
||||||
|
|
||||||
|
for _, db := range registeredDatabases {
|
||||||
|
dlg.databaseEngine.AddItem2(qt.NewQIcon4(db.iconPath), db.label)
|
||||||
|
|
||||||
|
frame := qt.NewQWidget2()
|
||||||
|
layout := qt.NewQFormLayout(frame)
|
||||||
|
|
||||||
|
// Deep-copy the provided default object
|
||||||
|
// useConn := deep_copy(db.conn)
|
||||||
|
useConn := db.conn // FIXME can't deep copy?!
|
||||||
|
|
||||||
|
resultingConfigs = append(resultingConfigs, useConn)
|
||||||
|
getters = append(getters, autoconfig.MakeConfigArea(useConn, layout))
|
||||||
|
|
||||||
|
dlg.stackedWidget.AddWidget(frame)
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg.databaseEngine.OnCurrentIndexChanged(func(index int) {
|
||||||
|
dlg.stackedWidget.SetCurrentIndex(index)
|
||||||
|
})
|
||||||
|
|
||||||
|
dlg.ConnectDialog.OnAccept(func(super func()) {
|
||||||
|
// Validate connection before closing
|
||||||
|
|
||||||
|
dlg.buttonBox.SetEnabled(false)
|
||||||
|
defer dlg.buttonBox.SetEnabled(true)
|
||||||
|
dlg.buttonBox.Repaint()
|
||||||
|
|
||||||
|
// Selected index
|
||||||
|
idx := dlg.databaseEngine.CurrentIndex()
|
||||||
|
|
||||||
|
// Save changes from UI into struct
|
||||||
|
getters[idx]()
|
||||||
|
config := resultingConfigs[idx]
|
||||||
|
|
||||||
|
// Connect -> get ld
|
||||||
|
ctx := context.Background() // TODO do in background thread?
|
||||||
|
ld, displayName, err := config.Connect(ctx)
|
||||||
|
if err != nil {
|
||||||
|
_ = qt.QMessageBox_Critical(dlg.ConnectDialog.QWidget, APPNAME, fmt.Sprintf("Connecting to %s database: %s", registeredDatabases[idx].label, err.Error()))
|
||||||
|
// Prevent the dialog from closing: do not call super()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add ld to mainwindow
|
||||||
|
f.addTopLevelDatabaseConnection(ld, displayName)
|
||||||
|
|
||||||
|
// Default accept behaviour is: setResult(Accepted), emits onFinished; && Hide()
|
||||||
|
super()
|
||||||
|
})
|
||||||
|
|
||||||
|
dlg.ConnectDialog.Open() // Modal, unlike .Show()
|
||||||
|
|
||||||
|
}
|
||||||
69
connectionDialog.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
// Generated by miqt-uic. To update this file, edit the .ui file in
|
||||||
|
// Qt Designer, and then run 'go generate'.
|
||||||
|
//
|
||||||
|
//go:generate miqt-uic -InFile connectionDialog.ui -OutFile connectionDialog.go -Qt6
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConnectDialogUi struct {
|
||||||
|
ConnectDialog *qt.QDialog
|
||||||
|
gridLayout *qt.QGridLayout
|
||||||
|
databaseEngine *qt.QComboBox
|
||||||
|
stackedWidget *qt.QStackedWidget
|
||||||
|
buttonBox *qt.QDialogButtonBox
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewConnectDialogUi creates all Qt widget classes for ConnectDialog.
|
||||||
|
func NewConnectDialogUi() *ConnectDialogUi {
|
||||||
|
ui := &ConnectDialogUi{}
|
||||||
|
ui.ConnectDialog = qt.NewQDialog(nil)
|
||||||
|
ConnectDialog__objectName := qt.NewQAnyStringView3("ConnectDialog")
|
||||||
|
ui.ConnectDialog.SetObjectName(*ConnectDialog__objectName)
|
||||||
|
ConnectDialog__objectName.Delete() // setter copied value
|
||||||
|
ui.ConnectDialog.Resize(385, 364)
|
||||||
|
icon0 := qt.NewQIcon()
|
||||||
|
icon0.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.ConnectDialog.SetWindowIcon(icon0)
|
||||||
|
ui.gridLayout = qt.NewQGridLayout(ui.ConnectDialog.QWidget)
|
||||||
|
gridLayout__objectName := qt.NewQAnyStringView3("gridLayout")
|
||||||
|
ui.gridLayout.SetObjectName(*gridLayout__objectName)
|
||||||
|
gridLayout__objectName.Delete() // setter copied value
|
||||||
|
ui.gridLayout.SetContentsMargins(11, 11, 11, 11)
|
||||||
|
ui.gridLayout.SetSpacing(6)
|
||||||
|
ui.databaseEngine = qt.NewQComboBox(ui.ConnectDialog.QWidget)
|
||||||
|
databaseEngine__objectName := qt.NewQAnyStringView3("databaseEngine")
|
||||||
|
ui.databaseEngine.SetObjectName(*databaseEngine__objectName)
|
||||||
|
databaseEngine__objectName.Delete() // setter copied value
|
||||||
|
|
||||||
|
ui.gridLayout.AddWidget2(ui.databaseEngine.QWidget, 0, 1)
|
||||||
|
ui.stackedWidget = qt.NewQStackedWidget(ui.ConnectDialog.QWidget)
|
||||||
|
stackedWidget__objectName := qt.NewQAnyStringView3("stackedWidget")
|
||||||
|
ui.stackedWidget.SetObjectName(*stackedWidget__objectName)
|
||||||
|
stackedWidget__objectName.Delete() // setter copied value
|
||||||
|
|
||||||
|
ui.gridLayout.AddWidget2(ui.stackedWidget.QWidget, 1, 1)
|
||||||
|
ui.buttonBox = qt.NewQDialogButtonBox(ui.ConnectDialog.QWidget)
|
||||||
|
buttonBox__objectName := qt.NewQAnyStringView3("buttonBox")
|
||||||
|
ui.buttonBox.SetObjectName(*buttonBox__objectName)
|
||||||
|
buttonBox__objectName.Delete() // setter copied value
|
||||||
|
ui.buttonBox.SetOrientation(qt.Horizontal)
|
||||||
|
ui.buttonBox.SetStandardButtons(qt.QDialogButtonBox__Cancel | qt.QDialogButtonBox__Ok)
|
||||||
|
|
||||||
|
ui.gridLayout.AddWidget3(ui.buttonBox.QWidget, 2, 0, 1, 2)
|
||||||
|
|
||||||
|
ui.buttonBox.OnAccepted(ui.ConnectDialog.Accept)
|
||||||
|
ui.buttonBox.OnRejected(ui.ConnectDialog.Reject)
|
||||||
|
|
||||||
|
ui.Retranslate()
|
||||||
|
|
||||||
|
return ui
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retranslate reapplies all text translations.
|
||||||
|
func (ui *ConnectDialogUi) Retranslate() {
|
||||||
|
ui.ConnectDialog.SetWindowTitle(qt.QCoreApplication_Tr("Connect..."))
|
||||||
|
}
|
||||||
76
connectionDialog.ui
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ConnectDialog</class>
|
||||||
|
<widget class="QDialog" name="ConnectDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>385</width>
|
||||||
|
<height>364</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Connect...</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="databaseEngine"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QStackedWidget" name="stackedWidget"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="embed.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ConnectDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ConnectDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
196
db_badger.go
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/dgraph-io/badger/v4"
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type badgerLoadedDatabase struct {
|
||||||
|
db *badger.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) DriverName() string {
|
||||||
|
return "BadgerDB v4"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
// Load properties
|
||||||
|
|
||||||
|
content := fmt.Sprintf("Table statistics: %#v", ld.db.Tables())
|
||||||
|
f.propertiesBox.SetText(content)
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
// Badger always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(2)
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels([]string{"Key", "Value"})
|
||||||
|
|
||||||
|
f.contentBox.SetRowCount(0)
|
||||||
|
|
||||||
|
err := ld.db.View(func(txn *badger.Txn) error {
|
||||||
|
|
||||||
|
// Create iterator
|
||||||
|
opts := badger.DefaultIteratorOptions
|
||||||
|
opts.PrefetchSize = 64
|
||||||
|
it := txn.NewIterator(opts)
|
||||||
|
defer it.Close()
|
||||||
|
|
||||||
|
for it.Rewind(); it.Valid(); it.Next() {
|
||||||
|
item := it.Item()
|
||||||
|
k := item.Key()
|
||||||
|
err := item.Value(func(v []byte) error {
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8(k)))
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8(v)))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil // No children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return []contextAction{
|
||||||
|
{Name: "Export backup...", Callback: ld.ExportBackup},
|
||||||
|
{Name: "Import backup...", Callback: ld.ImportBackup},
|
||||||
|
{Name: "Compact", Callback: ld.CompactGC},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) ExportBackup(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
saveAs := qt.QFileDialog_GetSaveFileName4(sender.TreeWidget().QWidget, "Export backup...", "", "Badger database backups (*.bak);;All files (*.*)")
|
||||||
|
if saveAs == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fh, err := os.OpenFile(saveAs, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
|
||||||
|
_, err = ld.db.Backup(fh, 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) ImportBackup(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
openPath := qt.QFileDialog_GetOpenFileName4(sender.TreeWidget().QWidget, "Import backup...", "", "Badger database backups (*.bak);;All files (*.*)")
|
||||||
|
if openPath == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fh, err := os.Open(openPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
|
||||||
|
return ld.db.Load(fh, 16) // concurrency - just a guess
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) CompactGC(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
// Move data from value log into levels ->
|
||||||
|
err := ld.db.RunValueLogGC(0.0001) // Compact if we would save 0.1% of disk space
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("RunValueLogGC: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -> then flatten all levels
|
||||||
|
err = ld.db.Flatten(4)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Flatten: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *badgerLoadedDatabase) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &badgerLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type badgerMemConnection struct{}
|
||||||
|
|
||||||
|
func (bmc *badgerMemConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &badgerLoadedDatabase{db: db}, `:memory:`, nil // SQLite-style naming
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type badgerDirConnection struct {
|
||||||
|
Directory autoconfig.ExistingDirectory
|
||||||
|
Readonly bool
|
||||||
|
Encryption_Method autoconfig.EnumList `yenum:"None;;Hex (AES-128/192/256);;Passphrase (SHA256 KDF to AES-256)"`
|
||||||
|
Encryption_Key autoconfig.Password
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bdc *badgerDirConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
opts := badger.DefaultOptions(string(bdc.Directory))
|
||||||
|
opts.ReadOnly = bdc.Readonly
|
||||||
|
opts.MetricsEnabled = false
|
||||||
|
|
||||||
|
switch bdc.Encryption_Method {
|
||||||
|
case 0: // None
|
||||||
|
case 1: // Hex (AES-128/192/256) - must be 16/24/32 bytes
|
||||||
|
ehx, err := hex.DecodeString(string(bdc.Encryption_Key))
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(len(ehx) == 16 || len(ehx) == 24 || len(ehx) == 32) {
|
||||||
|
return nil, "", fmt.Errorf("Hex encryption key must be 16/24/32 bytes long, got %d", len(ehx))
|
||||||
|
}
|
||||||
|
opts.EncryptionKey = ehx
|
||||||
|
|
||||||
|
case 2: // Passphrase (SHA256 KDF to AES-256)
|
||||||
|
hasher := sha256.New()
|
||||||
|
hasher.Write([]byte(bdc.Encryption_Key))
|
||||||
|
opts.EncryptionKey = hasher.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := badger.Open(opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &badgerLoadedDatabase{db: db}, filepath.Base(string(bdc.Directory)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&badgerMemConnection{}, "BadgerDB v4 (Memory)", `:/assets/vendor_dgraph.png`)
|
||||||
|
registerDatabase(&badgerDirConnection{}, "BadgerDB v4", `:/assets/vendor_dgraph.png`)
|
||||||
|
}
|
||||||
295
db_bolt.go
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
"go.etcd.io/bbolt"
|
||||||
|
"go.etcd.io/bbolt/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
type boltLoadedDatabase struct {
|
||||||
|
path string
|
||||||
|
db *bbolt.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
type boltConfig struct {
|
||||||
|
Path autoconfig.ExistingFile `yfilter:"Bolt database (*.db);;All files (*.*)"`
|
||||||
|
Readonly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc *boltConfig) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
|
||||||
|
opts := bbolt.Options{
|
||||||
|
Timeout: 1 * time.Second,
|
||||||
|
ReadOnly: bc.Readonly,
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := bbolt.Open(string(bc.Path), 0644, &opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("Failed to load database '%s': %w", bc.Path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
displayName := filepath.Base(string(bc.Path))
|
||||||
|
if bc.Readonly {
|
||||||
|
displayName += " (read-only)"
|
||||||
|
}
|
||||||
|
|
||||||
|
ld := &boltLoadedDatabase{
|
||||||
|
path: string(bc.Path),
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
|
||||||
|
return ld, displayName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&boltConfig{}, "Bolt", ":/assets/vendor_github.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) DriverName() string {
|
||||||
|
return "Bolt " + version.Version
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
// Load properties
|
||||||
|
|
||||||
|
content := fmt.Sprintf("Selected database: %#v", ld.db.Stats())
|
||||||
|
f.propertiesBox.SetText(content)
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
return nil // Can't have data outside of the top bucket
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
// Bolt always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(2)
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels([]string{"Key", "Value"})
|
||||||
|
|
||||||
|
f.contentBox.SetRowCount(0)
|
||||||
|
|
||||||
|
err := ld.db.View(func(tx *bbolt.Tx) error {
|
||||||
|
b := boltTargetBucket(tx, bucketPath)
|
||||||
|
if b == nil {
|
||||||
|
// no such bucket
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
c := b.Cursor()
|
||||||
|
for k, v := c.First(); k != nil; k, v = c.Next() {
|
||||||
|
|
||||||
|
// Nil values mean it's a bucket
|
||||||
|
// Hide from the data table, it will be shown in the nav instead
|
||||||
|
if v == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8(k)))
|
||||||
|
f.contentBox.SetItem(rpos, 1, qt.NewQTableWidgetItem2(formatUtf8(v)))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *boltLoadedDatabase) ApplyChanges(f *App, bucketPath []string) error {
|
||||||
|
if n.db.IsReadOnly() {
|
||||||
|
return errors.New("Database was opened read-only")
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have rendered row IDs, need to convert back to a bolt primary key
|
||||||
|
// TODO stash the real key inside f.contentBox.Objects()
|
||||||
|
// FIXME breaks if you try and edit the primary key(!)
|
||||||
|
primaryKeyForRendered := func(rowid int) []byte {
|
||||||
|
return []byte(f.ui.contentBox.Item(rowid, 0).Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
return n.db.Update(func(tx *bbolt.Tx) error {
|
||||||
|
|
||||||
|
// Get current bucket handle
|
||||||
|
b := boltTargetBucket(tx, bucketPath)
|
||||||
|
|
||||||
|
// Edit
|
||||||
|
for rowid, _ /*editcells*/ := range f.updateRows {
|
||||||
|
k := primaryKeyForRendered(rowid)
|
||||||
|
v := f.ui.contentBox.Item(rowid, 1).Text() // There's only one value cell
|
||||||
|
err := b.Put(k, []byte(v))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Updating cell %q: %w", formatUtf8(k), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete by key (affects rowids after re-render)
|
||||||
|
for rowid, _ := range f.deleteRows {
|
||||||
|
k := primaryKeyForRendered(rowid)
|
||||||
|
err := b.Delete(k)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Deleting cell %q: %w", formatUtf8(k), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert all new entries
|
||||||
|
for rowid, _ := range f.insertRows {
|
||||||
|
k := primaryKeyForRendered(rowid)
|
||||||
|
v := f.ui.contentBox.Item(rowid, 1).Text() // There's only one value cell
|
||||||
|
err := b.Put(k, []byte(v))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Inserting cell %q: %w", formatUtf8(k), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
// In the bolt implementation, the nav is a recursive tree of child buckets
|
||||||
|
return boltChildBucketNames(ld.db, bucketPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) NavContext(bucketPath []string) (ret []contextAction, err error) {
|
||||||
|
ret = append(ret, contextAction{"Add bucket...", ld.AddChildBucket})
|
||||||
|
|
||||||
|
if len(bucketPath) > 0 {
|
||||||
|
ret = append(ret, contextAction{"Delete bucket", ld.DeleteBucket})
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) AddChildBucket(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
bucketName := qt.QInputDialog_GetText(sender.TreeWidget().QWidget, APPNAME, "Enter a name for the new bucket:")
|
||||||
|
if bucketName == "" {
|
||||||
|
return nil // cancel
|
||||||
|
}
|
||||||
|
|
||||||
|
err := ld.db.Update(func(tx *bbolt.Tx) error {
|
||||||
|
parent := boltTargetBucket(tx, bucketPath)
|
||||||
|
if parent != nil {
|
||||||
|
_, err := parent.CreateBucket([]byte(bucketName))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top-level
|
||||||
|
_, err := tx.CreateBucket([]byte(bucketName))
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error adding bucket: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) DeleteBucket(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
err := ld.db.Update(func(tx *bbolt.Tx) error {
|
||||||
|
// Find parent of this bucket.
|
||||||
|
if len(bucketPath) >= 2 {
|
||||||
|
// child bucket
|
||||||
|
parent := boltTargetBucket(tx, bucketPath[0:len(bucketPath)-1])
|
||||||
|
return parent.DeleteBucket([]byte(bucketPath[len(bucketPath)-1]))
|
||||||
|
} else {
|
||||||
|
// top-level bucket
|
||||||
|
return tx.DeleteBucket([]byte(bucketPath[0]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error deleting bucket %q: %w", strings.Join(bucketPath, `/`), err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *boltLoadedDatabase) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &boltLoadedDatabase{} // interface assertion
|
||||||
|
var _ editableLoadedDatabase = &boltLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
func boltTargetBucket(tx *bbolt.Tx, path []string) *bbolt.Bucket {
|
||||||
|
|
||||||
|
// If we are already deep in buckets, go directly there to find children
|
||||||
|
if len(path) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
b := tx.Bucket([]byte(path[0]))
|
||||||
|
if b == nil {
|
||||||
|
return nil // unexpectedly missing
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i < len(path); i += 1 {
|
||||||
|
b = b.Bucket([]byte(path[i]))
|
||||||
|
if b == nil {
|
||||||
|
return nil // unexpectedly missing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return b // OK
|
||||||
|
}
|
||||||
|
|
||||||
|
func boltChildBucketNames(db *bbolt.DB, path []string) ([]string, error) {
|
||||||
|
var nextBucketNames []string
|
||||||
|
|
||||||
|
err := db.View(func(tx *bbolt.Tx) error {
|
||||||
|
|
||||||
|
// If we are already deep in buckets, go directly there to find children
|
||||||
|
if len(path) > 0 {
|
||||||
|
b := tx.Bucket([]byte(path[0]))
|
||||||
|
if b == nil {
|
||||||
|
return fmt.Errorf("Root bucket %q: %w", path[0], ErrNavNotExist)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i < len(path); i += 1 {
|
||||||
|
b = b.Bucket([]byte(path[i]))
|
||||||
|
if b == nil {
|
||||||
|
return fmt.Errorf("Bucket %q: %w", strings.Join(path[0:i], `/`), ErrNavNotExist)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find child buckets of this bucket
|
||||||
|
b.ForEachBucket(func(bucketName []byte) error {
|
||||||
|
nextBucketNames = append(nextBucketNames, string(bucketName))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Find root bucket names
|
||||||
|
return tx.ForEach(func(bucketName []byte, _ *bbolt.Bucket) error {
|
||||||
|
nextBucketNames = append(nextBucketNames, string(bucketName))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// OK
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(nextBucketNames)
|
||||||
|
|
||||||
|
return nextBucketNames, nil
|
||||||
|
}
|
||||||
98
db_debconf.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"yvbolt/debconf"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type debconfLoadedDatabase struct {
|
||||||
|
db *debconf.Database
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *debconfLoadedDatabase) DriverName() string {
|
||||||
|
return "debconf"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *debconfLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
// Load properties
|
||||||
|
|
||||||
|
content := fmt.Sprintf("Entries: %d\nUnique attributes: %d\n", len(ld.db.Entries), len(ld.db.AllColumnNames))
|
||||||
|
f.propertiesBox.SetText(content)
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
|
||||||
|
indexes := make(map[string]int)
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(len(ld.db.AllColumnNames))
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels(ld.db.AllColumnNames)
|
||||||
|
|
||||||
|
for i, cname := range ld.db.AllColumnNames {
|
||||||
|
indexes[cname] = i
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range ld.db.Entries {
|
||||||
|
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(entry.Name))
|
||||||
|
|
||||||
|
for _, proppair := range entry.Properties {
|
||||||
|
f.contentBox.SetItem(rpos, indexes[proppair[0]], qt.NewQTableWidgetItem2(proppair[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *debconfLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil // No children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *debconfLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return nil, nil // No special actions are supported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *debconfLoadedDatabase) Close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &debconfLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type debconfConnection struct {
|
||||||
|
Database autoconfig.ExistingFile `yfilter:"Debconf database (*.dat);;All files (*.*)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *debconfConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
fh, err := os.OpenFile(string(dc.Database), os.O_RDONLY, 0400)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
|
||||||
|
db, err := debconf.Parse(fh)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &debconfLoadedDatabase{db: db}, filepath.Base(string(dc.Database)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&debconfConnection{
|
||||||
|
Database: "/var/cache/debconf/config.dat", // Prefill default path
|
||||||
|
}, "Debconf", `:/assets/vendor_debian.png`)
|
||||||
|
}
|
||||||
94
db_leveldb.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type leveldbLoadedDatabase struct {
|
||||||
|
db *leveldb.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *leveldbLoadedDatabase) DriverName() string {
|
||||||
|
return "LevelDB"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *leveldbLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
// Load properties
|
||||||
|
|
||||||
|
var s leveldb.DBStats
|
||||||
|
err := ld.db.Stats(&s)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Stats: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
content := fmt.Sprintf("LevelDB stats: %#v", s)
|
||||||
|
f.propertiesBox.SetText(content)
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
// leveldb always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(2)
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels([]string{"Key", "Value"})
|
||||||
|
|
||||||
|
itn := ld.db.NewIterator(nil, nil)
|
||||||
|
defer itn.Release()
|
||||||
|
|
||||||
|
for itn.Next() {
|
||||||
|
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(string(itn.Key())))
|
||||||
|
f.contentBox.SetItem(rpos, 1, qt.NewQTableWidgetItem2(string(itn.Value())))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *leveldbLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil // No children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *leveldbLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return nil, nil // No special actions are supported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *leveldbLoadedDatabase) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &leveldbLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type leveldbDirConnection struct {
|
||||||
|
Directory autoconfig.ExistingDirectory
|
||||||
|
Readonly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pdc *leveldbDirConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
var o opt.Options
|
||||||
|
o.ReadOnly = pdc.Readonly
|
||||||
|
|
||||||
|
db, err := leveldb.OpenFile(string(pdc.Directory), &o)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &leveldbLoadedDatabase{db: db}, filepath.Base(string(pdc.Directory)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&leveldbDirConnection{}, "LevelDB", `:/assets/vendor_leveldb.png`)
|
||||||
|
}
|
||||||
22
db_none.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type noLoadedDatabase struct{}
|
||||||
|
|
||||||
|
func (n *noLoadedDatabase) DriverName() string {
|
||||||
|
return "No database selected"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
f.propertiesBox.SetText("Open a database to get started...")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *noLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return nil, nil // No special actions are supported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noLoadedDatabase) Close() {}
|
||||||
138
db_pebble.go
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime/debug"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/cockroachdb/pebble"
|
||||||
|
"github.com/cockroachdb/pebble/vfs"
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type pebbleLoadedDatabase struct {
|
||||||
|
db *pebble.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
version_Pebble_once sync.Once
|
||||||
|
version_Pebble string
|
||||||
|
)
|
||||||
|
|
||||||
|
func pebbleDriverVersion() string {
|
||||||
|
version_Pebble_once.Do(func() {
|
||||||
|
// ReadBuildInfo still works even with `-ldflags '-s -w'`.
|
||||||
|
mm, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
panic("Missing build info")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dep := range mm.Deps {
|
||||||
|
switch dep.Path {
|
||||||
|
case "github.com/cockroachdb/pebble":
|
||||||
|
version_Pebble = dep.Version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return version_Pebble
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *pebbleLoadedDatabase) DriverName() string {
|
||||||
|
return "Pebble " + pebbleDriverVersion() // Parsed from embedded go.mod copy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *pebbleLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Load properties
|
||||||
|
|
||||||
|
content := fmt.Sprintf("Pebble metrics: %#v", ld.db.Metrics())
|
||||||
|
f.propertiesBox.SetText(content)
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
// pebble always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(2)
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels([]string{"Key", "Value"})
|
||||||
|
|
||||||
|
itr, err := ld.db.NewIterWithContext(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer itr.Close()
|
||||||
|
|
||||||
|
for itr.First(); itr.Valid(); itr.Next() {
|
||||||
|
k := itr.Key()
|
||||||
|
v, err := itr.ValueAndErr()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to load data for key %q: %w", formatAny(k), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8(k)))
|
||||||
|
f.contentBox.SetItem(rpos, 1, qt.NewQTableWidgetItem2(formatUtf8(v)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *pebbleLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil // No children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *pebbleLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return nil, nil // No special actions are supported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *pebbleLoadedDatabase) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &pebbleLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type pebbleMemConnection struct{}
|
||||||
|
|
||||||
|
func (pmc *pebbleMemConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
db, err := pebble.Open("", &pebble.Options{FS: vfs.NewMem()})
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pebbleLoadedDatabase{db: db}, `:memory:`, nil // SQLite-style naming
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type pebbleDirConnection struct {
|
||||||
|
Directory autoconfig.ExistingDirectory
|
||||||
|
Readonly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pdc *pebbleDirConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
opts := (&pebble.Options{}).EnsureDefaults()
|
||||||
|
opts.ReadOnly = pdc.Readonly
|
||||||
|
|
||||||
|
db, err := pebble.Open(string(pdc.Directory), opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pebbleLoadedDatabase{db: db}, filepath.Base(string(pdc.Directory)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&pebbleMemConnection{}, "Pebble (Memory)", `:/assets/vendor_cockroach.png`)
|
||||||
|
registerDatabase(&pebbleDirConnection{}, "Pebble", `:/assets/vendor_cockroach.png`)
|
||||||
|
}
|
||||||
275
db_redis.go
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"yvbolt/lexer"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
type redisConnectionOptions struct {
|
||||||
|
Address autoconfig.AddressPort
|
||||||
|
Password autoconfig.Password
|
||||||
|
UseRespv3 bool `ylabel:"Use RESP v3 protocol"`
|
||||||
|
SSH_Tunnel *SSHTunnel
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&redisConnectionOptions{
|
||||||
|
Address: autoconfig.AddressPort{Port: 6379}, // default value
|
||||||
|
}, "Redis", ":/assets/vendor_redis.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
|
||||||
|
ld := &redisLoadedDatabase{
|
||||||
|
currentDb: 0,
|
||||||
|
maxDb: 1,
|
||||||
|
serverVersion: "<unknown>",
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := redis.Options{
|
||||||
|
Addr: fmt.Sprintf("%s:%d", config.Address.Address, config.Address.Port),
|
||||||
|
Password: string(config.Password),
|
||||||
|
UnstableResp3: config.UseRespv3,
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.SSH_Tunnel != nil {
|
||||||
|
sshc, err := config.SSH_Tunnel.Open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// When redis wants to open a tcp conn, don't dial directly, dial via the SSH tunnel
|
||||||
|
// Setting 'Dialer' takes priority over Addr/Network fields.
|
||||||
|
// ssh.Client.DialContext has a matching signature to redis.Options.Dialer
|
||||||
|
opts.Dialer = sshc.DialContext
|
||||||
|
ld.sshc = sshc
|
||||||
|
}
|
||||||
|
|
||||||
|
// Patch in a hook to remember current DB after keepalive reconnection
|
||||||
|
opts.DB = 0 // Default
|
||||||
|
opts.OnConnect = func(ctx context.Context, cn *redis.Conn) error {
|
||||||
|
return cn.Select(ctx, ld.currentDb).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient doesn't necessarily connect, so it can't throw an err
|
||||||
|
ld.db = redis.NewClient(&opts)
|
||||||
|
|
||||||
|
// Make an INFO request (mandatory)
|
||||||
|
info, err := ld.db.InfoMap(ctx).Result()
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("During INFO: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if serverInfo, ok := info["Server"]; ok {
|
||||||
|
if v, ok := serverInfo["redis_version"]; ok {
|
||||||
|
ld.serverVersion = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// List available databases (usually 1..16) with "0" as default
|
||||||
|
// If this fails, probably the target redis does not support multiple databases
|
||||||
|
// (e.g. Redis Cluster). Assume max=0.
|
||||||
|
if maxDatabases, err := ld.db.ConfigGet(ctx, "databases").Result(); err == nil {
|
||||||
|
// Got a result. Must parse it
|
||||||
|
m, err := strconv.ParseInt(maxDatabases["databases"], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", fmt.Errorf("During CONFIG GET databases: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ld.maxDb = int(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
displayName := config.Address.Address
|
||||||
|
|
||||||
|
return ld, displayName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type redisLoadedDatabase struct {
|
||||||
|
db *redis.Client
|
||||||
|
sshc *ssh.Client
|
||||||
|
|
||||||
|
currentDb int
|
||||||
|
maxDb int
|
||||||
|
serverVersion string // populated at connection-time from INFO command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) DriverName() string {
|
||||||
|
return "Redis " + ld.serverVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
// Top-level: Show info() on main Properties tab
|
||||||
|
infostr, err := ld.db.Info(ctx).Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Retreiving database info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.propertiesBox.SetText(infostr)
|
||||||
|
|
||||||
|
// Leave data tab disabled (default behaviour)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
} else if len(bucketPath) == 1 {
|
||||||
|
// One selected database
|
||||||
|
// Figure out its content
|
||||||
|
err := ld.db.Do(ctx, "SELECT", bucketPath[0]).Err()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Switching to database %q: %w", bucketPath[0], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
allKeys, err := ld.db.Keys(ctx, "*").Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Listing keys in database %q: %w", bucketPath[0], err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.propertiesBox.SetText(fmt.Sprintf("Database %s\nTotal keys: %d\n", bucketPath[0], len(allKeys)))
|
||||||
|
|
||||||
|
// Redis always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.SetColumnCount(3)
|
||||||
|
f.contentBox.SetHorizontalHeaderLabels([]string{"Key", "Type", "Value"})
|
||||||
|
|
||||||
|
for _, key := range allKeys {
|
||||||
|
typeName, err := ld.db.Type(ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Loading %q/%q: %w", bucketPath[0], key, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := f.contentBox.RowCount()
|
||||||
|
f.contentBox.SetRowCount(rpos + 1)
|
||||||
|
f.contentBox.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8([]byte(key))))
|
||||||
|
f.contentBox.SetItem(rpos, 1, qt.NewQTableWidgetItem2(typeName))
|
||||||
|
|
||||||
|
switch typeName {
|
||||||
|
case "string":
|
||||||
|
val, err := ld.db.Get(ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Loading %q/%q: %w", bucketPath[0], key, err)
|
||||||
|
}
|
||||||
|
f.contentBox.SetItem(rpos, 2, qt.NewQTableWidgetItem2(val))
|
||||||
|
|
||||||
|
case "hash":
|
||||||
|
val, err := ld.db.HGetAll(ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Loading %q/%q: %w", bucketPath[0], key, err)
|
||||||
|
}
|
||||||
|
// It's a map[string]string
|
||||||
|
f.contentBox.SetItem(rpos, 2, qt.NewQTableWidgetItem2(formatAny(val)))
|
||||||
|
|
||||||
|
case "lists":
|
||||||
|
fallthrough
|
||||||
|
case "sets":
|
||||||
|
fallthrough
|
||||||
|
case "sorted sets":
|
||||||
|
fallthrough
|
||||||
|
case "stream":
|
||||||
|
fallthrough
|
||||||
|
|
||||||
|
default:
|
||||||
|
f.contentBox.SetItem(rpos, 2, qt.NewQTableWidgetItem2("<<<other object type>>>"))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Unexpected nav position %q", bucketPath)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
// ctx := context.Background()
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
// Top-level: list of all child databases (usually 16x)
|
||||||
|
ret := make([]string, 0, ld.maxDb)
|
||||||
|
for i := 0; i < ld.maxDb; i++ {
|
||||||
|
ret = append(ret, fmt.Sprintf("%d", i))
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
|
||||||
|
} else if len(bucketPath) == 1 {
|
||||||
|
// One selected database
|
||||||
|
// No child keys underneath it
|
||||||
|
return []string{}, nil
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("Unexpected nav position %q", bucketPath)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return nil, nil // No special actions are supported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) ExecQuery(query string, resultArea *qt.QTableWidget) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Need to parse the query into separate string+args fields for the protocol
|
||||||
|
fields, err := lexer.Fields(query)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Parsing the query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fields_boxed := box_interface(fields)
|
||||||
|
|
||||||
|
ret, err := ld.db.Do(ctx, fields_boxed...).Result()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("The redis query returned an error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vcl_clear_grid(resultArea)
|
||||||
|
resultArea.SetColumnCount(1)
|
||||||
|
resultArea.SetHorizontalHeaderLabels([]string{"Result"})
|
||||||
|
|
||||||
|
// The result is probably a single value or a string slice
|
||||||
|
switch ret := ret.(type) {
|
||||||
|
case []string:
|
||||||
|
// Multiple values
|
||||||
|
for _, single := range ret {
|
||||||
|
|
||||||
|
rpos := resultArea.RowCount()
|
||||||
|
resultArea.SetRowCount(rpos + 1)
|
||||||
|
resultArea.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatUtf8([]byte(single))))
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Single value
|
||||||
|
rpos := resultArea.RowCount()
|
||||||
|
resultArea.SetRowCount(rpos + 1)
|
||||||
|
resultArea.SetItem(rpos, 0, qt.NewQTableWidgetItem2(formatAny(ret))) // formatUtf8
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
resultArea.ResizeColumnsToContents()
|
||||||
|
resultArea.SetEnabled(true)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *redisLoadedDatabase) Close() {
|
||||||
|
if ld.sshc != nil {
|
||||||
|
_ = ld.sshc.Close() // TODO does this also SIGINT remote processes?
|
||||||
|
}
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &redisLoadedDatabase{} // interface assertion
|
||||||
|
var _ queryableLoadedDatabase = &redisLoadedDatabase{} // interface assertion
|
||||||
458
db_sqlite.go
Normal file
@@ -0,0 +1,458 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"yvbolt/sqliteclidriver"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
mattn_sqlite3 "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
sqliteTablesCaption = "Tables"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sqliteLoadedDatabase struct {
|
||||||
|
db *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) DriverName() string {
|
||||||
|
if _, ok := ld.db.Driver().(*sqliteclidriver.SCDriver); ok {
|
||||||
|
return "SQLite (sqliteclidriver)"
|
||||||
|
}
|
||||||
|
|
||||||
|
ver1, _, _ := mattn_sqlite3.Version()
|
||||||
|
return "SQLite " + ver1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) RenderForNav(f *MainWindowUi, bucketPath []string) error {
|
||||||
|
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
// Top-level
|
||||||
|
f.propertiesBox.SetText("Please select...")
|
||||||
|
return nil
|
||||||
|
|
||||||
|
} else if len(bucketPath) == 1 {
|
||||||
|
// Category (tables, ...)
|
||||||
|
f.propertiesBox.SetText("Please select...")
|
||||||
|
return nil
|
||||||
|
|
||||||
|
} else if len(bucketPath) == 2 && bucketPath[0] == sqliteTablesCaption {
|
||||||
|
// Render for specific table
|
||||||
|
tableName := bucketPath[1]
|
||||||
|
|
||||||
|
// Get some basic properties
|
||||||
|
r := ld.db.QueryRow(`SELECT sql FROM sqlite_schema WHERE name = ?;`, tableName)
|
||||||
|
var schemaStmt string
|
||||||
|
err := r.Scan(&schemaStmt)
|
||||||
|
if err != nil {
|
||||||
|
schemaStmt = fmt.Sprintf("* Failed to describe table %q: %s", tableName, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display table properties
|
||||||
|
f.propertiesBox.SetText(fmt.Sprintf("Selected table %q\n\nSchema:\n\n%s", tableName, schemaStmt))
|
||||||
|
|
||||||
|
// Load column details
|
||||||
|
// Use SELECT form instead of common PRAGMA table_info so we can just get names
|
||||||
|
// We could possibly get this from the main data select, but this will
|
||||||
|
// work even when there are 0 results
|
||||||
|
columnNames, err := ld.sqliteGetColumnNamesForTable(tableName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to load columns for table %q: %w", tableName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
populateColumns(columnNames, f.contentBox)
|
||||||
|
|
||||||
|
// Find primary key, if any
|
||||||
|
var primaryKeyIdx int = -1
|
||||||
|
if primaryKeyColumnName, err := ld.getPrimaryKeyForTable(ctx, ld.db, tableName); err == nil {
|
||||||
|
if search, ok := slice_find(columnNames, primaryKeyColumnName); ok {
|
||||||
|
primaryKeyIdx = search
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select count(*) so we know to display a warning if there are too many entries
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Select * with small limit
|
||||||
|
datar, err := ld.db.Query(`SELECT * FROM "` + tableName + `" LIMIT 1000`) // WARNING can't prepare this parameter, but it comes from the DB (trusted)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to load data for table %q: %w", tableName, err)
|
||||||
|
}
|
||||||
|
defer datar.Close()
|
||||||
|
populateRows(datar, f.contentBox, primaryKeyIdx)
|
||||||
|
|
||||||
|
// We successfully populated the data grid
|
||||||
|
f.contentBox.ResizeColumnsToContents()
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// ??? unknown
|
||||||
|
return errors.New("?")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) sqliteGetColumnNamesForTable(tableName string) ([]string, error) {
|
||||||
|
colr, err := ld.db.Query(`SELECT name FROM pragma_table_info( ? )`, tableName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Query: %w", err)
|
||||||
|
}
|
||||||
|
defer colr.Close()
|
||||||
|
|
||||||
|
var ret []string
|
||||||
|
|
||||||
|
for colr.Next() {
|
||||||
|
|
||||||
|
var columnName string
|
||||||
|
err = colr.Scan(&columnName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Scan: %w", colr.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, columnName)
|
||||||
|
}
|
||||||
|
if colr.Err() != nil {
|
||||||
|
return nil, colr.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateColumns(names []string, dest *qt.QTableWidget) {
|
||||||
|
dest.SetColumnCount(len(names))
|
||||||
|
dest.SetHorizontalHeaderLabels(names)
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateRows(rr *sql.Rows, dest *qt.QTableWidget, pk_index int) {
|
||||||
|
|
||||||
|
numColumns := int(dest.ColumnCount())
|
||||||
|
|
||||||
|
for rr.Next() {
|
||||||
|
fields := make([]interface{}, numColumns)
|
||||||
|
pfields := make([]interface{}, numColumns)
|
||||||
|
for i := 0; i < numColumns; i += 1 {
|
||||||
|
pfields[i] = &fields[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
err := rr.Scan(pfields...)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(dest.QWidget, APPNAME, fmt.Sprintf("Failed to load data: %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := dest.RowCount()
|
||||||
|
dest.SetRowCount(rpos + 1)
|
||||||
|
for i := 0; i < len(fields); i += 1 {
|
||||||
|
|
||||||
|
cellItem := qt.NewQTableWidgetItem2(formatAny(fields[i]))
|
||||||
|
if i == pk_index {
|
||||||
|
cellItem.SetData(DataPrimaryKeyRole, qt.NewQVariant11(formatAny(fields[i]))) // FIXME stop doing string conversion here
|
||||||
|
} else if pk_index < 0 {
|
||||||
|
// We do not have a primary key for this table
|
||||||
|
// Therefore - disable editing
|
||||||
|
cellItem.SetFlags(cellItem.Flags() & ^qt.ItemIsEditable)
|
||||||
|
}
|
||||||
|
|
||||||
|
dest.SetItem(rpos, i, cellItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if rr.Err() != nil {
|
||||||
|
qt.QMessageBox_Warning(dest.QWidget, APPNAME, fmt.Sprintf("Failed to load data: %s", rr.Err().Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *qt.QTableWidget) error {
|
||||||
|
rr, err := ld.db.Query(query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rr.Close()
|
||||||
|
|
||||||
|
vcl_clear_grid(resultArea)
|
||||||
|
|
||||||
|
columns, err := rr.Columns()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
populateColumns(columns, resultArea)
|
||||||
|
|
||||||
|
populateRows(rr, resultArea, -1)
|
||||||
|
|
||||||
|
resultArea.ResizeColumnsToContents()
|
||||||
|
resultArea.SetEnabled(true)
|
||||||
|
resultArea.EditTriggers()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RowQueryContexter interface {
|
||||||
|
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *sqliteLoadedDatabase) getPrimaryKeyForTable(ctx context.Context, tx RowQueryContexter, tableName string) (string, error) {
|
||||||
|
var primaryColumnName string
|
||||||
|
err := tx.QueryRowContext(ctx, `SELECT l.name FROM pragma_table_info(?) as l WHERE l.pk = 1;`, tableName).Scan(&primaryColumnName)
|
||||||
|
return primaryColumnName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *sqliteLoadedDatabase) ApplyChanges(f *App, bucketPath []string) (retErr error) {
|
||||||
|
|
||||||
|
if len(bucketPath) != 2 {
|
||||||
|
return errors.New("invalid selection")
|
||||||
|
}
|
||||||
|
tableName := bucketPath[1]
|
||||||
|
|
||||||
|
// We have rendered row IDs, need to convert back to an SQLite primary key
|
||||||
|
// TODO stash the real key inside f.ui.contentBox.Objects()
|
||||||
|
// FIXME breaks if you try and edit the primary key(!) because the previous
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
tx, err := n.db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var commitOK bool = false
|
||||||
|
defer func() {
|
||||||
|
if !commitOK {
|
||||||
|
err := tx.Rollback()
|
||||||
|
if err != nil {
|
||||||
|
retErr = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Data grid properties
|
||||||
|
var columnNames []string
|
||||||
|
for i := 0; i < f.ui.contentBox.ColumnCount(); i++ {
|
||||||
|
columnNames = append(columnNames, f.ui.contentBox.HorizontalHeaderItem(i).Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query sqlite table metadata to determine which of these is the PRIMARY KEY
|
||||||
|
primaryColumnName, err := n.getPrimaryKeyForTable(ctx, tx, tableName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Finding primary key for update: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert it to an index
|
||||||
|
primaryColumnIdx, ok := slice_find(columnNames, primaryColumnName)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Primary key %q missing from available columns", primaryColumnName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SQLite can only LIMIT 1 on update/delete if it was compiled with
|
||||||
|
// SQLITE_ENABLE_UPDATE_DELETE_LIMIT, which isn't the case for the mattn
|
||||||
|
// cgo library
|
||||||
|
// Skip that, and just rely on primary key uniqueness
|
||||||
|
|
||||||
|
// Edit
|
||||||
|
for rowid, editcells := range f.updateRows {
|
||||||
|
stmt := `UPDATE "` + tableName + `" SET `
|
||||||
|
params := []interface{}{} // FIXME reinstate types for the driver (although SQLite doesn't mind)
|
||||||
|
|
||||||
|
for ct, cell := range editcells {
|
||||||
|
if ct > 0 {
|
||||||
|
stmt += `, `
|
||||||
|
}
|
||||||
|
stmt += `"` + columnNames[cell] + `" = ?`
|
||||||
|
params = append(params, f.ui.contentBox.Item(rowid, cell).Text())
|
||||||
|
}
|
||||||
|
stmt += ` WHERE "` + primaryColumnName + `" = ?`
|
||||||
|
|
||||||
|
// The primary key was stashed in DataPrimaryKeyRole, on the pk_idx'th
|
||||||
|
// column, as a QString qvariant
|
||||||
|
// FIXME avoid string marshalling
|
||||||
|
pkVal := f.ui.contentBox.Item(rowid, primaryColumnIdx).Data(DataPrimaryKeyRole).ToString()
|
||||||
|
params = append(params, pkVal)
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, stmt, params...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Updating row %q: %w", pkVal, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete by key (affects rowids after re-render)
|
||||||
|
for rowid, _ := range f.deleteRows {
|
||||||
|
pkVal := f.ui.contentBox.Item(rowid, primaryColumnIdx).Text()
|
||||||
|
|
||||||
|
stmt := `DELETE FROM "` + tableName + `" WHERE "` + primaryColumnName + `" = ?`
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, stmt, pkVal)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Deleting row %q: %w", pkVal, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert all new entries
|
||||||
|
for rowid, _ := range f.insertRows {
|
||||||
|
stmt := `INSERT INTO "` + tableName + `" (` + strings.Join(columnNames, `, `) + `) VALUES (`
|
||||||
|
params := []interface{}{} // FIXME reinstate types for the driver (although SQLite doesn't mind)
|
||||||
|
|
||||||
|
for colid := 0; colid < len(columnNames); colid++ {
|
||||||
|
if colid > 0 {
|
||||||
|
stmt += `, `
|
||||||
|
}
|
||||||
|
stmt += "?"
|
||||||
|
params = append(params, f.ui.contentBox.Item(rowid, colid).Text())
|
||||||
|
}
|
||||||
|
stmt += `)`
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, stmt, params...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Inserting row: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
commitOK = true // no need for rollback
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
// The top-level children are always:
|
||||||
|
return []string{sqliteTablesCaption}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bucketPath) == 1 && bucketPath[0] == sqliteTablesCaption {
|
||||||
|
rr, err := ld.db.Query(`SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC;`)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rr.Close()
|
||||||
|
|
||||||
|
var gather []string
|
||||||
|
for rr.Next() {
|
||||||
|
var tableName string
|
||||||
|
err = rr.Scan(&tableName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
gather = append(gather, tableName)
|
||||||
|
}
|
||||||
|
if rr.Err() != nil {
|
||||||
|
return nil, rr.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return gather, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bucketPath) == 2 {
|
||||||
|
return nil, nil // Never any deeper children
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unknown nav path %#v", bucketPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) NavContext(bucketPath []string) (ret []contextAction, err error) {
|
||||||
|
|
||||||
|
if len(bucketPath) == 0 {
|
||||||
|
ret = append(ret, contextAction{"Compact database", ld.CompactDatabase})
|
||||||
|
ret = append(ret, contextAction{"Export backup...", ld.ExportBackup})
|
||||||
|
}
|
||||||
|
if len(bucketPath) == 2 {
|
||||||
|
ret = append(ret, contextAction{"Drop table", ld.DropTable})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) CompactDatabase(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
_, err := ld.db.Exec(`VACUUM;`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) ExportBackup(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
// Popup for output file
|
||||||
|
savePath := qt.QFileDialog_GetSaveFileName4(sender.TreeWidget().QWidget, "Save backup as...", "", "SQLite database (*.db *.db3 *.sqlite *.sqlite3);;All files (*.*)")
|
||||||
|
if savePath == "" {
|
||||||
|
return nil // cancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ld.db.Exec(`VACUUM INTO ?`, savePath)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) DropTable(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
if len(bucketPath) != 2 {
|
||||||
|
return errors.New("Invalid selection")
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
tableName := bucketPath[1]
|
||||||
|
|
||||||
|
if !vcl_confirm_dialog(sender.TreeWidget().QWidget, "Drop table", fmt.Sprintf("Are you sure you want to drop the table %q?", tableName)) {
|
||||||
|
return nil // cancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ld.db.Exec(`DROP TABLE "` + tableName + `"`) // WARNING can't prepare this parameter, but it comes from the DB (trusted)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *sqliteLoadedDatabase) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &sqliteLoadedDatabase{} // interface assertion
|
||||||
|
var _ editableLoadedDatabase = &sqliteLoadedDatabase{} // interface assertion
|
||||||
|
var _ queryableLoadedDatabase = &sqliteLoadedDatabase{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type sqliteConnection struct {
|
||||||
|
Database autoconfig.ExistingFile `yfilter:"SQLite database (*.db *.db3 *.sqlite *.sqlite3);;All files (*.*)"`
|
||||||
|
CliDriver bool `ylabel:"Use experimental CLI driver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
|
||||||
|
driver := "sqlite3"
|
||||||
|
if sc.CliDriver {
|
||||||
|
driver = "sqliteclidriver"
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := sql.Open(driver, string(sc.Database))
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &sqliteLoadedDatabase{db: db}, filepath.Base(string(sc.Database)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type sqliteMemoryConnection struct{}
|
||||||
|
|
||||||
|
func (sc *sqliteMemoryConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
db, err := sql.Open("sqlite3", ":memory:")
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &sqliteLoadedDatabase{db: db}, ":memory:", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerDatabase(&sqliteConnection{}, "SQLite", `:/assets/vendor_sqlite.png`)
|
||||||
|
registerDatabase(&sqliteMemoryConnection{}, "SQLite (Memory)", `:/assets/vendor_sqlite.png`)
|
||||||
|
}
|
||||||
94
debconf/debconf.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package debconf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultConfigDat = `/var/cache/debconf/config.dat`
|
||||||
|
DefaultPasswordsDat = `/var/cache/debconf/passwords.dat`
|
||||||
|
DefaultTemplatesDat = `/var/cache/debconf/templates.dat`
|
||||||
|
)
|
||||||
|
|
||||||
|
type Entry struct {
|
||||||
|
Name string
|
||||||
|
Properties [][2]string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Database struct {
|
||||||
|
Entries []Entry
|
||||||
|
AllColumnNames []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Parse(r io.Reader) (*Database, error) {
|
||||||
|
sc := bufio.NewScanner(r)
|
||||||
|
|
||||||
|
var entries []Entry
|
||||||
|
var wip Entry
|
||||||
|
var linenum int = 0
|
||||||
|
|
||||||
|
knownColumnNames := map[string]struct{}{
|
||||||
|
"Name": struct{}{},
|
||||||
|
}
|
||||||
|
var discoveredColumns []string = []string{"Name"}
|
||||||
|
|
||||||
|
for sc.Scan() {
|
||||||
|
linenum++
|
||||||
|
line := sc.Text()
|
||||||
|
|
||||||
|
if line == "" {
|
||||||
|
if wip.Name != "" {
|
||||||
|
entries = append(entries, wip)
|
||||||
|
wip = Entry{}
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if line[0] == ' ' {
|
||||||
|
// continuation of last text entry
|
||||||
|
if len(wip.Properties) == 0 {
|
||||||
|
return nil, fmt.Errorf("Continuation of nonexistent entry on line %d", linenum)
|
||||||
|
}
|
||||||
|
|
||||||
|
wip.Properties[len(wip.Properties)-1][1] += line[1:]
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// New pair on current element
|
||||||
|
key, rest, ok := strings.Cut(line, `:`)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("Missing : on line %d", linenum)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := knownColumnNames[key]; !ok {
|
||||||
|
knownColumnNames[key] = struct{}{}
|
||||||
|
discoveredColumns = append(discoveredColumns, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
rest = strings.TrimLeft(rest, " \t")
|
||||||
|
|
||||||
|
if key == `Name` {
|
||||||
|
wip.Name = rest
|
||||||
|
} else {
|
||||||
|
wip.Properties = append(wip.Properties, [2]string{key, rest})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if sc.Err() != nil {
|
||||||
|
return nil, sc.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
if wip.Name != "" {
|
||||||
|
entries = append(entries, wip)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Database{
|
||||||
|
Entries: entries,
|
||||||
|
AllColumnNames: discoveredColumns,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
30
debconf/debconf_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package debconf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDebconfParse(t *testing.T) {
|
||||||
|
src, err := os.Open(DefaultConfigDat)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
t.Skip(err)
|
||||||
|
}
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
db, err := Parse(src)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Parse: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(db.Entries) == 0 {
|
||||||
|
t.Errorf("expected >0 entries, got %v", len(db.Entries))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(db.AllColumnNames) == 0 {
|
||||||
|
t.Errorf("expected >0 column names, got %v", len(db.AllColumnNames))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 30 KiB |
17
embed.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate miqt-rcc -Input "embed.qrc" -OutputGo "embed.go" -OutputRcc "embed.rcc" -Qt6
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed embed.rcc
|
||||||
|
var _resourceRcc []byte
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_ = embed.FS{}
|
||||||
|
qt.QResource_RegisterResourceWithRccData(&_resourceRcc[0])
|
||||||
|
}
|
||||||
32
embed.qrc
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>assets/add.png</file>
|
||||||
|
<file>assets/arrow_refresh.png</file>
|
||||||
|
<file>assets/chart_bar.png</file>
|
||||||
|
<file>assets/database.png</file>
|
||||||
|
<file>assets/database_add.png</file>
|
||||||
|
<file>assets/database_delete.png</file>
|
||||||
|
<file>assets/database_lightning.png</file>
|
||||||
|
<file>assets/database_save.png</file>
|
||||||
|
<file>assets/delete.png</file>
|
||||||
|
<file>assets/lightning.png</file>
|
||||||
|
<file>assets/lightning_go.png</file>
|
||||||
|
<file>assets/pencil.png</file>
|
||||||
|
<file>assets/pencil_add.png</file>
|
||||||
|
<file>assets/pencil_delete.png</file>
|
||||||
|
<file>assets/pencil_go.png</file>
|
||||||
|
<file>assets/resultset_next.png</file>
|
||||||
|
<file>assets/table.png</file>
|
||||||
|
<file>assets/table_add.png</file>
|
||||||
|
<file>assets/table_delete.png</file>
|
||||||
|
<file>assets/table_save.png</file>
|
||||||
|
<file>assets/vendor_cockroach.png</file>
|
||||||
|
<file>assets/vendor_debian.png</file>
|
||||||
|
<file>assets/vendor_dgraph.png</file>
|
||||||
|
<file>assets/vendor_github.png</file>
|
||||||
|
<file>assets/vendor_leveldb.png</file>
|
||||||
|
<file>assets/vendor_mysql.png</file>
|
||||||
|
<file>assets/vendor_redis.png</file>
|
||||||
|
<file>assets/vendor_sqlite.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
85
go.mod
@@ -1,45 +1,62 @@
|
|||||||
module yvbolt
|
module yvbolt
|
||||||
|
|
||||||
go 1.19
|
go 1.24.0
|
||||||
|
|
||||||
|
toolchain go1.24.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgraph-io/badger/v4 v4.2.0
|
github.com/cockroachdb/pebble v1.1.5
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
github.com/dgraph-io/badger/v4 v4.8.0
|
||||||
github.com/ying32/govcl v2.2.3+incompatible
|
github.com/google/uuid v1.6.0
|
||||||
go.etcd.io/bbolt v1.4.0-alpha.1
|
github.com/mappu/autoconfig v0.2.0
|
||||||
modernc.org/sqlite v1.24.0
|
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.32
|
||||||
|
github.com/redis/go-redis/v9 v9.16.0
|
||||||
|
github.com/stretchr/testify v1.11.1
|
||||||
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
|
go.etcd.io/bbolt v1.4.3
|
||||||
|
golang.org/x/crypto v0.44.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
github.com/DataDog/zstd v1.5.7 // indirect
|
||||||
github.com/dgraph-io/ristretto v0.1.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/cockroachdb/errors v1.12.0 // indirect
|
||||||
|
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
|
||||||
|
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect
|
||||||
|
github.com/cockroachdb/redact v1.1.6 // indirect
|
||||||
|
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
|
github.com/getsentry/sentry-go v0.36.2 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/glog v1.0.0 // indirect
|
github.com/golang/snappy v1.0.0 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
|
github.com/google/flatbuffers v25.9.23+incompatible // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/klauspost/compress v1.18.1 // indirect
|
||||||
github.com/golang/snappy v0.0.3 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/google/flatbuffers v1.12.1 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
|
||||||
github.com/klauspost/compress v1.12.3 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
go.opencensus.io v0.22.5 // indirect
|
github.com/prometheus/client_golang v1.23.2 // indirect
|
||||||
golang.org/x/mod v0.3.0 // indirect
|
github.com/prometheus/client_model v0.6.2 // indirect
|
||||||
golang.org/x/net v0.7.0 // indirect
|
github.com/prometheus/common v0.67.2 // indirect
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
github.com/prometheus/procfs v0.19.2 // indirect
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
|
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
google.golang.org/protobuf v1.28.1 // indirect
|
go.opentelemetry.io/otel v1.38.0 // indirect
|
||||||
lukechampine.com/uint128 v1.2.0 // indirect
|
go.opentelemetry.io/otel/metric v1.38.0 // indirect
|
||||||
modernc.org/cc/v3 v3.40.0 // indirect
|
go.opentelemetry.io/otel/trace v1.38.0 // indirect
|
||||||
modernc.org/ccgo/v3 v3.16.13 // indirect
|
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||||
modernc.org/libc v1.22.5 // indirect
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
||||||
modernc.org/mathutil v1.5.0 // indirect
|
golang.org/x/net v0.46.0 // indirect
|
||||||
modernc.org/memory v1.5.0 // indirect
|
golang.org/x/sys v0.38.0 // indirect
|
||||||
modernc.org/opt v0.1.3 // indirect
|
golang.org/x/text v0.31.0 // indirect
|
||||||
modernc.org/strutil v1.1.3 // indirect
|
google.golang.org/protobuf v1.36.10 // indirect
|
||||||
modernc.org/token v1.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
254
go.sum
@@ -1,159 +1,181 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
github.com/DataDog/zstd v1.5.7 h1:ybO8RBeh29qrxIhCA9E8gKY6xfONU9T6G6aP9DTKfLE=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/DataDog/zstd v1.5.7/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
|
||||||
|
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
|
||||||
|
github.com/cockroachdb/errors v1.12.0 h1:d7oCs6vuIMUQRVbi6jWWWEJZahLCfJpnJSVobd1/sUo=
|
||||||
|
github.com/cockroachdb/errors v1.12.0/go.mod h1:SvzfYNNBshAVbZ8wzNc/UPK3w1vf0dKDUP41ucAIf7g=
|
||||||
|
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 h1:pU88SPhIFid6/k0egdR5V6eALQYq2qbSmukrkgIh/0A=
|
||||||
|
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M=
|
||||||
|
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILMqgNeV5jiqR4j+sTuvQNHdf2chuKj1M5k=
|
||||||
|
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
|
||||||
|
github.com/cockroachdb/pebble v1.1.5 h1:5AAWCBWbat0uE0blr8qzufZP5tBjkRyy/jWe1QWLnvw=
|
||||||
|
github.com/cockroachdb/pebble v1.1.5/go.mod h1:17wO9el1YEigxkP/YtV8NtCivQDgoCyBg5c4VR/eOWo=
|
||||||
|
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
|
||||||
|
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||||
|
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb h1:3bCgBvB8PbJVMX1ouCcSIxvsqKPYM7gs72o0zC76n9g=
|
||||||
|
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgraph-io/badger/v4 v4.2.0 h1:kJrlajbXXL9DFTNuhhu9yCx7JJa4qpYWxtE8BzuWsEs=
|
github.com/dgraph-io/badger/v4 v4.8.0 h1:JYph1ChBijCw8SLeybvPINizbDKWZ5n/GYbz2yhN/bs=
|
||||||
github.com/dgraph-io/badger/v4 v4.2.0/go.mod h1:qfCqhPoWDFJRx1gp5QwwyGo8xk1lbHUxvK9nK0OGAak=
|
github.com/dgraph-io/badger/v4 v4.8.0/go.mod h1:U6on6e8k/RTbUWxqKR0MvugJuVmkxSNc79ap4917h4w=
|
||||||
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
|
github.com/dgraph-io/ristretto/v2 v2.3.0 h1:qTQ38m7oIyd4GAed/QkUZyPFNMnvVWyazGXRwvOt5zk=
|
||||||
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
|
github.com/dgraph-io/ristretto/v2 v2.3.0/go.mod h1:gpoRV3VzrEY1a9dWAYV6T1U7YzfgttXdd/ZzL1s9OZM=
|
||||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
|
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
|
||||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/getsentry/sentry-go v0.36.2 h1:uhuxRPTrUy0dnSzTd0LrYXlBYygLkKY0hhlG5LXarzM=
|
||||||
|
github.com/getsentry/sentry-go v0.36.2/go.mod h1:p5Im24mJBeruET8Q4bbcMfCQ+F+Iadc4L48tB1apo2c=
|
||||||
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
|
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||||
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
|
||||||
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
|
|
||||||
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
|
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I=
|
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/google/flatbuffers v25.9.23+incompatible h1:rGZKv+wOb6QPzIdkM2KxhBZCDrA0DeN6DNmRDrqIsQU=
|
||||||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
|
github.com/google/flatbuffers v25.9.23+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
|
||||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/flatbuffers v1.12.1 h1:MVlul7pQNoDzWRLTw5imwYsl+usrS1TXG2H4jg6ImGw=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
|
||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/klauspost/compress v1.12.3 h1:G5AfA94pHPysR56qqrkO2pxEexdDzrpFJ6yt/VqWxVU=
|
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
|
||||||
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
|
||||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/mappu/autoconfig v0.1.0 h1:T740iW7/rkqi+pxJIlP+WB433h34jNRjqqG9ABTSScs=
|
||||||
|
github.com/mappu/autoconfig v0.1.0/go.mod h1:kca6kaYjqOwkZnY9z5YKo0oI/7Bxe2fMIHhYzXwGHEE=
|
||||||
|
github.com/mappu/autoconfig v0.2.0 h1:5auhryqiubVBFq9CdY+VHU36bysG70tRGPpyT+M4ycs=
|
||||||
|
github.com/mappu/autoconfig v0.2.0/go.mod h1:kca6kaYjqOwkZnY9z5YKo0oI/7Bxe2fMIHhYzXwGHEE=
|
||||||
|
github.com/mappu/miqt v0.12.0 h1:bBMBDeACmV8TbdLfoN51la7kF6QT3sNAcG+ZdRDgmxU=
|
||||||
|
github.com/mappu/miqt v0.12.0/go.mod h1:xFg7ADaO1QSkmXPsPODoKe/bydJpRG9fgCYyIDl/h1U=
|
||||||
|
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf h1:SmBzNUevLUzu1msJ5xzWH/Kot+GtOtoz0u9la42dRU4=
|
||||||
|
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf/go.mod h1:xFg7ADaO1QSkmXPsPODoKe/bydJpRG9fgCYyIDl/h1U=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||||
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||||
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
|
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||||
|
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/prometheus/common v0.67.2 h1:PcBAckGFTIHt2+L3I33uNRTlKTplNzFctXcWhPyAEN8=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/prometheus/common v0.67.2/go.mod h1:63W3KZb1JOKgcjlIr64WW/LvFGAqKPj0atm+knVGEko=
|
||||||
github.com/ying32/govcl v2.2.3+incompatible h1:Iyfcl26yNE1USm+3uG+btQyhkoFIV18+VITrUdHu8Lw=
|
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
|
||||||
github.com/ying32/govcl v2.2.3+incompatible/go.mod h1:yZVtbJ9Md1nAVxtHKIriKZn4K6TQYqI1en3sN/m9FJ8=
|
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
|
||||||
|
github.com/redis/go-redis/v9 v9.16.0 h1:OotgqgLSRCmzfqChbQyG1PHC3tLNR89DG4jdOERSEP4=
|
||||||
|
github.com/redis/go-redis/v9 v9.16.0/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||||
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
|
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||||
|
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
go.etcd.io/bbolt v1.4.0-alpha.1 h1:3yrqQzbRRPFPdOMWS/QQIVxVnzSkAZQYeWlZFv1kbj4=
|
go.etcd.io/bbolt v1.4.3 h1:dEadXpI6G79deX5prL3QRNP6JB8UxVkqo4UPnHaNXJo=
|
||||||
go.etcd.io/bbolt v1.4.0-alpha.1/go.mod h1:S/Z/Nm3iuOnyO1W4XuFfPci51Gj6F1Hv0z8hisyYYOw=
|
go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E=
|
||||||
go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
|
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||||
|
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||||
|
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||||
|
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||||
|
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||||
|
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||||
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
|
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
|
||||||
|
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/crypto v0.44.0 h1:A97SsFvM3AIwEEmTBiaxPPTYpDC47w720rdiiUvgoAU=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/crypto v0.44.0/go.mod h1:013i+Nw79BMiQiMsOPcVCB5ZIJbYkerPrGnOa00tvmc=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
||||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
|
||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
|
||||||
|
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
|
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
|
||||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
|
||||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
|
|
||||||
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
|
||||||
modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=
|
|
||||||
modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
|
|
||||||
modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
|
|
||||||
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
|
|
||||||
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
|
|
||||||
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
|
|
||||||
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
|
|
||||||
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
|
|
||||||
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
|
|
||||||
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
|
||||||
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
|
|
||||||
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
|
||||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
|
||||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
|
||||||
modernc.org/sqlite v1.24.0 h1:EsClRIWHGhLTCX44p+Ri/JLD+vFGo0QGjasg2/F9TlI=
|
|
||||||
modernc.org/sqlite v1.24.0/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
|
|
||||||
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
|
|
||||||
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
|
|
||||||
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
|
|
||||||
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
|
|
||||||
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
|
||||||
modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY=
|
|
||||||
|
|||||||
56
images.go
@@ -1,56 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
|
|
||||||
"github.com/ying32/govcl/vcl"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed assets/*
|
|
||||||
var assetsFs embed.FS
|
|
||||||
|
|
||||||
const (
|
|
||||||
imgChartBar int32 = iota
|
|
||||||
imgDatabase
|
|
||||||
imgDatabaseAdd
|
|
||||||
imgDatabaseDelete
|
|
||||||
imgDatabaseLightning
|
|
||||||
imgDatabaseSave
|
|
||||||
imgLightning
|
|
||||||
imgTable
|
|
||||||
imgTableAdd
|
|
||||||
imgTableDelete
|
|
||||||
imgTableSave
|
|
||||||
)
|
|
||||||
|
|
||||||
func loadImages(owner vcl.IComponent) *vcl.TImageList {
|
|
||||||
|
|
||||||
mustLoad := func(n string) *vcl.TBitmap {
|
|
||||||
imgData, err := assetsFs.ReadFile(n)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
png := vcl.NewPngImage()
|
|
||||||
png.LoadFromBytes(imgData)
|
|
||||||
|
|
||||||
ret := vcl.NewBitmap()
|
|
||||||
ret.Assign(png)
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
ilist := vcl.NewImageList(owner)
|
|
||||||
ilist.Add(mustLoad("assets/chart_bar.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/database.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/database_add.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/database_delete.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/database_lightning.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/database_save.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/lightning.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/table.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/table_add.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/table_delete.png"), nil)
|
|
||||||
ilist.Add(mustLoad("assets/table_save.png"), nil)
|
|
||||||
return ilist
|
|
||||||
|
|
||||||
}
|
|
||||||
155
lexer/lexer.go
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
package lexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func isWhitespace(r byte) bool {
|
||||||
|
return (r == ' ' || r == '\t' || r == '\r' || r == '\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
func Quote(input string) string {
|
||||||
|
return `"` + strings.ReplaceAll(strings.ReplaceAll(input, `\`, `\\`), `"`, `\"`) + `"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields splits a string into separate tokens using something kind of vaguely
|
||||||
|
// like how SQL would do it.
|
||||||
|
// The result still includes the quote and backslash characters.
|
||||||
|
func Fields(input string) ([]string, error) {
|
||||||
|
|
||||||
|
const (
|
||||||
|
StateToplevel = 0
|
||||||
|
StateWhitespace = 1
|
||||||
|
StateInDoubleQuote = 2
|
||||||
|
StateInDoubleQuoteSlash = 3
|
||||||
|
StateInSingleQuote = 4
|
||||||
|
StateInSingleQuoteSlash = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ret []string
|
||||||
|
state int = StateToplevel
|
||||||
|
wip string
|
||||||
|
)
|
||||||
|
|
||||||
|
for pos := 0; pos < len(input); pos++ {
|
||||||
|
c := input[pos]
|
||||||
|
|
||||||
|
switch state {
|
||||||
|
|
||||||
|
case StateToplevel:
|
||||||
|
if isWhitespace(c) {
|
||||||
|
state = StateWhitespace
|
||||||
|
if len(wip) != 0 {
|
||||||
|
ret = append(ret, wip)
|
||||||
|
wip = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if c == '"' {
|
||||||
|
if len(wip) != 0 {
|
||||||
|
return nil, fmt.Errorf(`Unexpected " at char %d`, pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInDoubleQuote
|
||||||
|
|
||||||
|
} else if c == '\'' {
|
||||||
|
if len(wip) != 0 {
|
||||||
|
return nil, fmt.Errorf(`Unexpected ' at char %d`, pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInSingleQuote
|
||||||
|
|
||||||
|
} else if c == '\\' {
|
||||||
|
return nil, fmt.Errorf(`Unexpected \ at char %d`, pos)
|
||||||
|
|
||||||
|
} else if c == '(' || c == ')' || c == '?' || c == ',' || c == '+' || c == '*' || c == '-' || c == '/' || c == '%' || c == ';' || c == '=' {
|
||||||
|
// Tokenize separately, even if they appear touching another top-level token
|
||||||
|
// Should still be safe to re-join
|
||||||
|
if len(wip) != 0 {
|
||||||
|
ret = append(ret, wip)
|
||||||
|
wip = ""
|
||||||
|
}
|
||||||
|
ret = append(ret, string(c))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wip += string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
case StateWhitespace:
|
||||||
|
if isWhitespace(c) {
|
||||||
|
// continue
|
||||||
|
} else {
|
||||||
|
state = StateToplevel
|
||||||
|
pos-- // reparse
|
||||||
|
}
|
||||||
|
|
||||||
|
case StateInDoubleQuote:
|
||||||
|
if c == '"' {
|
||||||
|
wip += string(c)
|
||||||
|
ret = append(ret, wip)
|
||||||
|
wip = ""
|
||||||
|
state = StateToplevel
|
||||||
|
|
||||||
|
} else if c == '\\' {
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInDoubleQuoteSlash
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wip += string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
case StateInDoubleQuoteSlash:
|
||||||
|
if isWhitespace(c) {
|
||||||
|
return nil, fmt.Errorf(`Unexpected whitespace after \ at char %d`, pos)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInDoubleQuote
|
||||||
|
}
|
||||||
|
|
||||||
|
case StateInSingleQuote:
|
||||||
|
if c == '\'' {
|
||||||
|
wip += string(c)
|
||||||
|
ret = append(ret, wip)
|
||||||
|
wip = ""
|
||||||
|
state = StateToplevel
|
||||||
|
|
||||||
|
} else if c == '\\' {
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInSingleQuoteSlash
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wip += string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
case StateInSingleQuoteSlash:
|
||||||
|
if isWhitespace(c) {
|
||||||
|
return nil, fmt.Errorf(`Unexpected whitespace after \ at char %d`, pos)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wip += string(c)
|
||||||
|
state = StateInSingleQuote
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reached the end of input stream
|
||||||
|
switch state {
|
||||||
|
case StateToplevel:
|
||||||
|
if len(wip) > 0 {
|
||||||
|
ret = append(ret, wip)
|
||||||
|
wip = ""
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
|
||||||
|
case StateWhitespace:
|
||||||
|
return ret, nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf(`Unexpected end of quoted input`)
|
||||||
|
}
|
||||||
|
}
|
||||||
125
lexer/lexer_test.go
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package lexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLexer(t *testing.T) {
|
||||||
|
type testCase struct {
|
||||||
|
input string
|
||||||
|
expect []string
|
||||||
|
expectErr bool
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []testCase{
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: "foo bar baz",
|
||||||
|
expect: []string{"foo", "bar", "baz"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Quotes
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: `foo "bar" baz`,
|
||||||
|
expect: []string{"foo", `"bar"`, "baz"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo "bar baz" quux`,
|
||||||
|
expect: []string{"foo", `"bar baz"`, "quux"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo 'bar baz' quux`,
|
||||||
|
expect: []string{"foo", `'bar baz'`, "quux"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Escape characters
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: `foo 'bar \n baz' quux`,
|
||||||
|
expect: []string{"foo", `'bar \n baz'`, "quux"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo "bar\"" baz`,
|
||||||
|
expect: []string{"foo", `"bar\""`, "baz"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Collapsing whitespace
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: " foo bar \r\t\n baz\n",
|
||||||
|
expect: []string{"foo", "bar", "baz"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Special characters lexed as separate tokens, but only at top level
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: `3+5*(2.3/6);`,
|
||||||
|
expect: []string{"3", `+`, "5", "*", "(", "2.3", "/", "6", ")", ";"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `SELECT "3+5*(2.3/6)" AS expression;`,
|
||||||
|
expect: []string{"SELECT", `"3+5*(2.3/6)"`, "AS", "expression", ";"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `INSERT INTO foo (bar, baz) VALUES (?, ?);`,
|
||||||
|
expect: []string{"INSERT", "INTO", "foo", "(", "bar", ",", "baz", ")", "VALUES", "(", "?", ",", "?", ")", ";"},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
|
||||||
|
testCase{
|
||||||
|
input: `foo "bar`,
|
||||||
|
expect: nil,
|
||||||
|
expectErr: true, // mismatched quotes
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo 'bar`,
|
||||||
|
expect: nil,
|
||||||
|
expectErr: true, // mismatched quotes
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo \"bar"`,
|
||||||
|
expect: nil,
|
||||||
|
expectErr: true, // invalid top-level escape
|
||||||
|
},
|
||||||
|
testCase{
|
||||||
|
input: `foo "bar\ "`,
|
||||||
|
expect: nil,
|
||||||
|
expectErr: true, // escaping nothing
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
out, err := Fields(tc.input)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if !tc.expectErr {
|
||||||
|
t.Errorf("Test %q got error %v, expected nil", tc.input, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if tc.expectErr {
|
||||||
|
t.Errorf("Test %q got error <nil>, expected error", tc.input)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(out, tc.expect) {
|
||||||
|
t.Errorf("Test %q\n- got: %#v\n- expected %#v", tc.input, out, tc.expect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,31 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ying32/govcl/vcl"
|
"errors"
|
||||||
|
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrNavNotExist error = errors.New("The selected item no longer exists")
|
||||||
|
|
||||||
|
type contextAction struct {
|
||||||
|
Name string
|
||||||
|
Callback func(sender *qt.QTreeWidgetItem, bucketPath []string) error
|
||||||
|
}
|
||||||
|
|
||||||
// loadedDatabase is a DB-agnostic interface for each loaded database.
|
// loadedDatabase is a DB-agnostic interface for each loaded database.
|
||||||
type loadedDatabase interface {
|
type loadedDatabase interface {
|
||||||
DisplayName() string
|
|
||||||
DriverName() string
|
DriverName() string
|
||||||
RootElement() *vcl.TTreeNode
|
RenderForNav(f *MainWindowUi, bucketPath []string) error
|
||||||
RenderForNav(f *TMainForm, ndata *navData)
|
NavChildren(bucketPath []string) ([]string, error)
|
||||||
ExecQuery(query string, resultArea *vcl.TListView)
|
NavContext(bucketPath []string) ([]contextAction, error)
|
||||||
NavChildren(ndata *navData) ([]string, error)
|
Close()
|
||||||
Keepalive(ndata *navData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// navData is the .Data() pointer for each TTreeNode in the left-hand tree.
|
type queryableLoadedDatabase interface {
|
||||||
type navData struct {
|
ExecQuery(query string, resultArea *qt.QTableWidget) error
|
||||||
ld loadedDatabase
|
}
|
||||||
childrenLoaded bool
|
|
||||||
bucketPath []string
|
type editableLoadedDatabase interface {
|
||||||
|
ApplyChanges(f *App, bucketPath []string) error
|
||||||
}
|
}
|
||||||
|
|||||||
911
main.go
@@ -1,325 +1,684 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
_ "github.com/ying32/govcl/pkgs/winappres" // Extra _syso files for Windows
|
qt "github.com/mappu/miqt/qt6"
|
||||||
"github.com/ying32/govcl/vcl"
|
|
||||||
"github.com/ying32/govcl/vcl/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MY_SPACING = 6
|
APPNAME = "yvbolt"
|
||||||
MY_HEIGHT = 90
|
HOMEPAGE_URL = "https://code.ivysaur.me/yvbolt"
|
||||||
MY_WIDTH = 180
|
|
||||||
|
CO_INSERT = qt.Yellow
|
||||||
|
CO_EDIT_IMPLICIT = qt.Green
|
||||||
|
CO_EDIT_EXPLICIT = qt.DarkGreen
|
||||||
|
CO_DELETE = qt.Red
|
||||||
)
|
)
|
||||||
|
|
||||||
type TMainForm struct {
|
type App struct {
|
||||||
*vcl.TForm
|
ui *MainWindowUi
|
||||||
|
|
||||||
ImageList *vcl.TImageList
|
none *noLoadedDatabase
|
||||||
Menu *vcl.TMainMenu
|
|
||||||
StatusBar *vcl.TStatusBar
|
|
||||||
Buckets *vcl.TTreeView
|
|
||||||
Tabs *vcl.TPageControl
|
|
||||||
propertiesBox *vcl.TMemo
|
|
||||||
contentBox *vcl.TListView
|
|
||||||
queryInput *vcl.TMemo
|
|
||||||
queryResult *vcl.TListView
|
|
||||||
|
|
||||||
dbs []loadedDatabase
|
dbs_next int
|
||||||
|
dbs map[int]loadedDatabase
|
||||||
|
|
||||||
|
isEditing bool
|
||||||
|
updateRows map[int][]int // row => []column
|
||||||
|
insertRows map[int]struct{}
|
||||||
|
deleteRows map[int]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
func newApp() *App {
|
||||||
mainForm *TMainForm
|
|
||||||
)
|
a := &App{}
|
||||||
|
|
||||||
|
a.dbs_next = 0
|
||||||
|
a.dbs = make(map[int]loadedDatabase, 0)
|
||||||
|
|
||||||
|
a.isEditing = false
|
||||||
|
a.updateRows = make(map[int][]int, 0)
|
||||||
|
a.insertRows = make(map[int]struct{}, 0)
|
||||||
|
a.deleteRows = make(map[int]struct{}, 0)
|
||||||
|
|
||||||
|
a.ui = NewMainWindowUi()
|
||||||
|
|
||||||
|
// "Midlight" is pretty close on Breeze but wrong on Fusion and Windows
|
||||||
|
// AlternateBase ^
|
||||||
|
// Window --> too dark
|
||||||
|
// Button --> too light on Breeze; close on Fusion; too light on Windows
|
||||||
|
// Light --> too light on Breeze; correct on Fusion; too light on Windows
|
||||||
|
|
||||||
|
currentStyle := strings.ToLower(qt.QApplication_Style().Name())
|
||||||
|
|
||||||
|
effectiveTabBackground := qt.QPalette__Window // correct on Windows
|
||||||
|
if currentStyle == "fusion" {
|
||||||
|
effectiveTabBackground = qt.QPalette__Light
|
||||||
|
} else if currentStyle == "breeze" {
|
||||||
|
effectiveTabBackground = qt.QPalette__Midlight // ?? how does this look on dark mode...?
|
||||||
|
}
|
||||||
|
|
||||||
|
a.ui.propertiesBox.Viewport().SetBackgroundRole(effectiveTabBackground)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
a.ui.actionConnect.OnTriggered(a.OnMnuConnectClick)
|
||||||
|
|
||||||
|
a.ui.actionE_xit.OnTriggered(a.OnMnuFileExitClick)
|
||||||
|
|
||||||
|
a.ui.mnuExecute.OnTriggered(a.OnQueryExecute)
|
||||||
|
|
||||||
|
a.ui.mnuDriverVersions.OnTriggered(a.OnMenuHelpVersion)
|
||||||
|
a.ui.mnuHelpAbout.OnTriggered(a.OnMnuHelpHomepage)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
a.ui.Buckets.OnCurrentItemChanged(a.OnNavChange)
|
||||||
|
a.ui.Buckets.SetContextMenuPolicy(qt.CustomContextMenu)
|
||||||
|
a.ui.Buckets.OnCustomContextMenuRequested(a.OnNavContextPopup)
|
||||||
|
a.ui.Buckets.OnExpanded(func(index *qt.QModelIndex) {
|
||||||
|
if index == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
item := a.ui.Buckets.ItemFromIndex(index)
|
||||||
|
if item == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
a.OnNavExpanding(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
a.ui.dataRefreshBtn.OnClicked(a.RefreshCurrentItem)
|
||||||
|
a.ui.dataInsertBtn.OnClicked(a.OnDataInsertClick)
|
||||||
|
a.ui.dataDelRowBtn.OnClicked(a.OnDataDeleteRowClick)
|
||||||
|
a.ui.dataCommitBtn.OnClicked(a.OnDataCommitClick)
|
||||||
|
|
||||||
|
// contentBox: set editable
|
||||||
|
vcl_clear_grid(a.ui.contentBox)
|
||||||
|
a.ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
a.ui.contentBox.SetVerticalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
a.ui.contentBox.OnCellChanged(a.OnDataCellEdited)
|
||||||
|
|
||||||
|
// a.ui.queryInput.OnTextChanged(a.OnQueryTextChanged) // apply syntax highlighting
|
||||||
|
|
||||||
|
a.ui.queryExecBtn.OnClicked(a.OnQueryExecute)
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
a.ui.queryInput.SetFontFamily("Consolas")
|
||||||
|
} else {
|
||||||
|
a.ui.queryInput.SetFontFamily("monospace")
|
||||||
|
}
|
||||||
|
|
||||||
|
vcl_clear_grid(a.ui.queryResult)
|
||||||
|
a.ui.queryResult.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
a.ui.queryResult.SetVerticalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
|
||||||
|
a.none = &noLoadedDatabase{}
|
||||||
|
a.OnNavChange(nil, nil) // calls f.none.RenderForNav and sets up status bar content
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
vcl.RunApp(&mainForm)
|
qt.NewQApplication(os.Args)
|
||||||
|
|
||||||
|
sort.Slice(registeredDatabases, func(i, j int) bool {
|
||||||
|
return registeredDatabases[i].label < registeredDatabases[j].label
|
||||||
|
}) // might not have been done yet
|
||||||
|
|
||||||
|
app := newApp()
|
||||||
|
app.ui.MainWindow.Show()
|
||||||
|
|
||||||
|
qt.QApplication_Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
func (f *App) OnMnuFileExitClick() {
|
||||||
f.ImageList = loadImages(f)
|
f.ui.MainWindow.Close()
|
||||||
|
|
||||||
f.SetCaption("yvbolt")
|
|
||||||
f.ImageList.GetIcon(imgDatabaseLightning, f.Icon())
|
|
||||||
|
|
||||||
mnuFile := vcl.NewMenuItem(f)
|
|
||||||
mnuFile.SetCaption("File")
|
|
||||||
|
|
||||||
mnuFileOpen := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuFileOpen.SetCaption("Open Bolt database...")
|
|
||||||
mnuFileOpen.SetImageIndex(imgDatabaseAdd)
|
|
||||||
mnuFileOpen.SetShortCutFromString("Ctrl+O")
|
|
||||||
mnuFileOpen.SetOnClick(f.OnMnuFileOpenClick)
|
|
||||||
mnuFile.Add(mnuFileOpen)
|
|
||||||
|
|
||||||
mnuFileSqliteOpen := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuFileSqliteOpen.SetCaption("Open SQLite database...")
|
|
||||||
mnuFileSqliteOpen.SetImageIndex(imgDatabaseAdd)
|
|
||||||
mnuFileSqliteOpen.SetOnClick(f.OnMnuFileSqliteOpenClick)
|
|
||||||
mnuFile.Add(mnuFileSqliteOpen)
|
|
||||||
|
|
||||||
mnuFileBadgerOpen := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuFileBadgerOpen.SetCaption("Open Badger v4 database...")
|
|
||||||
mnuFileBadgerOpen.SetImageIndex(imgDatabaseAdd)
|
|
||||||
mnuFileBadgerOpen.SetOnClick(f.OnMnuFileBadgerOpenClick)
|
|
||||||
mnuFile.Add(mnuFileBadgerOpen)
|
|
||||||
|
|
||||||
mnuFileSqliteMemory := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuFileSqliteMemory.SetCaption("New SQLite in-memory database")
|
|
||||||
mnuFileSqliteMemory.SetImageIndex(imgDatabaseAdd)
|
|
||||||
mnuFileSqliteMemory.SetOnClick(f.OnMnuFileSqliteMemoryClick)
|
|
||||||
mnuFile.Add(mnuFileSqliteMemory)
|
|
||||||
|
|
||||||
mnuSep := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuSep.SetCaption("-") // Creates separator
|
|
||||||
mnuFile.Add(mnuSep)
|
|
||||||
|
|
||||||
mnuFileExit := vcl.NewMenuItem(mnuFile)
|
|
||||||
mnuFileExit.SetCaption("Exit")
|
|
||||||
mnuFileExit.SetOnClick(f.OnMnuFileExitClick)
|
|
||||||
mnuFile.Add(mnuFileExit)
|
|
||||||
|
|
||||||
mnuQuery := vcl.NewMenuItem(f)
|
|
||||||
mnuQuery.SetCaption("Query")
|
|
||||||
|
|
||||||
mnuQueryExecute := vcl.NewMenuItem(mnuQuery)
|
|
||||||
mnuQueryExecute.SetCaption("Execute")
|
|
||||||
mnuQueryExecute.SetShortCutFromString("F5")
|
|
||||||
mnuQueryExecute.SetOnClick(f.OnQueryExecute)
|
|
||||||
mnuQueryExecute.SetImageIndex(imgLightning)
|
|
||||||
mnuQuery.Add(mnuQueryExecute)
|
|
||||||
|
|
||||||
f.Menu = vcl.NewMainMenu(f)
|
|
||||||
f.Menu.SetImages(f.ImageList)
|
|
||||||
f.Menu.Items().Add(mnuFile)
|
|
||||||
f.Menu.Items().Add(mnuQuery)
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
f.StatusBar = vcl.NewStatusBar(f)
|
|
||||||
f.StatusBar.SetParent(f)
|
|
||||||
f.StatusBar.SetSimpleText("")
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
f.Buckets = vcl.NewTreeView(f)
|
|
||||||
f.Buckets.SetParent(f)
|
|
||||||
f.Buckets.SetImages(f.ImageList)
|
|
||||||
f.Buckets.SetAlign(types.AlLeft)
|
|
||||||
f.Buckets.SetWidth(MY_WIDTH)
|
|
||||||
f.Buckets.SetReadOnly(true) // prevent click to rename on nodes
|
|
||||||
f.Buckets.SetOnExpanding(f.OnNavExpanding)
|
|
||||||
f.Buckets.SetOnChange(f.OnNavChange)
|
|
||||||
|
|
||||||
hsplit := vcl.NewSplitter(f)
|
|
||||||
hsplit.SetParent(f)
|
|
||||||
hsplit.SetAlign(types.AlLeft)
|
|
||||||
hsplit.SetLeft(1) // Just needs to be further "over" than f.Buckets for auto-alignment
|
|
||||||
|
|
||||||
f.Tabs = vcl.NewPageControl(f)
|
|
||||||
f.Tabs.SetParent(f)
|
|
||||||
f.Tabs.SetAlign(types.AlClient) // fill remaining space
|
|
||||||
f.Tabs.SetImages(f.ImageList)
|
|
||||||
|
|
||||||
propertiesTab := vcl.NewTabSheet(f.Tabs)
|
|
||||||
propertiesTab.SetParent(f.Tabs)
|
|
||||||
propertiesTab.SetCaption("Properties")
|
|
||||||
propertiesTab.SetImageIndex(imgChartBar)
|
|
||||||
|
|
||||||
f.propertiesBox = vcl.NewMemo(propertiesTab)
|
|
||||||
f.propertiesBox.SetParent(propertiesTab)
|
|
||||||
f.propertiesBox.BorderSpacing().SetAround(MY_SPACING)
|
|
||||||
f.propertiesBox.SetAlign(types.AlClient) // fill remaining space
|
|
||||||
f.propertiesBox.SetReadOnly(true)
|
|
||||||
f.propertiesBox.SetEnabled(false)
|
|
||||||
f.propertiesBox.SetBorderStyle(types.BsNone)
|
|
||||||
f.propertiesBox.SetText("Open a database to get started...")
|
|
||||||
|
|
||||||
dataTab := vcl.NewTabSheet(f.Tabs)
|
|
||||||
dataTab.SetParent(f.Tabs)
|
|
||||||
dataTab.SetCaption("Data")
|
|
||||||
dataTab.SetImageIndex(imgTable)
|
|
||||||
|
|
||||||
f.contentBox = vcl.NewListView(dataTab)
|
|
||||||
f.contentBox.SetParent(dataTab)
|
|
||||||
f.contentBox.BorderSpacing().SetAround(MY_SPACING)
|
|
||||||
f.contentBox.SetAlign(types.AlClient) // fill remaining space
|
|
||||||
f.contentBox.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
|
||||||
f.contentBox.SetAutoWidthLastColumn(true)
|
|
||||||
f.contentBox.SetReadOnly(true)
|
|
||||||
f.contentBox.Columns().Clear()
|
|
||||||
|
|
||||||
queryTab := vcl.NewTabSheet(f.Tabs)
|
|
||||||
queryTab.SetParent(f.Tabs)
|
|
||||||
queryTab.SetCaption("Query")
|
|
||||||
queryTab.SetImageIndex(imgLightning)
|
|
||||||
|
|
||||||
queryButtonBar := vcl.NewToolBar(queryTab)
|
|
||||||
queryButtonBar.SetParent(queryTab)
|
|
||||||
queryButtonBar.SetAlign(types.AlTop)
|
|
||||||
queryButtonBar.BorderSpacing().SetLeft(MY_SPACING)
|
|
||||||
queryButtonBar.BorderSpacing().SetTop(MY_SPACING)
|
|
||||||
queryButtonBar.BorderSpacing().SetBottom(0)
|
|
||||||
queryButtonBar.BorderSpacing().SetRight(MY_SPACING)
|
|
||||||
queryButtonBar.SetImages(f.ImageList)
|
|
||||||
queryButtonBar.SetShowCaptions(true)
|
|
||||||
|
|
||||||
queryExecBtn := vcl.NewToolButton(queryButtonBar)
|
|
||||||
queryExecBtn.SetParent(queryButtonBar)
|
|
||||||
queryExecBtn.SetCaption("Execute")
|
|
||||||
// queryExecBtn.SetImageIndex(imgLightning)
|
|
||||||
queryExecBtn.SetOnClick(f.OnQueryExecute)
|
|
||||||
|
|
||||||
f.queryInput = vcl.NewMemo(queryTab)
|
|
||||||
f.queryInput.SetParent(queryTab)
|
|
||||||
f.queryInput.SetHeight(MY_HEIGHT)
|
|
||||||
f.queryInput.SetAlign(types.AlTop)
|
|
||||||
f.queryInput.SetTop(1)
|
|
||||||
f.queryInput.Font().SetName("monospace")
|
|
||||||
f.queryInput.BorderSpacing().SetLeft(MY_SPACING)
|
|
||||||
f.queryInput.BorderSpacing().SetTop(0)
|
|
||||||
f.queryInput.BorderSpacing().SetRight(MY_SPACING)
|
|
||||||
|
|
||||||
vsplit := vcl.NewSplitter(queryTab)
|
|
||||||
vsplit.SetParent(queryTab)
|
|
||||||
vsplit.SetAlign(types.AlTop)
|
|
||||||
vsplit.SetTop(2)
|
|
||||||
|
|
||||||
f.queryResult = vcl.NewListView(queryTab)
|
|
||||||
f.queryResult.SetParent(queryTab)
|
|
||||||
f.queryResult.SetAlign(types.AlClient) // fill remaining space
|
|
||||||
f.queryResult.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
|
||||||
f.queryResult.SetAutoWidthLastColumn(true)
|
|
||||||
f.queryResult.SetReadOnly(true)
|
|
||||||
f.queryResult.Columns().Clear()
|
|
||||||
f.queryResult.BorderSpacing().SetLeft(MY_SPACING)
|
|
||||||
f.queryResult.BorderSpacing().SetRight(MY_SPACING)
|
|
||||||
f.queryResult.BorderSpacing().SetBottom(MY_SPACING)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileOpenClick(sender vcl.IObject) {
|
func (f *App) OnMnuHelpHomepage() {
|
||||||
dlg := vcl.NewOpenDialog(f)
|
url := qt.NewQUrl3(HOMEPAGE_URL)
|
||||||
dlg.SetTitle("Select a database file...")
|
ok := qt.QDesktopServices_OpenUrl(url)
|
||||||
dlg.SetFilter("Bolt database|*.db|All files|*.*")
|
url.Delete()
|
||||||
ret := dlg.Execute() // Fake blocking
|
|
||||||
if ret {
|
if !ok {
|
||||||
f.boltAddDatabaseFromFile(dlg.FileName())
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, "Error opening browser")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileSqliteOpenClick(sender vcl.IObject) {
|
func (f *App) OnMenuHelpVersion() {
|
||||||
dlg := vcl.NewOpenDialog(f)
|
|
||||||
dlg.SetTitle("Select a database file...")
|
|
||||||
dlg.SetFilter("SQLite database|*.db;*.db3;*.sqlite;*.sqlite3|All files|*.*")
|
|
||||||
ret := dlg.Execute() // Fake blocking
|
|
||||||
if ret {
|
|
||||||
f.sqliteAddDatabaseFromFile(dlg.FileName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileBadgerOpenClick(sender vcl.IObject) {
|
bi, ok := debug.ReadBuildInfo()
|
||||||
dlg := vcl.NewSelectDirectoryDialog(f)
|
if !ok {
|
||||||
dlg.SetTitle("Select a database directory...")
|
|
||||||
ret := dlg.Execute() // Fake blocking
|
|
||||||
if ret {
|
|
||||||
f.badgerAddDatabaseFromDirectory(dlg.FileName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileSqliteMemoryClick(sender vcl.IObject) {
|
|
||||||
f.sqliteAddDatabaseFromFile(`:memory:`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileExitClick(sender vcl.IObject) {
|
|
||||||
f.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
|
||||||
// If query tab is not selected, switch to it, but do not exec
|
|
||||||
if f.Tabs.ActivePageIndex() != 2 {
|
|
||||||
f.Tabs.SetActivePageIndex(2)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info := "This version of " + APPNAME + " was compiled with:\n\n"
|
||||||
|
for _, dep := range bi.Deps {
|
||||||
|
|
||||||
|
// Filter to only interesting things
|
||||||
|
switch dep.Path {
|
||||||
|
case `github.com/cockroachdb/pebble`,
|
||||||
|
`github.com/dgraph-io/badger/v4`,
|
||||||
|
`github.com/mattn/go-sqlite3`,
|
||||||
|
`github.com/redis/go-redis/v9`,
|
||||||
|
`go.etcd.io/bbolt`,
|
||||||
|
`modernc.org/sqlite`:
|
||||||
|
info += fmt.Sprintf("- %s %s\n", dep.Path, dep.Version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qt.QMessageBox_About(f.ui.MainWindow.QWidget, APPNAME, info)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnNavContextPopup(pos *qt.QPoint) {
|
||||||
|
|
||||||
|
curItem := f.ui.Buckets.ItemAt(pos) // f.ui.Buckets.Selected()
|
||||||
|
if curItem == nil {
|
||||||
|
// Nothing is selected at all
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bucketPath, err := f.getBucketPathFor(curItem)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ld := f.getLoadedDatabaseFor(curItem)
|
||||||
|
|
||||||
|
mnu := qt.NewQMenu2()
|
||||||
|
|
||||||
|
mnuRefresh := mnu.AddAction2(qt.NewQIcon4(`:/assets/arrow_refresh.png`), "Refresh")
|
||||||
|
mnuRefresh.OnTriggered(func() { f.OnNavContextRefresh(curItem) })
|
||||||
|
|
||||||
|
// Check what custom actions the ndata->db itself wants to add
|
||||||
|
actions, err := ld.NavContext(bucketPath)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(actions) > 0 {
|
||||||
|
mnu.AddSeparator()
|
||||||
|
|
||||||
|
for _, action := range actions {
|
||||||
|
cb := action.Callback // Copy to avoid reuse of loop variable
|
||||||
|
|
||||||
|
mnuAction := mnu.AddActionWithText(action.Name)
|
||||||
|
mnuAction.OnTriggered(func() {
|
||||||
|
err := cb(curItem, bucketPath)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
}
|
||||||
|
f.OnNavContextRefresh(curItem)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if curItem.Parent() == nil {
|
||||||
|
// Top-level item (database connection). Allow closing by right-click.
|
||||||
|
mnu.AddSeparator()
|
||||||
|
|
||||||
|
mnuClose := mnu.AddAction2(qt.NewQIcon4(`:/assets/database_delete.png`), "Close")
|
||||||
|
mnuClose.OnTriggered(f.OnNavContextClose)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show popup
|
||||||
|
globalPos := f.ui.Buckets.MapToGlobalWithQPoint(pos)
|
||||||
|
mnu.Popup(globalPos)
|
||||||
|
mnu.SetAttribute2(qt.WA_DeleteOnClose, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) RefreshCurrentItem() {
|
||||||
|
curItem := f.ui.Buckets.CurrentItem()
|
||||||
|
if curItem == nil {
|
||||||
|
return // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there were any edited rows, refreshing will lose them
|
||||||
|
// Prompt for confirmation first
|
||||||
|
// FIXME this should also trigger when changing selection on LHS nav??
|
||||||
|
if len(f.deleteRows) > 0 || len(f.updateRows) > 0 || len(f.deleteRows) > 0 {
|
||||||
|
ok := qt.QMessageBox_Warning2(f.ui.MainWindow.QWidget, APPNAME, "Your modifications have not been applied. Continue without applying?", qt.QMessageBox__Ok, qt.QMessageBox__Cancel)
|
||||||
|
if ok != int(qt.QMessageBox__Ok) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.OnNavContextRefresh(curItem) // Refresh LHS pane/children
|
||||||
|
f.OnNavChange(curItem, curItem) // Refresh RHS pane/data content
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnNavContextRefresh(item *qt.QTreeWidgetItem) {
|
||||||
|
isExpanded := item.IsExpanded()
|
||||||
|
|
||||||
|
// Reset nav node to 'unloaded' state
|
||||||
|
item.SetExpanded(false)
|
||||||
|
children := item.TakeChildren()
|
||||||
|
for _, child := range children {
|
||||||
|
child.Delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up with fake children again
|
||||||
|
item.SetChildIndicatorPolicy(qt.QTreeWidgetItem__ShowIndicator) // dynamically populate in OnNavExpanding
|
||||||
|
|
||||||
|
// Trigger a virtual reload
|
||||||
|
// Calls OnNavExpanding to dynamically detect children
|
||||||
|
|
||||||
|
f.OnNavExpanding(item)
|
||||||
|
|
||||||
|
// Restore previous gui state
|
||||||
|
item.SetExpanded(isExpanded)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnDataCellEdited(aRow, aCol int) {
|
||||||
|
|
||||||
|
if !f.isEditing {
|
||||||
|
return // current in full table refresh, this signal is not a true edit
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is an insert row, no need to patch updateRows
|
||||||
|
if _, ok := f.insertRows[aRow]; ok {
|
||||||
|
return // nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
if chk, ok := f.updateRows[aRow]; ok {
|
||||||
|
if slice_contains(chk, aCol) {
|
||||||
|
// nothing to do
|
||||||
|
} else {
|
||||||
|
chk = append(chk, aCol)
|
||||||
|
f.updateRows[aRow] = chk
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f.updateRows[aRow] = []int{aCol}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this row was marked for deletion, this new edit takes priority
|
||||||
|
delete(f.deleteRows, aRow)
|
||||||
|
|
||||||
|
// Recolour the row
|
||||||
|
explicitCol := qt.NewQBrush4(CO_EDIT_EXPLICIT)
|
||||||
|
implicitCol := qt.NewQBrush4(CO_EDIT_IMPLICIT)
|
||||||
|
|
||||||
|
numCols := f.ui.contentBox.ColumnCount()
|
||||||
|
for i := 0; i < numCols; i++ {
|
||||||
|
cell := f.ui.contentBox.Item(aRow, i)
|
||||||
|
|
||||||
|
if i == aCol {
|
||||||
|
cell.SetBackground(explicitCol)
|
||||||
|
} else {
|
||||||
|
cell.SetBackground(implicitCol) // FIXME preserve explicitCol for other changed cells too!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnDataInsertClick() {
|
||||||
|
if !f.ui.contentBox.IsEnabled() {
|
||||||
|
return // Not an active data view
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := f.ui.contentBox.RowCount()
|
||||||
|
f.ui.contentBox.SetRowCount(rpos + 1)
|
||||||
|
|
||||||
|
f.insertRows[rpos] = struct{}{}
|
||||||
|
|
||||||
|
// Create the cells, so they're not nil when we try and set the bgcolor
|
||||||
|
colCt := f.ui.contentBox.ColumnCount()
|
||||||
|
for i := 0; i < colCt; i++ {
|
||||||
|
f.ui.contentBox.SetItem(rpos, i, qt.NewQTableWidgetItem())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repaint cells
|
||||||
|
vcl_grid_set_row_colour(f.ui.contentBox, rpos, qt.NewQBrush4(CO_INSERT))
|
||||||
|
|
||||||
|
// Scroll to bottom
|
||||||
|
f.ui.contentBox.ScrollToBottom()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnDataDeleteRowClick() {
|
||||||
|
if !f.ui.contentBox.IsEnabled() {
|
||||||
|
return // Not an active data view
|
||||||
|
}
|
||||||
|
|
||||||
|
rpos := f.ui.contentBox.CurrentRow()
|
||||||
|
f.deleteRows[rpos] = struct{}{}
|
||||||
|
|
||||||
|
// If this row was marked for edit, this takes priority
|
||||||
|
delete(f.updateRows, rpos)
|
||||||
|
|
||||||
|
// Repaint cells
|
||||||
|
vcl_grid_set_row_colour(f.ui.contentBox, rpos, qt.NewQBrush4(CO_DELETE))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnDataCommitClick() {
|
||||||
|
if !f.ui.contentBox.IsEnabled() {
|
||||||
|
return // Not an active data view
|
||||||
|
}
|
||||||
|
|
||||||
|
node := f.ui.Buckets.CurrentItem()
|
||||||
|
if node == nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, "No database selected")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ld := f.getLoadedDatabaseFor(node)
|
||||||
|
editableLd, ok := ld.(editableLoadedDatabase)
|
||||||
|
if !ok {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, "Unsupported action for this database")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bucketPath, err := f.getBucketPathFor(node)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = editableLd.ApplyChanges(f, bucketPath)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh content
|
||||||
|
f.OnNavChange(node, node) // Refresh RHS pane/data content
|
||||||
|
|
||||||
|
// Preserve scroll position
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnNavContextClose() {
|
||||||
|
curItem := f.ui.Buckets.CurrentItem()
|
||||||
|
if curItem == nil {
|
||||||
|
return // Nothing selected (shouldn't happen)
|
||||||
|
}
|
||||||
|
if curItem.Parent() != nil {
|
||||||
|
return // Selection is not top-level DB connection (shouldn't happen)
|
||||||
|
}
|
||||||
|
|
||||||
|
ldID := curItem.Data(0, LoadedDatabaseIdRole).ToInt()
|
||||||
|
ld := f.dbs[ldID]
|
||||||
|
|
||||||
|
ld.Close()
|
||||||
|
curItem.Delete() // n.b. This triggers OnNavChange, which will then re-render from noLoadedDatabase{}
|
||||||
|
|
||||||
|
// We can also nil-out the entry in our .db array so Go can GC everything else
|
||||||
|
// Keep the slot, though, just to avoid complexity
|
||||||
|
f.dbs[ldID] = nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (f *App) OnQueryTextChanged() {
|
||||||
|
|
||||||
|
// FIXME changing the text colour calls the onchange handler recursively
|
||||||
|
// FIXME changing the text colour pushes into the undo stack
|
||||||
|
|
||||||
|
// Preserve
|
||||||
|
f.ui.queryInput.Lines().BeginUpdate()
|
||||||
|
origPos := f.ui.queryInput.SelStart()
|
||||||
|
origLen := f.ui.queryInput.SelLength()
|
||||||
|
defer func() {
|
||||||
|
f.ui.queryInput.SetSelStart(origPos)
|
||||||
|
f.ui.queryInput.SetSelLength(origLen)
|
||||||
|
f.ui.queryInput.Lines().EndUpdate()
|
||||||
|
}()
|
||||||
|
|
||||||
|
tx := strings.ToLower(f.ui.queryInput.Text())
|
||||||
|
|
||||||
|
// Reset all existing colors
|
||||||
|
f.ui.queryInput.SetSelStart(0)
|
||||||
|
f.ui.queryInput.SetSelLength(int32(len(tx)))
|
||||||
|
f.ui.queryInput.SelAttributes().SetColor(colors.ClBlack)
|
||||||
|
|
||||||
|
searchPos := 0
|
||||||
|
for {
|
||||||
|
matchPos := strings.Index(tx[searchPos:], "select")
|
||||||
|
if matchPos == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
matchPos += searchPos // compensate for slicing
|
||||||
|
|
||||||
|
f.ui.queryInput.SetSelStart(int32(matchPos))
|
||||||
|
f.ui.queryInput.SetSelLength(6)
|
||||||
|
f.ui.queryInput.SelAttributes().SetColor(colors.ClRed)
|
||||||
|
|
||||||
|
searchPos = matchPos + 6 // strlen(SELECT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (f *App) OnQueryExecute() {
|
||||||
|
// If query tab is not selected, switch to it, but do not exec
|
||||||
|
if f.ui.tabWidget.CurrentIndex() != 2 {
|
||||||
|
f.ui.tabWidget.SetCurrentIndex(2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString := f.ui.queryInput.ToPlainText()
|
||||||
|
|
||||||
|
if selectedText := f.ui.queryInput.TextCursor().SelectedText(); len(selectedText) > 0 {
|
||||||
|
queryString = selectedText // Just the selected text
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(queryString) == "" {
|
||||||
|
return // prevent blank query
|
||||||
|
}
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
node := f.Buckets.Selected()
|
node := f.ui.Buckets.CurrentItem()
|
||||||
if node == nil {
|
if node == nil {
|
||||||
vcl.ShowMessage("No database selected")
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, "No database selected")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ndata := (*navData)(node.Data())
|
ld := f.getLoadedDatabaseFor(node)
|
||||||
ndata.ld.ExecQuery(f.queryInput.Text(), f.queryResult)
|
|
||||||
|
queryableLd, ok := ld.(queryableLoadedDatabase)
|
||||||
|
if !ok {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, "Unsupported action for this database")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := queryableLd.ExecQuery(queryString, f.ui.queryResult)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnNavChange(sender vcl.IObject, node *vcl.TTreeNode) {
|
func (f *App) OnNavChange(node *qt.QTreeWidgetItem, _ *qt.QTreeWidgetItem) {
|
||||||
|
|
||||||
if node.Data() == nil {
|
var ld loadedDatabase = f.none
|
||||||
vcl.ShowMessage("unexpected nil data")
|
var bucketPath []string = nil
|
||||||
return
|
|
||||||
|
if node != nil {
|
||||||
|
ld = f.getLoadedDatabaseFor(node)
|
||||||
|
bucketPath, _ = f.getBucketPathFor(node) // FIXME suppressing error
|
||||||
}
|
}
|
||||||
|
|
||||||
ndata := (*navData)(node.Data())
|
// Reset some controls that the render function is expected to populate
|
||||||
|
f.insertRows = make(map[int]struct{})
|
||||||
|
f.updateRows = make(map[int][]int)
|
||||||
|
f.deleteRows = make(map[int]struct{})
|
||||||
|
f.isEditing = false
|
||||||
|
f.ui.propertiesBox.Clear()
|
||||||
|
vcl_clear_grid(f.ui.contentBox)
|
||||||
|
|
||||||
ndata.ld.RenderForNav(f, ndata) // Handover to the database type's own renderer function
|
err := ld.RenderForNav(f.ui, bucketPath) // Handover to the database type's own renderer function
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
|
||||||
|
// Ensure elements are disabled
|
||||||
|
f.ui.contentBox.SetEnabled(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle the Edit functionality
|
||||||
|
_, ok := ld.(editableLoadedDatabase)
|
||||||
|
f.ui.dataCommitBtn.SetEnabled(ok)
|
||||||
|
f.ui.dataDelRowBtn.SetEnabled(ok)
|
||||||
|
f.ui.dataInsertBtn.SetEnabled(ok)
|
||||||
|
f.isEditing = ok
|
||||||
|
|
||||||
|
// Toggle the Query functionality
|
||||||
|
_, ok = ld.(queryableLoadedDatabase)
|
||||||
|
f.ui.queryInput.SetEnabled(ok)
|
||||||
|
f.ui.queryResult.SetEnabled(ok)
|
||||||
|
f.ui.queryExecBtn.SetEnabled(ok)
|
||||||
|
|
||||||
// We're in charge of common status bar text updates
|
// We're in charge of common status bar text updates
|
||||||
f.StatusBar.SetSimpleText(ndata.ld.DisplayName() + " | " + ndata.ld.DriverName())
|
// Find database displayname
|
||||||
|
f.ui.MainWindow.StatusBar().ShowMessage(f.DatabaseDisplayName(node) + " | " + ld.DriverName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnNavExpanding(sender vcl.IObject, node *vcl.TTreeNode, allowExpansion *bool) {
|
func (f *App) DatabaseDisplayName(item *qt.QTreeWidgetItem) string {
|
||||||
|
if item == nil {
|
||||||
if node.Data() == nil {
|
return ""
|
||||||
vcl.ShowMessage("unexpected nil data")
|
|
||||||
*allowExpansion = false
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ndata := (*navData)(node.Data())
|
// The database displayname is the text content from the topmost parent of this item
|
||||||
|
for {
|
||||||
if ndata.childrenLoaded {
|
parent := item.Parent()
|
||||||
return
|
if parent == nil {
|
||||||
}
|
break
|
||||||
|
|
||||||
// Find the child buckets from this point under the element
|
|
||||||
nextBucketNames, err := ndata.ld.NavChildren(ndata)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to find child buckets under %q: %s", strings.Join(ndata.bucketPath, `/`), err.Error()))
|
|
||||||
*allowExpansion = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ndata.childrenLoaded = true // don't repeat this work
|
|
||||||
|
|
||||||
if len(nextBucketNames) == 0 {
|
|
||||||
node.SetHasChildren(false)
|
|
||||||
*allowExpansion = false
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Populate LCL child nodes
|
|
||||||
for _, bucketName := range nextBucketNames {
|
|
||||||
|
|
||||||
node := f.Buckets.Items().AddChild(node, formatUtf8([]byte(bucketName)))
|
|
||||||
node.SetHasChildren(true) // dynamically populate in OnNavExpanding
|
|
||||||
node.SetImageIndex(imgTable)
|
|
||||||
node.SetSelectedIndex(imgTable)
|
|
||||||
navData := &navData{
|
|
||||||
ld: ndata.ld,
|
|
||||||
childrenLoaded: false, // will be loaded dynamically
|
|
||||||
bucketPath: []string{}, // empty = root
|
|
||||||
}
|
|
||||||
navData.bucketPath = append(navData.bucketPath, ndata.bucketPath...)
|
|
||||||
navData.bucketPath = append(navData.bucketPath, bucketName)
|
|
||||||
node.SetData(unsafe.Pointer(navData))
|
|
||||||
|
|
||||||
ndata.ld.Keepalive(navData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*allowExpansion = true
|
item = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item.Text(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) OnNavExpanding(item *qt.QTreeWidgetItem) {
|
||||||
|
|
||||||
|
if item.ChildCount() > 0 {
|
||||||
|
// We've already virtual-expanded this item once, don't repeat it
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bucketPath, err := f.getBucketPathFor(item)
|
||||||
|
if err != nil {
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.NavLoadChildren(item, bucketPath)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
if errors.Is(err, ErrNavNotExist) {
|
||||||
|
// The nav entry has been deleted.
|
||||||
|
// This is a normal thing to happen when e.g. deleting a table
|
||||||
|
// f.StatusBar.SetSimpleText(err.Error()) // Just gets overridden when the selection changes
|
||||||
|
item.Delete()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
|
||||||
|
item.SetChildIndicatorPolicy(qt.QTreeWidgetItem__DontShowIndicatorWhenChildless) // disable dynamic-expansion in future
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// While we're here - preload one single level deep (not any deeper)
|
||||||
|
// This makes it "seem" like we don't have empty virtual subfolders most of the time
|
||||||
|
|
||||||
|
childCt := item.ChildCount()
|
||||||
|
for i := 0; i < childCt; i++ {
|
||||||
|
|
||||||
|
cc := item.Child(i)
|
||||||
|
f.OnNavExpanding(cc)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
LoadedDatabaseIdRole = int(qt.UserRole + 100)
|
||||||
|
BucketPathStringRole = int(qt.UserRole + 101)
|
||||||
|
DataPrimaryKeyRole = int(qt.UserRole + 102) // sqlite
|
||||||
|
)
|
||||||
|
|
||||||
|
// getLoadedDatabaseFor gets the ld ptr out of a child nav item.
|
||||||
|
func (f *App) getLoadedDatabaseFor(item *qt.QTreeWidgetItem) loadedDatabase {
|
||||||
|
ldID := item.Data(0, LoadedDatabaseIdRole).ToInt()
|
||||||
|
return f.dbs[ldID]
|
||||||
|
}
|
||||||
|
|
||||||
|
// getBucketPathFor gets the bucketPath array out of a child nav item.
|
||||||
|
func (f *App) getBucketPathFor(item *qt.QTreeWidgetItem) ([]string, error) {
|
||||||
|
bucketPathJsonArr := item.Data(0, BucketPathStringRole).ToString()
|
||||||
|
|
||||||
|
var ret []string
|
||||||
|
err := json.Unmarshal([]byte(bucketPathJsonArr), &ret)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) NavLoadChildren(item *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
|
||||||
|
ldID := item.Data(0, LoadedDatabaseIdRole).ToInt()
|
||||||
|
ld := f.dbs[ldID]
|
||||||
|
|
||||||
|
// Find the child buckets from this point under the element
|
||||||
|
nextBucketNames, err := ld.NavChildren(bucketPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to find child buckets under %q: %w", strings.Join(bucketPath, `/`), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
item.SetChildIndicatorPolicy(qt.QTreeWidgetItem__DontShowIndicatorWhenChildless) // n.b. maybe childless
|
||||||
|
|
||||||
|
// Populate child nodes
|
||||||
|
for _, bucketName := range nextBucketNames {
|
||||||
|
|
||||||
|
node := qt.NewQTreeWidgetItem()
|
||||||
|
node.SetText(0, formatUtf8([]byte(bucketName)))
|
||||||
|
node.SetIcon(0, qt.NewQIcon4(`:/assets/table.png`))
|
||||||
|
node.SetChildIndicatorPolicy(qt.QTreeWidgetItem__ShowIndicator) // dynamically populate in OnNavExpanding
|
||||||
|
|
||||||
|
childPath := make([]string, 0, len(bucketPath)+1)
|
||||||
|
childPath = append(childPath, bucketPath...)
|
||||||
|
childPath = append(childPath, bucketName)
|
||||||
|
|
||||||
|
childPathJson, _ := json.Marshal(childPath)
|
||||||
|
|
||||||
|
node.SetData(0, LoadedDatabaseIdRole, qt.NewQVariant4(ldID))
|
||||||
|
node.SetData(0, BucketPathStringRole, qt.NewQVariant11(string(childPathJson)))
|
||||||
|
|
||||||
|
item.AddChild(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *App) addTopLevelDatabaseConnection(ld loadedDatabase, displayName string) {
|
||||||
|
|
||||||
|
nav := qt.NewQTreeWidgetItem()
|
||||||
|
nav.SetText(0, displayName)
|
||||||
|
nav.SetChildIndicatorPolicy(qt.QTreeWidgetItem__ShowIndicator) // dynamically populate in OnNavExpanding
|
||||||
|
nav.SetIcon(0, qt.NewQIcon4(`:/assets/database.png`))
|
||||||
|
|
||||||
|
// Keepalive for the *ld pointer itself
|
||||||
|
ldID := f.dbs_next
|
||||||
|
f.dbs_next++
|
||||||
|
f.dbs[ldID] = ld
|
||||||
|
|
||||||
|
nav.SetData(0, LoadedDatabaseIdRole, qt.NewQVariant4(ldID))
|
||||||
|
nav.SetData(0, BucketPathStringRole, qt.NewQVariant11(`[]`)) // empty array
|
||||||
|
|
||||||
|
f.ui.Buckets.AddTopLevelItem(nav)
|
||||||
|
f.ui.Buckets.SetCurrentItem(nav) // Select new element
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
446
mainwindow.go
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
// Generated by miqt-uic. To update this file, edit the .ui file in
|
||||||
|
// Qt Designer, and then run 'go generate'.
|
||||||
|
//
|
||||||
|
//go:generate miqt-uic -InFile mainwindow.ui -OutFile mainwindow.go -Qt6
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MainWindowUi struct {
|
||||||
|
MainWindow *qt.QMainWindow
|
||||||
|
centralwidget *qt.QWidget
|
||||||
|
gridLayout *qt.QGridLayout
|
||||||
|
splitter *qt.QSplitter
|
||||||
|
Buckets *qt.QTreeWidget
|
||||||
|
tabWidget *qt.QTabWidget
|
||||||
|
tabProperties *qt.QWidget
|
||||||
|
gridLayout_2 *qt.QGridLayout
|
||||||
|
propertiesBox *qt.QTextEdit
|
||||||
|
tabData *qt.QWidget
|
||||||
|
verticalLayout *qt.QVBoxLayout
|
||||||
|
horizontalLayout *qt.QHBoxLayout
|
||||||
|
dataRefreshBtn *qt.QToolButton
|
||||||
|
dataInsertBtn *qt.QToolButton
|
||||||
|
dataDelRowBtn *qt.QToolButton
|
||||||
|
dataCommitBtn *qt.QToolButton
|
||||||
|
horizontalSpacer *qt.QSpacerItem
|
||||||
|
contentBox *qt.QTableWidget
|
||||||
|
tabQuery *qt.QWidget
|
||||||
|
verticalLayout_2 *qt.QVBoxLayout
|
||||||
|
horizontalLayout_2 *qt.QHBoxLayout
|
||||||
|
queryExecBtn *qt.QToolButton
|
||||||
|
horizontalSpacer_2 *qt.QSpacerItem
|
||||||
|
splitter_2 *qt.QSplitter
|
||||||
|
queryInput *qt.QTextEdit
|
||||||
|
queryResult *qt.QTableWidget
|
||||||
|
menubar *qt.QMenuBar
|
||||||
|
menu_File *qt.QMenu
|
||||||
|
menu_Query *qt.QMenu
|
||||||
|
menu_Help *qt.QMenu
|
||||||
|
statusbar *qt.QStatusBar
|
||||||
|
actionE_xit *qt.QAction
|
||||||
|
mnuBadgerOpen *qt.QAction
|
||||||
|
mnuBadgerNewInMemory *qt.QAction
|
||||||
|
mnuBoltNew *qt.QAction
|
||||||
|
mnuBoltOpenDatabase *qt.QAction
|
||||||
|
mnuBoltOpenDatabaseReadonly *qt.QAction
|
||||||
|
mnuDebconfOpen *qt.QAction
|
||||||
|
mnuPebbleOpenDatabase *qt.QAction
|
||||||
|
mnuPebbleNewInMemory *qt.QAction
|
||||||
|
mnuRedisConnect *qt.QAction
|
||||||
|
mnuSqliteOpenDatabase *qt.QAction
|
||||||
|
mnuSqliteNewInMemory *qt.QAction
|
||||||
|
mnuSqliteExperimentalDriver *qt.QAction
|
||||||
|
mnuExecute *qt.QAction
|
||||||
|
mnuDriverVersions *qt.QAction
|
||||||
|
mnuHelpAbout *qt.QAction
|
||||||
|
actionConnect *qt.QAction
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMainWindowUi creates all Qt widget classes for MainWindow.
|
||||||
|
func NewMainWindowUi() *MainWindowUi {
|
||||||
|
ui := &MainWindowUi{}
|
||||||
|
ui.MainWindow = qt.NewQMainWindow(nil)
|
||||||
|
MainWindow__objectName := qt.NewQAnyStringView3("MainWindow")
|
||||||
|
ui.MainWindow.SetObjectName(*MainWindow__objectName)
|
||||||
|
MainWindow__objectName.Delete() // setter copied value
|
||||||
|
ui.MainWindow.Resize(1280, 640)
|
||||||
|
icon0 := qt.NewQIcon()
|
||||||
|
icon0.AddFile4(":/assets/database_lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.MainWindow.SetWindowIcon(icon0)
|
||||||
|
ui.actionE_xit = qt.NewQAction()
|
||||||
|
actionE_xit__objectName := qt.NewQAnyStringView3("actionE_xit")
|
||||||
|
ui.actionE_xit.SetObjectName(*actionE_xit__objectName)
|
||||||
|
actionE_xit__objectName.Delete() // setter copied value
|
||||||
|
ui.mnuBadgerOpen = qt.NewQAction()
|
||||||
|
mnuBadgerOpen__objectName := qt.NewQAnyStringView3("mnuBadgerOpen")
|
||||||
|
ui.mnuBadgerOpen.SetObjectName(*mnuBadgerOpen__objectName)
|
||||||
|
mnuBadgerOpen__objectName.Delete() // setter copied value
|
||||||
|
icon1 := qt.NewQIcon()
|
||||||
|
icon1.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuBadgerOpen.SetIcon(icon1)
|
||||||
|
ui.mnuBadgerNewInMemory = qt.NewQAction()
|
||||||
|
mnuBadgerNewInMemory__objectName := qt.NewQAnyStringView3("mnuBadgerNewInMemory")
|
||||||
|
ui.mnuBadgerNewInMemory.SetObjectName(*mnuBadgerNewInMemory__objectName)
|
||||||
|
mnuBadgerNewInMemory__objectName.Delete() // setter copied value
|
||||||
|
icon2 := qt.NewQIcon()
|
||||||
|
icon2.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuBadgerNewInMemory.SetIcon(icon2)
|
||||||
|
ui.mnuBoltNew = qt.NewQAction()
|
||||||
|
mnuBoltNew__objectName := qt.NewQAnyStringView3("mnuBoltNew")
|
||||||
|
ui.mnuBoltNew.SetObjectName(*mnuBoltNew__objectName)
|
||||||
|
mnuBoltNew__objectName.Delete() // setter copied value
|
||||||
|
icon3 := qt.NewQIcon()
|
||||||
|
icon3.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuBoltNew.SetIcon(icon3)
|
||||||
|
ui.mnuBoltOpenDatabase = qt.NewQAction()
|
||||||
|
mnuBoltOpenDatabase__objectName := qt.NewQAnyStringView3("mnuBoltOpenDatabase")
|
||||||
|
ui.mnuBoltOpenDatabase.SetObjectName(*mnuBoltOpenDatabase__objectName)
|
||||||
|
mnuBoltOpenDatabase__objectName.Delete() // setter copied value
|
||||||
|
icon4 := qt.NewQIcon()
|
||||||
|
icon4.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuBoltOpenDatabase.SetIcon(icon4)
|
||||||
|
ui.mnuBoltOpenDatabaseReadonly = qt.NewQAction()
|
||||||
|
mnuBoltOpenDatabaseReadonly__objectName := qt.NewQAnyStringView3("mnuBoltOpenDatabaseReadonly")
|
||||||
|
ui.mnuBoltOpenDatabaseReadonly.SetObjectName(*mnuBoltOpenDatabaseReadonly__objectName)
|
||||||
|
mnuBoltOpenDatabaseReadonly__objectName.Delete() // setter copied value
|
||||||
|
icon5 := qt.NewQIcon()
|
||||||
|
icon5.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuBoltOpenDatabaseReadonly.SetIcon(icon5)
|
||||||
|
ui.mnuDebconfOpen = qt.NewQAction()
|
||||||
|
mnuDebconfOpen__objectName := qt.NewQAnyStringView3("mnuDebconfOpen")
|
||||||
|
ui.mnuDebconfOpen.SetObjectName(*mnuDebconfOpen__objectName)
|
||||||
|
mnuDebconfOpen__objectName.Delete() // setter copied value
|
||||||
|
icon6 := qt.NewQIcon()
|
||||||
|
icon6.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuDebconfOpen.SetIcon(icon6)
|
||||||
|
ui.mnuPebbleOpenDatabase = qt.NewQAction()
|
||||||
|
mnuPebbleOpenDatabase__objectName := qt.NewQAnyStringView3("mnuPebbleOpenDatabase")
|
||||||
|
ui.mnuPebbleOpenDatabase.SetObjectName(*mnuPebbleOpenDatabase__objectName)
|
||||||
|
mnuPebbleOpenDatabase__objectName.Delete() // setter copied value
|
||||||
|
icon7 := qt.NewQIcon()
|
||||||
|
icon7.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuPebbleOpenDatabase.SetIcon(icon7)
|
||||||
|
ui.mnuPebbleNewInMemory = qt.NewQAction()
|
||||||
|
mnuPebbleNewInMemory__objectName := qt.NewQAnyStringView3("mnuPebbleNewInMemory")
|
||||||
|
ui.mnuPebbleNewInMemory.SetObjectName(*mnuPebbleNewInMemory__objectName)
|
||||||
|
mnuPebbleNewInMemory__objectName.Delete() // setter copied value
|
||||||
|
icon8 := qt.NewQIcon()
|
||||||
|
icon8.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuPebbleNewInMemory.SetIcon(icon8)
|
||||||
|
ui.mnuRedisConnect = qt.NewQAction()
|
||||||
|
mnuRedisConnect__objectName := qt.NewQAnyStringView3("mnuRedisConnect")
|
||||||
|
ui.mnuRedisConnect.SetObjectName(*mnuRedisConnect__objectName)
|
||||||
|
mnuRedisConnect__objectName.Delete() // setter copied value
|
||||||
|
icon9 := qt.NewQIcon()
|
||||||
|
icon9.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuRedisConnect.SetIcon(icon9)
|
||||||
|
ui.mnuSqliteOpenDatabase = qt.NewQAction()
|
||||||
|
mnuSqliteOpenDatabase__objectName := qt.NewQAnyStringView3("mnuSqliteOpenDatabase")
|
||||||
|
ui.mnuSqliteOpenDatabase.SetObjectName(*mnuSqliteOpenDatabase__objectName)
|
||||||
|
mnuSqliteOpenDatabase__objectName.Delete() // setter copied value
|
||||||
|
icon10 := qt.NewQIcon()
|
||||||
|
icon10.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuSqliteOpenDatabase.SetIcon(icon10)
|
||||||
|
ui.mnuSqliteNewInMemory = qt.NewQAction()
|
||||||
|
mnuSqliteNewInMemory__objectName := qt.NewQAnyStringView3("mnuSqliteNewInMemory")
|
||||||
|
ui.mnuSqliteNewInMemory.SetObjectName(*mnuSqliteNewInMemory__objectName)
|
||||||
|
mnuSqliteNewInMemory__objectName.Delete() // setter copied value
|
||||||
|
icon11 := qt.NewQIcon()
|
||||||
|
icon11.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuSqliteNewInMemory.SetIcon(icon11)
|
||||||
|
ui.mnuSqliteExperimentalDriver = qt.NewQAction()
|
||||||
|
mnuSqliteExperimentalDriver__objectName := qt.NewQAnyStringView3("mnuSqliteExperimentalDriver")
|
||||||
|
ui.mnuSqliteExperimentalDriver.SetObjectName(*mnuSqliteExperimentalDriver__objectName)
|
||||||
|
mnuSqliteExperimentalDriver__objectName.Delete() // setter copied value
|
||||||
|
/* miqt-uic: no handler for QAction property 'checkable' */
|
||||||
|
ui.mnuExecute = qt.NewQAction()
|
||||||
|
mnuExecute__objectName := qt.NewQAnyStringView3("mnuExecute")
|
||||||
|
ui.mnuExecute.SetObjectName(*mnuExecute__objectName)
|
||||||
|
mnuExecute__objectName.Delete() // setter copied value
|
||||||
|
icon12 := qt.NewQIcon()
|
||||||
|
icon12.AddFile4(":/assets/resultset_next.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.mnuExecute.SetIcon(icon12)
|
||||||
|
ui.mnuDriverVersions = qt.NewQAction()
|
||||||
|
mnuDriverVersions__objectName := qt.NewQAnyStringView3("mnuDriverVersions")
|
||||||
|
ui.mnuDriverVersions.SetObjectName(*mnuDriverVersions__objectName)
|
||||||
|
mnuDriverVersions__objectName.Delete() // setter copied value
|
||||||
|
ui.mnuHelpAbout = qt.NewQAction()
|
||||||
|
mnuHelpAbout__objectName := qt.NewQAnyStringView3("mnuHelpAbout")
|
||||||
|
ui.mnuHelpAbout.SetObjectName(*mnuHelpAbout__objectName)
|
||||||
|
mnuHelpAbout__objectName.Delete() // setter copied value
|
||||||
|
ui.actionConnect = qt.NewQAction()
|
||||||
|
actionConnect__objectName := qt.NewQAnyStringView3("actionConnect")
|
||||||
|
ui.actionConnect.SetObjectName(*actionConnect__objectName)
|
||||||
|
actionConnect__objectName.Delete() // setter copied value
|
||||||
|
icon13 := qt.NewQIcon()
|
||||||
|
icon13.AddFile4(":/assets/database_add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.actionConnect.SetIcon(icon13)
|
||||||
|
ui.centralwidget = qt.NewQWidget(ui.MainWindow.QWidget)
|
||||||
|
centralwidget__objectName := qt.NewQAnyStringView3("centralwidget")
|
||||||
|
ui.centralwidget.SetObjectName(*centralwidget__objectName)
|
||||||
|
centralwidget__objectName.Delete() // setter copied value
|
||||||
|
ui.gridLayout = qt.NewQGridLayout(ui.centralwidget)
|
||||||
|
gridLayout__objectName := qt.NewQAnyStringView3("gridLayout")
|
||||||
|
ui.gridLayout.SetObjectName(*gridLayout__objectName)
|
||||||
|
gridLayout__objectName.Delete() // setter copied value
|
||||||
|
ui.gridLayout.SetContentsMargins(11, 11, 11, 11)
|
||||||
|
ui.gridLayout.SetSpacing(6)
|
||||||
|
ui.splitter = qt.NewQSplitter(ui.centralwidget)
|
||||||
|
splitter__objectName := qt.NewQAnyStringView3("splitter")
|
||||||
|
ui.splitter.SetObjectName(*splitter__objectName)
|
||||||
|
splitter__objectName.Delete() // setter copied value
|
||||||
|
ui.splitter.SetOrientation(qt.Horizontal)
|
||||||
|
ui.splitter.SetChildrenCollapsible(false)
|
||||||
|
ui.Buckets = qt.NewQTreeWidget(ui.splitter.QWidget)
|
||||||
|
Buckets__objectName := qt.NewQAnyStringView3("Buckets")
|
||||||
|
ui.Buckets.SetObjectName(*Buckets__objectName)
|
||||||
|
Buckets__objectName.Delete() // setter copied value
|
||||||
|
ui.Buckets.SetUniformRowHeights(true)
|
||||||
|
ui.Buckets.SetHeaderHidden(true)
|
||||||
|
/* miqt-uic: no handler for Buckets attribute 'headerVisible' */
|
||||||
|
ui.Buckets.HeaderItem().SetText(0, "1")
|
||||||
|
ui.splitter.AddWidget(ui.Buckets.QWidget)
|
||||||
|
ui.tabWidget = qt.NewQTabWidget(ui.splitter.QWidget)
|
||||||
|
tabWidget__objectName := qt.NewQAnyStringView3("tabWidget")
|
||||||
|
ui.tabWidget.SetObjectName(*tabWidget__objectName)
|
||||||
|
tabWidget__objectName.Delete() // setter copied value
|
||||||
|
tabWidget__sizePolicy := qt.NewQSizePolicy()
|
||||||
|
tabWidget__sizePolicy.SetHorizontalPolicy(qt.QSizePolicy__Expanding)
|
||||||
|
tabWidget__sizePolicy.SetVerticalPolicy(qt.QSizePolicy__Expanding)
|
||||||
|
tabWidget__sizePolicy.SetHorizontalStretch(1)
|
||||||
|
tabWidget__sizePolicy.SetVerticalStretch(0)
|
||||||
|
tabWidget__sizePolicy.SetHeightForWidth(ui.tabWidget.SizePolicy().HasHeightForWidth())
|
||||||
|
ui.tabWidget.SetSizePolicy(*tabWidget__sizePolicy)
|
||||||
|
tabWidget__sizePolicy.Delete() // setter copies values
|
||||||
|
ui.tabProperties = qt.NewQWidget(ui.tabWidget.QWidget)
|
||||||
|
tabProperties__objectName := qt.NewQAnyStringView3("tabProperties")
|
||||||
|
ui.tabProperties.SetObjectName(*tabProperties__objectName)
|
||||||
|
tabProperties__objectName.Delete() // setter copied value
|
||||||
|
ui.gridLayout_2 = qt.NewQGridLayout(ui.tabProperties)
|
||||||
|
gridLayout_2__objectName := qt.NewQAnyStringView3("gridLayout_2")
|
||||||
|
ui.gridLayout_2.SetObjectName(*gridLayout_2__objectName)
|
||||||
|
gridLayout_2__objectName.Delete() // setter copied value
|
||||||
|
ui.gridLayout_2.SetContentsMargins(11, 11, 11, 11)
|
||||||
|
ui.gridLayout_2.SetSpacing(6)
|
||||||
|
ui.propertiesBox = qt.NewQTextEdit(ui.tabProperties)
|
||||||
|
propertiesBox__objectName := qt.NewQAnyStringView3("propertiesBox")
|
||||||
|
ui.propertiesBox.SetObjectName(*propertiesBox__objectName)
|
||||||
|
propertiesBox__objectName.Delete() // setter copied value
|
||||||
|
ui.propertiesBox.SetFrameShape(qt.QFrame__NoFrame)
|
||||||
|
ui.propertiesBox.SetReadOnly(true)
|
||||||
|
|
||||||
|
ui.gridLayout_2.AddWidget2(ui.propertiesBox.QWidget, 0, 0)
|
||||||
|
icon14 := qt.NewQIcon()
|
||||||
|
icon14.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.tabWidget.AddTab2(ui.tabProperties, icon14, "")
|
||||||
|
ui.tabData = qt.NewQWidget(ui.tabWidget.QWidget)
|
||||||
|
tabData__objectName := qt.NewQAnyStringView3("tabData")
|
||||||
|
ui.tabData.SetObjectName(*tabData__objectName)
|
||||||
|
tabData__objectName.Delete() // setter copied value
|
||||||
|
ui.verticalLayout = qt.NewQVBoxLayout(ui.tabData)
|
||||||
|
verticalLayout__objectName := qt.NewQAnyStringView3("verticalLayout")
|
||||||
|
ui.verticalLayout.SetObjectName(*verticalLayout__objectName)
|
||||||
|
verticalLayout__objectName.Delete() // setter copied value
|
||||||
|
ui.verticalLayout.SetContentsMargins(11, 11, 11, 11)
|
||||||
|
ui.verticalLayout.SetSpacing(6)
|
||||||
|
ui.horizontalLayout = qt.NewQHBoxLayout2()
|
||||||
|
horizontalLayout__objectName := qt.NewQAnyStringView3("horizontalLayout")
|
||||||
|
ui.horizontalLayout.SetObjectName(*horizontalLayout__objectName)
|
||||||
|
horizontalLayout__objectName.Delete() // setter copied value
|
||||||
|
ui.horizontalLayout.SetContentsMargins(0, 0, 0, 0)
|
||||||
|
ui.horizontalLayout.SetSpacing(6)
|
||||||
|
ui.dataRefreshBtn = qt.NewQToolButton(ui.tabData)
|
||||||
|
dataRefreshBtn__objectName := qt.NewQAnyStringView3("dataRefreshBtn")
|
||||||
|
ui.dataRefreshBtn.SetObjectName(*dataRefreshBtn__objectName)
|
||||||
|
dataRefreshBtn__objectName.Delete() // setter copied value
|
||||||
|
icon15 := qt.NewQIcon()
|
||||||
|
icon15.AddFile4(":/assets/arrow_refresh.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.dataRefreshBtn.SetIcon(icon15)
|
||||||
|
ui.dataRefreshBtn.SetAutoRaise(true)
|
||||||
|
|
||||||
|
ui.horizontalLayout.AddWidget(ui.dataRefreshBtn.QWidget)
|
||||||
|
ui.dataInsertBtn = qt.NewQToolButton(ui.tabData)
|
||||||
|
dataInsertBtn__objectName := qt.NewQAnyStringView3("dataInsertBtn")
|
||||||
|
ui.dataInsertBtn.SetObjectName(*dataInsertBtn__objectName)
|
||||||
|
dataInsertBtn__objectName.Delete() // setter copied value
|
||||||
|
icon16 := qt.NewQIcon()
|
||||||
|
icon16.AddFile4(":/assets/add.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.dataInsertBtn.SetIcon(icon16)
|
||||||
|
ui.dataInsertBtn.SetAutoRaise(true)
|
||||||
|
|
||||||
|
ui.horizontalLayout.AddWidget(ui.dataInsertBtn.QWidget)
|
||||||
|
ui.dataDelRowBtn = qt.NewQToolButton(ui.tabData)
|
||||||
|
dataDelRowBtn__objectName := qt.NewQAnyStringView3("dataDelRowBtn")
|
||||||
|
ui.dataDelRowBtn.SetObjectName(*dataDelRowBtn__objectName)
|
||||||
|
dataDelRowBtn__objectName.Delete() // setter copied value
|
||||||
|
icon17 := qt.NewQIcon()
|
||||||
|
icon17.AddFile4(":/assets/delete.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.dataDelRowBtn.SetIcon(icon17)
|
||||||
|
ui.dataDelRowBtn.SetAutoRaise(true)
|
||||||
|
|
||||||
|
ui.horizontalLayout.AddWidget(ui.dataDelRowBtn.QWidget)
|
||||||
|
ui.dataCommitBtn = qt.NewQToolButton(ui.tabData)
|
||||||
|
dataCommitBtn__objectName := qt.NewQAnyStringView3("dataCommitBtn")
|
||||||
|
ui.dataCommitBtn.SetObjectName(*dataCommitBtn__objectName)
|
||||||
|
dataCommitBtn__objectName.Delete() // setter copied value
|
||||||
|
icon18 := qt.NewQIcon()
|
||||||
|
icon18.AddFile4(":/assets/pencil_go.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.dataCommitBtn.SetIcon(icon18)
|
||||||
|
ui.dataCommitBtn.SetAutoRaise(true)
|
||||||
|
|
||||||
|
ui.horizontalLayout.AddWidget(ui.dataCommitBtn.QWidget)
|
||||||
|
ui.horizontalSpacer = qt.NewQSpacerItem4(40, 20, qt.QSizePolicy__Expanding, qt.QSizePolicy__Minimum)
|
||||||
|
|
||||||
|
ui.horizontalLayout.AddItem(ui.horizontalSpacer.QLayoutItem)
|
||||||
|
|
||||||
|
ui.verticalLayout.AddLayout(ui.horizontalLayout.QLayout)
|
||||||
|
ui.contentBox = qt.NewQTableWidget(ui.tabData)
|
||||||
|
contentBox__objectName := qt.NewQAnyStringView3("contentBox")
|
||||||
|
ui.contentBox.SetObjectName(*contentBox__objectName)
|
||||||
|
contentBox__objectName.Delete() // setter copied value
|
||||||
|
ui.contentBox.SetVerticalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
|
||||||
|
ui.verticalLayout.AddWidget(ui.contentBox.QWidget)
|
||||||
|
icon19 := qt.NewQIcon()
|
||||||
|
icon19.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.tabWidget.AddTab2(ui.tabData, icon19, "")
|
||||||
|
ui.tabQuery = qt.NewQWidget(ui.tabWidget.QWidget)
|
||||||
|
tabQuery__objectName := qt.NewQAnyStringView3("tabQuery")
|
||||||
|
ui.tabQuery.SetObjectName(*tabQuery__objectName)
|
||||||
|
tabQuery__objectName.Delete() // setter copied value
|
||||||
|
ui.verticalLayout_2 = qt.NewQVBoxLayout(ui.tabQuery)
|
||||||
|
verticalLayout_2__objectName := qt.NewQAnyStringView3("verticalLayout_2")
|
||||||
|
ui.verticalLayout_2.SetObjectName(*verticalLayout_2__objectName)
|
||||||
|
verticalLayout_2__objectName.Delete() // setter copied value
|
||||||
|
ui.verticalLayout_2.SetContentsMargins(11, 11, 11, 11)
|
||||||
|
ui.verticalLayout_2.SetSpacing(6)
|
||||||
|
ui.horizontalLayout_2 = qt.NewQHBoxLayout2()
|
||||||
|
horizontalLayout_2__objectName := qt.NewQAnyStringView3("horizontalLayout_2")
|
||||||
|
ui.horizontalLayout_2.SetObjectName(*horizontalLayout_2__objectName)
|
||||||
|
horizontalLayout_2__objectName.Delete() // setter copied value
|
||||||
|
ui.horizontalLayout_2.SetContentsMargins(0, 0, 0, 0)
|
||||||
|
ui.horizontalLayout_2.SetSpacing(6)
|
||||||
|
ui.queryExecBtn = qt.NewQToolButton(ui.tabQuery)
|
||||||
|
queryExecBtn__objectName := qt.NewQAnyStringView3("queryExecBtn")
|
||||||
|
ui.queryExecBtn.SetObjectName(*queryExecBtn__objectName)
|
||||||
|
queryExecBtn__objectName.Delete() // setter copied value
|
||||||
|
icon20 := qt.NewQIcon()
|
||||||
|
icon20.AddFile4(":/assets/resultset_next.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.queryExecBtn.SetIcon(icon20)
|
||||||
|
ui.queryExecBtn.SetAutoRaise(true)
|
||||||
|
|
||||||
|
ui.horizontalLayout_2.AddWidget(ui.queryExecBtn.QWidget)
|
||||||
|
ui.horizontalSpacer_2 = qt.NewQSpacerItem4(40, 20, qt.QSizePolicy__Expanding, qt.QSizePolicy__Minimum)
|
||||||
|
|
||||||
|
ui.horizontalLayout_2.AddItem(ui.horizontalSpacer_2.QLayoutItem)
|
||||||
|
|
||||||
|
ui.verticalLayout_2.AddLayout(ui.horizontalLayout_2.QLayout)
|
||||||
|
ui.splitter_2 = qt.NewQSplitter(ui.tabQuery)
|
||||||
|
splitter_2__objectName := qt.NewQAnyStringView3("splitter_2")
|
||||||
|
ui.splitter_2.SetObjectName(*splitter_2__objectName)
|
||||||
|
splitter_2__objectName.Delete() // setter copied value
|
||||||
|
ui.splitter_2.SetOrientation(qt.Vertical)
|
||||||
|
ui.splitter_2.SetChildrenCollapsible(false)
|
||||||
|
ui.queryInput = qt.NewQTextEdit(ui.splitter_2.QWidget)
|
||||||
|
queryInput__objectName := qt.NewQAnyStringView3("queryInput")
|
||||||
|
ui.queryInput.SetObjectName(*queryInput__objectName)
|
||||||
|
queryInput__objectName.Delete() // setter copied value
|
||||||
|
/* miqt-uic: no handler for queryInput property 'font' */
|
||||||
|
ui.splitter_2.AddWidget(ui.queryInput.QWidget)
|
||||||
|
ui.queryResult = qt.NewQTableWidget(ui.splitter_2.QWidget)
|
||||||
|
queryResult__objectName := qt.NewQAnyStringView3("queryResult")
|
||||||
|
ui.queryResult.SetObjectName(*queryResult__objectName)
|
||||||
|
queryResult__objectName.Delete() // setter copied value
|
||||||
|
ui.queryResult.SetVerticalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
ui.queryResult.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
ui.splitter_2.AddWidget(ui.queryResult.QWidget)
|
||||||
|
|
||||||
|
ui.verticalLayout_2.AddWidget(ui.splitter_2.QWidget)
|
||||||
|
icon21 := qt.NewQIcon()
|
||||||
|
icon21.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.tabWidget.AddTab2(ui.tabQuery, icon21, "")
|
||||||
|
ui.splitter.AddWidget(ui.tabWidget.QWidget)
|
||||||
|
|
||||||
|
ui.gridLayout.AddWidget2(ui.splitter.QWidget, 0, 0)
|
||||||
|
ui.MainWindow.SetCentralWidget(ui.centralwidget) // Set central widget
|
||||||
|
ui.menubar = qt.NewQMenuBar(ui.MainWindow.QWidget)
|
||||||
|
menubar__objectName := qt.NewQAnyStringView3("menubar")
|
||||||
|
ui.menubar.SetObjectName(*menubar__objectName)
|
||||||
|
menubar__objectName.Delete() // setter copied value
|
||||||
|
ui.menubar.Resize(1280, 29)
|
||||||
|
ui.menu_File = qt.NewQMenu(ui.menubar.QWidget)
|
||||||
|
menu_File__objectName := qt.NewQAnyStringView3("menu_File")
|
||||||
|
ui.menu_File.SetObjectName(*menu_File__objectName)
|
||||||
|
menu_File__objectName.Delete() // setter copied value
|
||||||
|
ui.menu_File.QWidget.AddAction(ui.actionConnect)
|
||||||
|
ui.menu_File.AddSeparator()
|
||||||
|
ui.menu_File.QWidget.AddAction(ui.actionE_xit)
|
||||||
|
ui.menu_Query = qt.NewQMenu(ui.menubar.QWidget)
|
||||||
|
menu_Query__objectName := qt.NewQAnyStringView3("menu_Query")
|
||||||
|
ui.menu_Query.SetObjectName(*menu_Query__objectName)
|
||||||
|
menu_Query__objectName.Delete() // setter copied value
|
||||||
|
ui.menu_Query.QWidget.AddAction(ui.mnuExecute)
|
||||||
|
ui.menu_Help = qt.NewQMenu(ui.menubar.QWidget)
|
||||||
|
menu_Help__objectName := qt.NewQAnyStringView3("menu_Help")
|
||||||
|
ui.menu_Help.SetObjectName(*menu_Help__objectName)
|
||||||
|
menu_Help__objectName.Delete() // setter copied value
|
||||||
|
ui.menu_Help.QWidget.AddAction(ui.mnuDriverVersions)
|
||||||
|
ui.menu_Help.QWidget.AddAction(ui.mnuHelpAbout)
|
||||||
|
ui.menubar.AddMenu(ui.menu_File)
|
||||||
|
ui.menubar.AddMenu(ui.menu_Query)
|
||||||
|
ui.menubar.AddMenu(ui.menu_Help)
|
||||||
|
ui.MainWindow.SetMenuBar(ui.menubar)
|
||||||
|
ui.statusbar = qt.NewQStatusBar(ui.MainWindow.QWidget)
|
||||||
|
statusbar__objectName := qt.NewQAnyStringView3("statusbar")
|
||||||
|
ui.statusbar.SetObjectName(*statusbar__objectName)
|
||||||
|
statusbar__objectName.Delete() // setter copied value
|
||||||
|
ui.MainWindow.SetStatusBar(ui.statusbar)
|
||||||
|
|
||||||
|
ui.Retranslate()
|
||||||
|
|
||||||
|
ui.tabWidget.SetCurrentIndex(0)
|
||||||
|
|
||||||
|
return ui
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retranslate reapplies all text translations.
|
||||||
|
func (ui *MainWindowUi) Retranslate() {
|
||||||
|
ui.MainWindow.SetWindowTitle(qt.QCoreApplication_Tr("yvbolt"))
|
||||||
|
ui.actionE_xit.SetText(qt.QMainWindow_Tr("E&xit"))
|
||||||
|
ui.mnuBadgerOpen.SetText(qt.QMainWindow_Tr("Open database..."))
|
||||||
|
ui.mnuBadgerNewInMemory.SetText(qt.QMainWindow_Tr("New in-memory database"))
|
||||||
|
ui.mnuBoltNew.SetText(qt.QMainWindow_Tr("New database..."))
|
||||||
|
ui.mnuBoltOpenDatabase.SetText(qt.QMainWindow_Tr("Open database..."))
|
||||||
|
ui.mnuBoltOpenDatabaseReadonly.SetText(qt.QMainWindow_Tr("Open database (read-only)..."))
|
||||||
|
ui.mnuDebconfOpen.SetText(qt.QMainWindow_Tr("Open database..."))
|
||||||
|
ui.mnuPebbleOpenDatabase.SetText(qt.QMainWindow_Tr("Open database..."))
|
||||||
|
ui.mnuPebbleNewInMemory.SetText(qt.QMainWindow_Tr("New in-memory database"))
|
||||||
|
ui.mnuRedisConnect.SetText(qt.QMainWindow_Tr("Connect..."))
|
||||||
|
ui.mnuSqliteOpenDatabase.SetText(qt.QMainWindow_Tr("Open database..."))
|
||||||
|
ui.mnuSqliteNewInMemory.SetText(qt.QMainWindow_Tr("New in-memory database"))
|
||||||
|
ui.mnuSqliteExperimentalDriver.SetText(qt.QMainWindow_Tr("Connect using CLI driver (experimental)"))
|
||||||
|
ui.mnuExecute.SetText(qt.QMainWindow_Tr("E&xecute"))
|
||||||
|
ui.mnuExecute.SetShortcut(qt.NewQKeySequence2(qt.QMainWindow_Tr("F9")))
|
||||||
|
ui.mnuDriverVersions.SetText(qt.QMainWindow_Tr("Driver versions..."))
|
||||||
|
ui.mnuHelpAbout.SetText(qt.QMainWindow_Tr("&About yvbolt"))
|
||||||
|
ui.mnuHelpAbout.SetShortcut(qt.NewQKeySequence2(qt.QMainWindow_Tr("F1")))
|
||||||
|
ui.actionConnect.SetText(qt.QMainWindow_Tr("Connect..."))
|
||||||
|
ui.actionConnect.SetShortcut(qt.NewQKeySequence2(qt.QMainWindow_Tr("Ctrl+O")))
|
||||||
|
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabProperties), qt.QTabWidget_Tr("Properties"))
|
||||||
|
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabData), qt.QTabWidget_Tr("Data"))
|
||||||
|
ui.dataRefreshBtn.SetToolTip(qt.QWidget_Tr("Refresh"))
|
||||||
|
ui.dataRefreshBtn.SetShortcut(qt.NewQKeySequence2(qt.QWidget_Tr("F5")))
|
||||||
|
ui.dataInsertBtn.SetToolTip(qt.QWidget_Tr("Insert"))
|
||||||
|
ui.dataDelRowBtn.SetToolTip(qt.QWidget_Tr("Delete Row"))
|
||||||
|
ui.dataCommitBtn.SetToolTip(qt.QWidget_Tr("Commit"))
|
||||||
|
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabQuery), qt.QTabWidget_Tr("Query"))
|
||||||
|
ui.queryExecBtn.SetText(qt.QWidget_Tr("Execute"))
|
||||||
|
ui.menu_File.SetTitle(qt.QMenuBar_Tr("&File"))
|
||||||
|
ui.menu_Query.SetTitle(qt.QMenuBar_Tr("&Query"))
|
||||||
|
ui.menu_Help.SetTitle(qt.QMenuBar_Tr("&Help"))
|
||||||
|
}
|
||||||
435
mainwindow.ui
Normal file
@@ -0,0 +1,435 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1280</width>
|
||||||
|
<height>640</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>yvbolt</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_lightning.png</normaloff>:/assets/database_lightning.png</iconset>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="childrenCollapsible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QTreeWidget" name="Buckets">
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="headerHidden">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="headerVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">1</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>1</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tabProperties">
|
||||||
|
<attribute name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/chart_bar.png</normaloff>:/assets/chart_bar.png</iconset>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Properties</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTextEdit" name="propertiesBox">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::Shape::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tabData">
|
||||||
|
<attribute name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/table.png</normaloff>:/assets/table.png</iconset>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Data</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="dataRefreshBtn">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Refresh</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/arrow_refresh.png</normaloff>:/assets/arrow_refresh.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F5</string>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="dataInsertBtn">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Insert</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/add.png</normaloff>:/assets/add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="dataDelRowBtn">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Delete Row</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/delete.png</normaloff>:/assets/delete.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="dataCommitBtn">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Commit</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/pencil_go.png</normaloff>:/assets/pencil_go.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTableWidget" name="contentBox">
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollMode::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollMode::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tabQuery">
|
||||||
|
<attribute name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/lightning.png</normaloff>:/assets/lightning.png</iconset>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Query</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="queryExecBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Execute</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/resultset_next.png</normaloff>:/assets/resultset_next.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSplitter" name="splitter_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="childrenCollapsible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QTextEdit" name="queryInput">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Monospace</family>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QTableWidget" name="queryResult">
|
||||||
|
<property name="verticalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollMode::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollMode">
|
||||||
|
<enum>QAbstractItemView::ScrollMode::ScrollPerPixel</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1280</width>
|
||||||
|
<height>29</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menu_File">
|
||||||
|
<property name="title">
|
||||||
|
<string>&File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionConnect"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionE_xit"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_Query">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Query</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="mnuExecute"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_Help">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Help</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="mnuDriverVersions"/>
|
||||||
|
<addaction name="mnuHelpAbout"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menu_File"/>
|
||||||
|
<addaction name="menu_Query"/>
|
||||||
|
<addaction name="menu_Help"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionE_xit">
|
||||||
|
<property name="text">
|
||||||
|
<string>E&xit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuBadgerOpen">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuBadgerNewInMemory">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New in-memory database</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuBoltNew">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuBoltOpenDatabase">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuBoltOpenDatabaseReadonly">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database (read-only)...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuDebconfOpen">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuPebbleOpenDatabase">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuPebbleNewInMemory">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New in-memory database</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuRedisConnect">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuSqliteOpenDatabase">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open database...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuSqliteNewInMemory">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New in-memory database</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuSqliteExperimentalDriver">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect using CLI driver (experimental)</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuExecute">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/resultset_next.png</normaloff>:/assets/resultset_next.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>E&xecute</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F9</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuDriverVersions">
|
||||||
|
<property name="text">
|
||||||
|
<string>Driver versions...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="mnuHelpAbout">
|
||||||
|
<property name="text">
|
||||||
|
<string>&About yvbolt</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionConnect">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/database_add.png</normaloff>:/assets/database_add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="embed.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
266
sqlite.go
@@ -1,266 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/ying32/govcl/vcl"
|
|
||||||
"github.com/ying32/govcl/vcl/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sqliteTablesCaption = "Tables"
|
|
||||||
)
|
|
||||||
|
|
||||||
type sqliteLoadedDatabase struct {
|
|
||||||
displayName string
|
|
||||||
path string
|
|
||||||
db *sql.DB
|
|
||||||
nav *vcl.TTreeNode
|
|
||||||
|
|
||||||
arena []*navData // keepalive
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) DisplayName() string {
|
|
||||||
return ld.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) RootElement() *vcl.TTreeNode {
|
|
||||||
return ld.nav
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) Keepalive(ndata *navData) {
|
|
||||||
ld.arena = append(ld.arena, ndata)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
|
||||||
|
|
||||||
if len(ndata.bucketPath) == 0 {
|
|
||||||
// Top-level
|
|
||||||
f.propertiesBox.SetText("Please select...")
|
|
||||||
f.contentBox.SetEnabled(false)
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
} else if len(ndata.bucketPath) == 1 {
|
|
||||||
// Category (tables, ...)
|
|
||||||
f.propertiesBox.SetText("Please select...")
|
|
||||||
f.contentBox.SetEnabled(false)
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
} else if len(ndata.bucketPath) == 2 && ndata.bucketPath[0] == sqliteTablesCaption {
|
|
||||||
// Render for specific table
|
|
||||||
tableName := ndata.bucketPath[1]
|
|
||||||
|
|
||||||
// Get some basic properties
|
|
||||||
r := ld.db.QueryRow(`SELECT sql FROM sqlite_schema WHERE name = ?;`, tableName)
|
|
||||||
var schemaStmt string
|
|
||||||
err := r.Scan(&schemaStmt)
|
|
||||||
if err != nil {
|
|
||||||
schemaStmt = fmt.Sprintf("* Failed to describe table %q: %s", tableName, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display table properties
|
|
||||||
f.propertiesBox.SetText(fmt.Sprintf("Selected table %q\n\nSchema:\n\n%s", tableName, schemaStmt))
|
|
||||||
|
|
||||||
f.contentBox.SetEnabled(false)
|
|
||||||
f.contentBox.Clear()
|
|
||||||
|
|
||||||
// Load column details
|
|
||||||
// Use SELECT form instead of common PRAGMA table_info so we can just get names
|
|
||||||
// We could possibly get this from the main data select, but this will
|
|
||||||
// work even when there are 0 results
|
|
||||||
columnNames, err := ld.sqliteGetColumnNamesForTable(tableName)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessageFmt("Failed to load columns for table %q: %s", tableName, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
populateColumns(columnNames, f.contentBox)
|
|
||||||
|
|
||||||
// Select count(*) so we know to display a warning if there are too many entries
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Select * with small limit
|
|
||||||
datar, err := ld.db.Query(`SELECT * FROM ` + tableName + ` LIMIT 1000`) // WARNING can't prepare this parameter, but it comes from the DB (trusted)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessageFmt("Failed to load data for table %q: %s", tableName, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer datar.Close()
|
|
||||||
populateRows(datar, f.contentBox)
|
|
||||||
|
|
||||||
// We successfully populated the data grid
|
|
||||||
f.contentBox.SetEnabled(true)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// ??? unknown
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) sqliteGetColumnNamesForTable(tableName string) ([]string, error) {
|
|
||||||
colr, err := ld.db.Query(`SELECT name FROM pragma_table_info(?)`, tableName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Query: %w", err)
|
|
||||||
}
|
|
||||||
defer colr.Close()
|
|
||||||
|
|
||||||
var ret []string
|
|
||||||
|
|
||||||
for colr.Next() {
|
|
||||||
|
|
||||||
var columnName string
|
|
||||||
err = colr.Scan(&columnName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Scan: %w", colr.Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = append(ret, columnName)
|
|
||||||
}
|
|
||||||
if colr.Err() != nil {
|
|
||||||
return nil, colr.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func populateColumns(names []string, dest *vcl.TListView) {
|
|
||||||
dest.Columns().Clear()
|
|
||||||
for _, columnName := range names {
|
|
||||||
col := dest.Columns().Add()
|
|
||||||
col.SetCaption(columnName)
|
|
||||||
col.SetWidth(MY_WIDTH)
|
|
||||||
col.SetAlignment(types.TaLeftJustify)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func populateRows(rr *sql.Rows, dest *vcl.TListView) {
|
|
||||||
|
|
||||||
numColumns := int(dest.Columns().Count())
|
|
||||||
|
|
||||||
for rr.Next() {
|
|
||||||
fields := make([]interface{}, numColumns)
|
|
||||||
pfields := make([]interface{}, numColumns)
|
|
||||||
for i := 0; i < numColumns; i += 1 {
|
|
||||||
pfields[i] = &fields[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
err := rr.Scan(pfields...)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessageFmt("Failed to load data: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dataEntry := dest.Items().Add()
|
|
||||||
dataEntry.SetCaption(formatAny(fields[0]))
|
|
||||||
for i := 1; i < len(fields); i += 1 {
|
|
||||||
dataEntry.SubItems().Add(formatAny(fields[i]))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if rr.Err() != nil {
|
|
||||||
vcl.ShowMessageFmt("Failed to load data: %s", rr.Err().Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *vcl.TListView) {
|
|
||||||
rr, err := ld.db.Query(query)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer rr.Close()
|
|
||||||
|
|
||||||
resultArea.SetEnabled(false)
|
|
||||||
resultArea.Clear()
|
|
||||||
|
|
||||||
columns, err := rr.Columns()
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
populateColumns(columns, resultArea)
|
|
||||||
|
|
||||||
populateRows(rr, resultArea)
|
|
||||||
|
|
||||||
resultArea.SetEnabled(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
|
||||||
|
|
||||||
if len(ndata.bucketPath) == 0 {
|
|
||||||
// The top-level children are always:
|
|
||||||
return []string{sqliteTablesCaption}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ndata.bucketPath) == 1 && ndata.bucketPath[0] == sqliteTablesCaption {
|
|
||||||
rr, err := ld.db.Query(`SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC;`)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rr.Close()
|
|
||||||
|
|
||||||
var gather []string
|
|
||||||
for rr.Next() {
|
|
||||||
var tableName string
|
|
||||||
err = rr.Scan(&tableName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
gather = append(gather, tableName)
|
|
||||||
}
|
|
||||||
if rr.Err() != nil {
|
|
||||||
return nil, rr.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gather, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ndata.bucketPath) == 2 {
|
|
||||||
return nil, nil // Never any deeper children
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("unknown nav path %#v", ndata.bucketPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ loadedDatabase = &sqliteLoadedDatabase{} // interface assertion
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
func (f *TMainForm) sqliteAddDatabaseFromFile(path string) {
|
|
||||||
|
|
||||||
// TODO load in background thread to stop blocking the UI
|
|
||||||
db, err := sql.Open("sqlite3", path)
|
|
||||||
if err != nil {
|
|
||||||
vcl.ShowMessage(fmt.Sprintf("Failed to load database '%s': %s", path, err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ld := &sqliteLoadedDatabase{
|
|
||||||
path: path,
|
|
||||||
displayName: filepath.Base(path),
|
|
||||||
db: db,
|
|
||||||
}
|
|
||||||
|
|
||||||
ld.nav = f.Buckets.Items().Add(nil, ld.displayName)
|
|
||||||
ld.nav.SetImageIndex(imgDatabase)
|
|
||||||
ld.nav.SetSelectedIndex(imgDatabase)
|
|
||||||
ld.nav.SetHasChildren(true) // dynamically populate in OnNavExpanding
|
|
||||||
navData := &navData{
|
|
||||||
ld: ld,
|
|
||||||
childrenLoaded: false, // will be loaded dynamically
|
|
||||||
bucketPath: []string{}, // empty = root
|
|
||||||
}
|
|
||||||
ld.nav.SetData(unsafe.Pointer(navData))
|
|
||||||
|
|
||||||
f.dbs = append(f.dbs, ld)
|
|
||||||
|
|
||||||
ld.Keepalive(navData)
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
//+build cgo
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
sqlite3 "github.com/mattn/go-sqlite3"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) DriverName() string {
|
|
||||||
ver1, _, _ := sqlite3.Version()
|
|
||||||
return "SQLite " + ver1
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//+build !cgo
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "modernc.org/sqlite"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (ld *sqliteLoadedDatabase) DriverName() string {
|
|
||||||
return "SQLite (modernc.org)"
|
|
||||||
}
|
|
||||||
115
sqliteclidriver/eventcmd.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
evtypeStdout int = iota
|
||||||
|
evtypeStderr
|
||||||
|
evtypeExit
|
||||||
|
)
|
||||||
|
|
||||||
|
type processEvent struct {
|
||||||
|
evtype int
|
||||||
|
data []byte
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pe processEvent) Error() string {
|
||||||
|
if pe.err != nil {
|
||||||
|
return pe.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
if pe.evtype == evtypeStderr {
|
||||||
|
return string(pe.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<no error>"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pe processEvent) Unwrap() error {
|
||||||
|
return pe.err
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
|
||||||
|
|
||||||
|
pw, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pr, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pe, err := cmd.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
chEvents := make(chan processEvent, 0)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
processEventWorker(pr, evtypeStdout, chEvents)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
processEventWorker(pe, evtypeStderr, chEvents)
|
||||||
|
}()
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// Only call cmd.Wait() after pipes are closed
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
err = cmd.Wait()
|
||||||
|
chEvents <- processEvent{
|
||||||
|
evtype: evtypeExit,
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
|
||||||
|
close(chEvents)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return chEvents, pw, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func processEventWorker(p io.Reader, evtype int, dest chan<- processEvent) {
|
||||||
|
for {
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
n, err := p.Read(buf)
|
||||||
|
|
||||||
|
if n > 0 {
|
||||||
|
dest <- processEvent{
|
||||||
|
evtype: evtype,
|
||||||
|
data: buf[0:n],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
dest <- processEvent{
|
||||||
|
evtype: evtype,
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume all errors are permanent
|
||||||
|
// Ordering can produce either io.EOF, ErrClosedPipe, or PathError{"file already closed"}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
69
sqliteclidriver/eventcmd_test.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEventCmd(t *testing.T) {
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", `echo "hello world"`)
|
||||||
|
|
||||||
|
ch, _, err := ExecEvents(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var consume []processEvent
|
||||||
|
for ev := range ch {
|
||||||
|
consume = append(consume, ev)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect := []processEvent{
|
||||||
|
processEvent{evtype: evtypeStdout, data: []byte("hello world\n")},
|
||||||
|
processEvent{evtype: evtypeStdout, err: io.EOF},
|
||||||
|
processEvent{evtype: evtypeStderr, err: io.EOF},
|
||||||
|
processEvent{evtype: evtypeExit, err: nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.EqualValues(t, expect, consume)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEventCmdStdin(t *testing.T) {
|
||||||
|
cmd := exec.Command("/usr/bin/tr", "a-z", "A-Z")
|
||||||
|
|
||||||
|
ch, pw, err := ExecEvents(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
|
var consume []processEvent
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
for ev := range ch {
|
||||||
|
if ev.err != nil && errors.Is(ev.err, io.EOF) {
|
||||||
|
continue // skip flakey ordering of two EOF statements
|
||||||
|
}
|
||||||
|
consume = append(consume, ev)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
pw.Write([]byte("hello world"))
|
||||||
|
pw.Close()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
expect := []processEvent{
|
||||||
|
processEvent{evtype: evtypeStdout, data: []byte("HELLO WORLD")},
|
||||||
|
processEvent{evtype: evtypeExit, err: nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.EqualValues(t, expect, consume)
|
||||||
|
}
|
||||||
85
sqliteclidriver/orderedkv.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Pair struct {
|
||||||
|
Key string
|
||||||
|
Value any
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderedKV []Pair
|
||||||
|
|
||||||
|
func (o *OrderedKV) UnmarshalJSON(data []byte) error {
|
||||||
|
// Rough estimate malloc size based on number of `:`
|
||||||
|
// This is a lower bound since there might be nested elements
|
||||||
|
var elCount int64
|
||||||
|
for _, c := range data {
|
||||||
|
if c == ':' {
|
||||||
|
elCount += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*o = make([]Pair, 0, elCount)
|
||||||
|
|
||||||
|
// Parse the initial opening { delimiter from the JSON stream
|
||||||
|
|
||||||
|
reader := bytes.NewReader(data)
|
||||||
|
dec := json.NewDecoder(reader)
|
||||||
|
|
||||||
|
tok, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("expected '{': %w", err)
|
||||||
|
}
|
||||||
|
if d, ok := tok.(json.Delim); !ok || (rune(d) != '{') {
|
||||||
|
return fmt.Errorf("expected '{', got %v", tok)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read remaining content
|
||||||
|
|
||||||
|
for dec.More() {
|
||||||
|
|
||||||
|
var p Pair
|
||||||
|
|
||||||
|
// Parse key: either string or Delim('}')
|
||||||
|
tok, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("expected '{': %w", err)
|
||||||
|
}
|
||||||
|
switch tok := tok.(type) {
|
||||||
|
case json.Delim:
|
||||||
|
if rune(tok) == '}' {
|
||||||
|
// Finished
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// Something else
|
||||||
|
return fmt.Errorf("expected string or }, got %v", tok)
|
||||||
|
|
||||||
|
case string:
|
||||||
|
// Valid key
|
||||||
|
p.Key = tok
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("expected string or }, got %v", tok)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse value (any)
|
||||||
|
err = dec.Decode(&p.Value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*o = append(*o, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert that there is no remaining content
|
||||||
|
if reader.Len() != 0 {
|
||||||
|
return fmt.Errorf("Unexpected trailing data (%d bytes remaining)", reader.Len())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done
|
||||||
|
return nil
|
||||||
|
}
|
||||||
30
sqliteclidriver/orderedkv_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOrderedKV(t *testing.T) {
|
||||||
|
|
||||||
|
input := `
|
||||||
|
{
|
||||||
|
"zzz": "foo",
|
||||||
|
"aaa": "bar"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
var got OrderedKV
|
||||||
|
err := json.Unmarshal([]byte(input), &got)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect := OrderedKV{
|
||||||
|
Pair{Key: "zzz", Value: "foo"},
|
||||||
|
Pair{Key: "aaa", Value: "bar"},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.EqualValues(t, expect, got)
|
||||||
|
}
|
||||||
378
sqliteclidriver/sqliteclidriver.go
Normal file
@@ -0,0 +1,378 @@
|
|||||||
|
// sqliteclidriver is a database/sql driver for SQLite implemented on top of
|
||||||
|
// the sqlite3 command-line tool. This allows it to be used over remote SSH
|
||||||
|
// connections.
|
||||||
|
//
|
||||||
|
// Functionality is limited.
|
||||||
|
//
|
||||||
|
// Known caveats:
|
||||||
|
// - Bad error handling
|
||||||
|
// - Few supported types
|
||||||
|
// - Has to escape parameters for CLI instead of preparing them, so not safe for untrusted usage
|
||||||
|
// - No context handling
|
||||||
|
// - No way to configure sqlite3 command line path
|
||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"database/sql/driver"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"yvbolt/lexer"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrNotSupported = errors.New("Not supported")
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCDriver struct{}
|
||||||
|
|
||||||
|
func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
|
||||||
|
// TODO support custom binpath from our connection string
|
||||||
|
|
||||||
|
cmd := exec.Command(`/usr/bin/sqlite3`, `-noheader`, `-json`, connectionString) // n.b. doesn't support `--`
|
||||||
|
|
||||||
|
chEvents, pw, err := ExecEvents(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SCConn{
|
||||||
|
listen: chEvents,
|
||||||
|
w: pw,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Driver = &SCDriver{} // interface assertion
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
sql.Register("sqliteclidriver", &SCDriver{})
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCConnector struct {
|
||||||
|
connectionString string
|
||||||
|
driver *SCDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SCConnector) Connect(context.Context) (driver.Conn, error) {
|
||||||
|
return c.driver.Open(c.connectionString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SCConnector) Driver() driver.Driver {
|
||||||
|
return c.driver
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Connector = &SCConnector{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCConn struct {
|
||||||
|
listen <-chan processEvent
|
||||||
|
w io.WriteCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SCConn) Prepare(query string) (driver.Stmt, error) {
|
||||||
|
f, err := lexer.Fields(query) // Rely on the query's escaping still being present
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(f) == 0 {
|
||||||
|
return nil, errors.New("Empty query")
|
||||||
|
}
|
||||||
|
|
||||||
|
if f[len(f)-1] != ";" {
|
||||||
|
f = append(f, ";") // Query must end in semicolon
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SCStmt{
|
||||||
|
conn: c,
|
||||||
|
query: f,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SCConn) Close() error {
|
||||||
|
return c.w.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SCConn) Begin() (driver.Tx, error) {
|
||||||
|
return nil, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Conn = &SCConn{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCStmt struct {
|
||||||
|
conn *SCConn
|
||||||
|
query []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SCStmt) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SCStmt) NumInput() int {
|
||||||
|
var ct int = 0
|
||||||
|
for _, token := range s.query {
|
||||||
|
if token == `?` {
|
||||||
|
ct++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ct
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SCStmt) buildQuery(args []driver.Value) ([]byte, error) {
|
||||||
|
|
||||||
|
// Embed query params
|
||||||
|
// WARNING: Not secure against injection? That's not a security boundary
|
||||||
|
// for the purposes of yvbolt, but maybe for other package users
|
||||||
|
|
||||||
|
var querybuilder bytes.Buffer
|
||||||
|
|
||||||
|
for _, token := range s.query {
|
||||||
|
if token == `?` {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return nil, errors.New("Not enough arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
arg := args[0]
|
||||||
|
args = args[1:]
|
||||||
|
|
||||||
|
// Format the argument
|
||||||
|
if szarg, ok := arg.(string); ok {
|
||||||
|
querybuilder.WriteString(lexer.Quote(szarg))
|
||||||
|
|
||||||
|
} else if intarg, ok := arg.(int64); ok {
|
||||||
|
querybuilder.WriteString(fmt.Sprintf("%d", intarg))
|
||||||
|
|
||||||
|
} else if flarg, ok := arg.(float64); ok {
|
||||||
|
querybuilder.WriteString(fmt.Sprintf("%f", flarg))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("Parameter %v has unsupported type", arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Normal token
|
||||||
|
querybuilder.WriteString(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whitespace
|
||||||
|
querybuilder.WriteByte(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, errors.New("Too many arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap final whitespace for a \n
|
||||||
|
submit := querybuilder.Bytes()
|
||||||
|
submit[len(submit)-1] = '\n'
|
||||||
|
|
||||||
|
return submit, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SCStmt) Exec(args []driver.Value) (driver.Result, error) {
|
||||||
|
|
||||||
|
submit, err := s.buildQuery(args)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.CopyN(s.conn.w, bytes.NewReader(submit), int64(len(submit)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Write: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drain stdout
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Drain stderr
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return &SCResult{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SCStmt) Query(args []driver.Value) (driver.Rows, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
submit, err := s.buildQuery(args)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are no results to the query, the sqlite3 -json mode does not
|
||||||
|
// print anything on stdout at all and we would hang forever
|
||||||
|
// Add a followup sentinel query that we can detect
|
||||||
|
const sentinelKey = `__sqliteclidriver_sentinel`
|
||||||
|
sentinelVal := uuid.Must(uuid.NewRandom()).String()
|
||||||
|
submit = append(submit, []byte(fmt.Sprintf("SELECT \"%s\" AS %s;\n", sentinelVal, sentinelKey))...)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
_, err = io.CopyN(s.conn.w, bytes.NewReader(submit), int64(len(submit)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Write: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consume process events until either error or the json decoder is satisfied
|
||||||
|
pr, pw := io.Pipe()
|
||||||
|
|
||||||
|
listenContext, listenContextCancel := context.WithCancel(ctx) // Use to stop signalling once json decoder is satisfied
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer pw.Close()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case msg, ok := <-s.conn.listen:
|
||||||
|
if !ok {
|
||||||
|
pw.CloseWithError(fmt.Errorf("process already closed"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if msg.err != nil {
|
||||||
|
pw.CloseWithError(msg.err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.evtype == evtypeStdout {
|
||||||
|
_, err := io.CopyN(pw, bytes.NewReader(msg.data), int64(len(msg.data)))
|
||||||
|
if err != nil {
|
||||||
|
pw.CloseWithError(msg.err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Anything else (process event / stderr)
|
||||||
|
// Throw
|
||||||
|
pw.CloseWithError(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
case <-listenContext.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// We expect some kind of thing on stdout
|
||||||
|
// If something happens on stderr, or to the process, pr will read an error
|
||||||
|
ret := []OrderedKV{}
|
||||||
|
decoder := json.NewDecoder(pr)
|
||||||
|
err = decoder.Decode(&ret)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this was the data or the sentinel
|
||||||
|
wasSentinel := false
|
||||||
|
if len(ret) > 0 && len(ret[0]) > 0 && ret[0][0].Key == sentinelKey {
|
||||||
|
if check, ok := ret[0][0].Value.(string); ok && check == sentinelVal {
|
||||||
|
// It was the sentinel
|
||||||
|
wasSentinel = true
|
||||||
|
// Nothing more to parse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if wasSentinel {
|
||||||
|
// There was no data.
|
||||||
|
// Wipe out `ret`
|
||||||
|
ret = nil
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// There was data.
|
||||||
|
// Need to decode again (from the same decoder reader) until we find the sentinel
|
||||||
|
surplus := []map[string]any{}
|
||||||
|
err = decoder.Decode(&surplus)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listenContextCancel()
|
||||||
|
|
||||||
|
// Drain stderr
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Come up with a canonical ordering for the columns after json.NewDecoder
|
||||||
|
// wiped it out for us
|
||||||
|
// FIXME use a different json parsing library
|
||||||
|
|
||||||
|
var columnNames []string
|
||||||
|
if len(ret) > 0 {
|
||||||
|
for _, cell := range ret[0] {
|
||||||
|
columnNames = append(columnNames, cell.Key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
return &SCRows{
|
||||||
|
idx: 0,
|
||||||
|
columns: columnNames,
|
||||||
|
data: ret,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Stmt = &SCStmt{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCResult struct{}
|
||||||
|
|
||||||
|
func (r *SCResult) LastInsertId() (int64, error) {
|
||||||
|
return 0, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *SCResult) RowsAffected() (int64, error) {
|
||||||
|
return 0, ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Result = &SCResult{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type SCRows struct {
|
||||||
|
idx int
|
||||||
|
columns []string
|
||||||
|
data []OrderedKV
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *SCRows) Columns() []string {
|
||||||
|
return r.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *SCRows) Close() error {
|
||||||
|
r.idx = 0
|
||||||
|
r.data = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *SCRows) Next(dest []driver.Value) error {
|
||||||
|
if r.idx >= len(r.data) {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(dest) != len(r.data[r.idx]) {
|
||||||
|
return errors.New("Wrong number of arguments to Next()")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(dest); i++ {
|
||||||
|
cell := r.data[r.idx][i]
|
||||||
|
|
||||||
|
dest[i] = cell.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
r.idx++
|
||||||
|
return nil
|
||||||
|
}
|
||||||
78
sqliteclidriver/sqliteclidriver_test.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSqliteCliDriver(t *testing.T) {
|
||||||
|
db, err := sql.Open("sqliteclidriver", ":memory:")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = db.Exec(`CREATE TABLE my_test_table ( id INTEGER PRIMARY KEY, extra TEXT NOT NULL );`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = db.Exec(`INSERT INTO my_test_table (id, extra) VALUES ( ? , ? ), ( ? , ? );`, 1337, "abcdef", 9001, "whoop")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Repeat this part to ensure we can make followup queries on the same connection
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
|
||||||
|
res, err := db.Query(`SELECT * FROM my_test_table ORDER BY id ASC;`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
cols, err := res.Columns()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, cols, []string{"id", "extra"})
|
||||||
|
|
||||||
|
var rowCount int = 0
|
||||||
|
|
||||||
|
for res.Next() {
|
||||||
|
rowCount++
|
||||||
|
|
||||||
|
var idVal int
|
||||||
|
var extraVal string
|
||||||
|
err = res.Scan(&idVal, &extraVal)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch rowCount {
|
||||||
|
case 1:
|
||||||
|
require.EqualValues(t, 1337, idVal)
|
||||||
|
require.EqualValues(t, "abcdef", extraVal)
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
require.EqualValues(t, 9001, idVal)
|
||||||
|
require.EqualValues(t, "whoop", extraVal)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, rowCount, 2)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSqliteCliDriverNoResults(t *testing.T) {
|
||||||
|
db, err := sql.Open("sqliteclidriver", ":memory:")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Repeat this part to ensure we can make followup queries on the same connection
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
_, err = db.Query(`SELECT 1 AS expect_no_result WHERE 1=2`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Mix of results and no-results
|
||||||
|
rr := db.QueryRow(`SELECT 1 AS expect_result WHERE 1=1`)
|
||||||
|
require.NoError(t, rr.Err())
|
||||||
|
|
||||||
|
var result int64
|
||||||
|
err = rr.Scan(&result)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, result, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
80
sshTunnel.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SSHTunnel struct {
|
||||||
|
Server autoconfig.AddressPort
|
||||||
|
Username string
|
||||||
|
Password autoconfig.Password
|
||||||
|
PrivateKeyContent autoconfig.MultiLineString
|
||||||
|
PrivateKeyFile autoconfig.ExistingFile
|
||||||
|
PrivateKeyPassword autoconfig.Password
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SSHTunnel) InitDefaults() { // Used by autoconfig package when creating a new value
|
||||||
|
s.Server.Port = 22
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SSHTunnel) String() string {
|
||||||
|
return fmt.Sprintf("ssh://%s@%s:%d", s.Username, s.Server.Address, s.Server.Port)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMaybePasswordedKey(key, passphrase []byte) (ssh.Signer, error) {
|
||||||
|
if len(passphrase) == 0 {
|
||||||
|
return ssh.ParsePrivateKey(key)
|
||||||
|
}
|
||||||
|
return ssh.ParsePrivateKeyWithPassphrase(key, passphrase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SSHTunnel) Open(ctx context.Context) (*ssh.Client, error) {
|
||||||
|
cfg := ssh.ClientConfig{
|
||||||
|
BannerCallback: func(message string) error {
|
||||||
|
resp := qt.QMessageBox_Information7(nil, APPNAME, message, qt.QMessageBox__Ok, qt.QMessageBox__Cancel)
|
||||||
|
if resp != qt.QMessageBox__Ok {
|
||||||
|
return errors.New("SSH connection was cancelled")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(), // FIXME
|
||||||
|
User: s.Username,
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Password != "" {
|
||||||
|
cfg.Auth = append(cfg.Auth, ssh.Password(string(s.Password)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.PrivateKeyContent != "" {
|
||||||
|
signer, err := parseMaybePasswordedKey([]byte(s.PrivateKeyContent), []byte(s.PrivateKeyPassword))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Parsing private key: %w", err)
|
||||||
|
}
|
||||||
|
cfg.Auth = append(cfg.Auth, ssh.PublicKeys(signer))
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.PrivateKeyFile != "" {
|
||||||
|
keyBytes, err := os.ReadFile(string(s.PrivateKeyFile))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Loading private key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
signer, err := parseMaybePasswordedKey(keyBytes, []byte(s.PrivateKeyPassword))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Parsing private key: %w", err)
|
||||||
|
}
|
||||||
|
cfg.Auth = append(cfg.Auth, ssh.PublicKeys(signer))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO DialContext
|
||||||
|
// Use wrapper from https://github.com/golang/go/issues/20288
|
||||||
|
return ssh.Dial("tcp", fmt.Sprintf("%s:%d", s.Server.Address, s.Server.Port), &cfg)
|
||||||
|
}
|
||||||
26
util_types.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// box_interface creates a slice where all elements of the input slice are boxed
|
||||||
|
// in an interface{} type.
|
||||||
|
func box_interface[T any](input []T) []interface{} {
|
||||||
|
ret := make([]interface{}, 0, len(input))
|
||||||
|
for _, v := range input {
|
||||||
|
ret = append(ret, v)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func slice_contains[T comparable](haystack []T, needle T) bool {
|
||||||
|
_, ok := slice_find(haystack, needle)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func slice_find[T comparable](haystack []T, needle T) (int, bool) {
|
||||||
|
for idx, v := range haystack {
|
||||||
|
if v == needle {
|
||||||
|
return idx, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1, false
|
||||||
|
}
|
||||||
30
util_vcl.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
)
|
||||||
|
|
||||||
|
func vcl_clear_grid(grid *qt.QTableWidget) {
|
||||||
|
grid.Clear() // clears header labels
|
||||||
|
grid.SetColumnCount(0) // clears content
|
||||||
|
grid.SetRowCount(0) // clears content
|
||||||
|
grid.SetEnabled(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func vcl_confirm_dialog(parent *qt.QWidget, title string, message string) bool {
|
||||||
|
|
||||||
|
ret := qt.QMessageBox_Question2(parent, title, message,
|
||||||
|
qt.QMessageBox__Apply,
|
||||||
|
qt.QMessageBox__Cancel)
|
||||||
|
|
||||||
|
return ret == int(qt.QMessageBox__Apply)
|
||||||
|
}
|
||||||
|
|
||||||
|
func vcl_grid_set_row_colour(grid *qt.QTableWidget, rowId int, colour *qt.QBrush) {
|
||||||
|
|
||||||
|
numCols := grid.ColumnCount()
|
||||||
|
for i := 0; i < numCols; i++ {
|
||||||
|
cell := grid.Item(rowId, i)
|
||||||
|
cell.SetBackground(colour)
|
||||||
|
}
|
||||||
|
}
|
||||||