Commit 4831ded
authored
Autocomplete (#46)
* Add smart SQL autocomplete with context-aware suggestions
- New SQL completion engine using sqlparse for context detection
- Suggests tables after FROM/JOIN, columns after WHERE/SELECT, operators after column names
- Lazy loading of columns to avoid UI lag during schema indexing
- Scrollable autocomplete dropdown with keyboard navigation
- Auto-hide when cursor moves away from typing position
- Fuzzy matching and alias resolution support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* fix: prompt for password when connection password is empty
Previously, an empty string password was treated differently from None,
meaning connections with empty passwords would fail instead of prompting
the user. Now both None and empty string trigger the password prompt.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* fix: add Azure SQL Database compatibility for MSSQL adapter
Azure SQL Database does not support cross-database queries or USE
statements. This fix:
- Adds _get_cursor_for_database() that tries USE first (fast for
regular SQL Server), then falls back to creating a new connection
with the target database (for Azure SQL)
- Stores config and driver on connection object for reconnection
- Removes all cross-database reference syntax ([Database].schema.table)
- Updates all adapter methods to use the new approach
Also adds unit tests verifying no cross-database references are used,
and integration tests for Azure SQL Database.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* refactor: split SQL completion into separate modules by statement type
Reorganizes sql_completion.py into a package with separate modules:
- core.py: base classes and utilities
- completion.py: main SQLCompletion class
- alter_table.py, create_table.py, create_index.py, create_view.py,
delete.py, drop.py, insert.py, truncate.py, update.py: statement handlers
Also introduces QueryTextArea widget that wraps TextArea with SQL
autocomplete functionality, simplifying the integration.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* fix: don't show completions without SQL context
- Return empty completions when there's no SQL content yet (just
whitespace). This prevents showing irrelevant keywords when pressing
space/enter on an empty query.
- Add handlers for IN ( and EXISTS ( patterns to suggest SELECT for
subqueries.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* fix: use correct database context when clicking tables in tree
For Azure SQL Database, clicking a table from a different database now
correctly executes the query against that database:
- build_select_query no longer includes [database] prefix (breaks Azure)
- Added _query_target_database to track which database to query
- Query execution uses apply_database_override when target differs
- Target database is cleared after use to not affect user-typed queries
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* fix: use fully qualified table names in autocomplete when no default database
When connected without a default database (multiple databases visible),
autocomplete now suggests fully qualified names like [db].[schema].[table]
instead of just table names. This allows queries to work correctly.
Uses adapter.quote_identifier() for proper quoting (brackets for SQL Server).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
* feat: idle scheduler for background schema loading and UX improvements
Idle Scheduler:
- Add idle scheduler inspired by browser's requestIdleCallback API
- Execute background work during user idle periods (500ms threshold)
- Queue schema loading (tables/views/procedures) as idle jobs
- Add --debug-idle-scheduler flag to show scheduler status bar
- Preload columns for tables found in query editor during idle
Shared Cache:
- Tree and autocomplete now share _db_object_cache for tables/views/procedures
- Expanding tree nodes populates autocomplete cache and vice versa
- Refresh ('f') clears both object cache and column cache
Azure SQL:
- Add separate AzureSQLAdapter with required database field
- Simplify MSSQL adapter by removing Azure-specific fallback logic
Autocomplete UX:
- Add *, DISTINCT, TOP, ALL to SELECT clause completions
- Remove table names from SELECT suggestions (belong after FROM)
- Dropdown stays visible when window loses focus
- Dropdown constrained to stay within bounds (no right-edge cutoff)
* Enter key dismisses autocomplete instead of accepting
- Enter now hides the autocomplete dropdown and inserts a newline
- Only Tab accepts autocomplete suggestions
- Added suppress flag to prevent autocomplete from re-triggering
after Enter dismisses it (newline text change was re-showing dropdown)
* Persist active database preference across sessions
Introduces _active_database separate from current_config.database to
preserve tree structure while allowing users to set a preferred database.
- Added get/set_database_preference() to config.py for persistence
- On connect: load cached preference into _active_database
- On 'u' press: save preference and reload schema for new database
- On disconnect: clear _active_database
- Star display in tree now uses _active_database
- Autocomplete schema loading now respects _active_database
The connection config (and tree structure) remains unchanged - only the
user's runtime preference is cached in settings.json.
* Add system_databases property per adapter and fix ESC behavior
- Add system_databases property to DatabaseAdapter base class
- Define system databases for each adapter:
- MSSQL: master, tempdb, model, msdb
- PostgreSQL: template0, template1
- MySQL/MariaDB: mysql, information_schema, performance_schema, sys
- ClickHouse: system, information_schema
- Snowflake: SNOWFLAKE
- Update autocomplete to filter using adapter.system_databases
- ESC key now closes autocomplete AND exits to normal mode
- Add unit tests for system_databases property
* Fix ESC key priority on modal screens
Add priority=True to escape bindings on all modal screens to ensure
ESC key is handled correctly when other bindings are active.
* Fix error display in results table
Flatten multi-line error messages to single line since DataTable cells
only display one line. Replaces textwrap with regex whitespace collapse.
* Add supports_cross_database_queries property and auto-switch databases
- Add supports_cross_database_queries property to DatabaseAdapter
- Returns True for MSSQL, MySQL, ClickHouse, Snowflake (support USE)
- Returns False for PostgreSQL, CockroachDB, D1 (require reconnection)
- Add switch_database() method to ConnectionSession for reconnecting
to a different database while reusing SSH tunnel
- Auto-switch database when expanding database nodes or their contents
- For cross-db adapters: sets active database (USE approach)
- For non-cross-db adapters: reconnects to the database
- Falls back to reconnection if USE fails (e.g., Azure SQL)
- Remove 'u' keybinding - Enter on database node now sets it active
- Apply active database to query execution context
- Add helper functions in providers.py for database requirement checks
- Update tests with new mock attributes
* Remove Azure SQL adapter - use MSSQL with automatic fallback
Azure SQL is now handled by the MSSQL adapter with automatic fallback:
- If USE statement fails, automatically reconnect to target database
- Retry the operation after reconnection
- Show original error only if reconnection also fails
This makes Azure SQL work transparently without a separate adapter.
* Handle cross-db capability in autocomplete
* Handle ESC in leader menu
* Add tests for autocomplete database modes
* Add autocomplete demo gifs
* Hide autocomplete after statement terminator (semicolon)
Previously, typing a semicolon after a complete statement would show
irrelevant suggestions (tables or keywords). Now the autocomplete
popup hides when the cursor is immediately after a semicolon.
* Remove db caching
* Fix password prompt for explicitly empty passwords
- Only prompt for password when password is None (not set), not when
it's an empty string (explicitly set to empty)
- Some databases allow passwordless connections, so "" should be valid
- Remove Azure SQL adapter tests (adapter was removed)
---------
Co-authored-by: Peter Adams <18162810+Maxteabag@users.noreply.github.com>1 parent 168efe4 commit 4831ded
File tree
64 files changed
+7758
-358
lines changed- demos
- sqlit
- db
- adapters
- services
- sql_completion
- ui
- mixins
- screens
- tests
- ui/explorer
- unit
- sql_completion
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
64 files changed
+7758
-358
lines changedLoading
Loading
Loading
Loading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
211 | 225 | | |
212 | 226 | | |
213 | 227 | | |
| |||
260 | 274 | | |
261 | 275 | | |
262 | 276 | | |
263 | | - | |
264 | 277 | | |
265 | 278 | | |
266 | 279 | | |
| |||
297 | 310 | | |
298 | 311 | | |
299 | 312 | | |
| 313 | + | |
300 | 314 | | |
301 | 315 | | |
302 | 316 | | |
| |||
355 | 369 | | |
356 | 370 | | |
357 | 371 | | |
358 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
359 | 375 | | |
360 | 376 | | |
361 | 377 | | |
| |||
387 | 403 | | |
388 | 404 | | |
389 | 405 | | |
390 | | - | |
391 | | - | |
| 406 | + | |
| 407 | + | |
392 | 408 | | |
393 | 409 | | |
394 | 410 | | |
| |||
416 | 432 | | |
417 | 433 | | |
418 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
419 | 439 | | |
420 | 440 | | |
421 | 441 | | |
| |||
509 | 529 | | |
510 | 530 | | |
511 | 531 | | |
512 | | - | |
| 532 | + | |
513 | 533 | | |
514 | 534 | | |
515 | 535 | | |
| |||
521 | 541 | | |
522 | 542 | | |
523 | 543 | | |
| 544 | + | |
524 | 545 | | |
525 | 546 | | |
526 | 547 | | |
| |||
531 | 552 | | |
532 | 553 | | |
533 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
534 | 564 | | |
535 | 565 | | |
536 | 566 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
164 | 169 | | |
165 | 170 | | |
166 | 171 | | |
| |||
284 | 289 | | |
285 | 290 | | |
286 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
287 | 296 | | |
288 | 297 | | |
289 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
185 | 201 | | |
186 | 202 | | |
187 | 203 | | |
188 | 204 | | |
189 | 205 | | |
190 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
191 | 216 | | |
192 | 217 | | |
193 | 218 | | |
| |||
250 | 275 | | |
251 | 276 | | |
252 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
253 | 282 | | |
254 | 283 | | |
255 | 284 | | |
| |||
567 | 596 | | |
568 | 597 | | |
569 | 598 | | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
570 | 603 | | |
571 | 604 | | |
572 | 605 | | |
| |||
821 | 854 | | |
822 | 855 | | |
823 | 856 | | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
824 | 866 | | |
825 | 867 | | |
826 | 868 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
0 commit comments