sqlit-provider-redis 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/PKG-INFO +1 -1
  2. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/pyproject.toml +1 -1
  3. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/adapter.py +10 -0
  4. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/tui.py +20 -1
  5. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/tests/test_live.py +3 -0
  6. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/tests/test_tui.py +16 -1
  7. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/.gitignore +0 -0
  8. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/LICENSE +0 -0
  9. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/README.md +0 -0
  10. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/__init__.py +0 -0
  11. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/autoload.py +0 -0
  12. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/bootstrap.py +0 -0
  13. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis/provider.py +0 -0
  14. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/src/sqlit_provider_redis.pth +0 -0
  15. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/tests/conftest.py +0 -0
  16. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/tests/test_adapter.py +0 -0
  17. {sqlit_provider_redis-0.1.0 → sqlit_provider_redis-0.1.1}/tests/test_install.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sqlit-provider-redis
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Redis and Valkey command console provider for sqlit
5
5
  Project-URL: Repository, https://github.com/sudosubin/sqlit-provider-redis
6
6
  Project-URL: Issues, https://github.com/sudosubin/sqlit-provider-redis/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sqlit-provider-redis"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Redis and Valkey command console provider for sqlit"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -208,6 +208,16 @@ class RedisAdapter(DatabaseAdapter):
208
208
  def get_databases(self, conn: Any) -> list[str]:
209
209
  return [str(conn.connection_pool.connection_kwargs.get("db", 0))]
210
210
 
211
+ def get_commands(self, conn: Any) -> dict[str, list[str]]:
212
+ """Map the server's supported command names to their subcommands, for autocomplete."""
213
+ return {
214
+ name.upper(): sorted(
215
+ _plain(sub[0]).partition("|")[2].upper() for sub in info.get("subcommands") or ()
216
+ )
217
+ for name, info in conn.execute_command("COMMAND").items()
218
+ if name.upper() not in _UNSUPPORTED_COMMANDS
219
+ }
220
+
211
221
  def _nothing(self, conn: Any, *args: Any, **kwargs: Any) -> list:
212
222
  return []
213
223
 
@@ -20,6 +20,7 @@ from textual.css.query import NoMatches
20
20
 
21
21
  class RedisValkeyTUI(SSMSTUI):
22
22
  CSS_PATH = Path(inspect.getfile(SSMSTUI)).with_name("main.css")
23
+ _commands: dict[str, list[str]] = {}
23
24
 
24
25
  def _native(self) -> bool:
25
26
  return self.current_provider is not None and self.current_provider.metadata.db_type in {
@@ -36,8 +37,26 @@ class RedisValkeyTUI(SSMSTUI):
36
37
  except NoMatches:
37
38
  pass
38
39
 
40
+ def _on_connect(self) -> None:
41
+ super()._on_connect()
42
+ self._commands = {}
43
+ if self._native():
44
+ # Autocomplete is optional, so a failed load must not stop the app.
45
+ self.run_worker(
46
+ self._load_commands(), group="commands", exclusive=True, exit_on_error=False
47
+ )
48
+
49
+ async def _load_commands(self) -> None:
50
+ adapter = self.current_provider.query_executor
51
+ self._commands = await asyncio.to_thread(adapter.get_commands, self.current_connection)
52
+
39
53
  def _get_autocomplete_suggestions(self, text, cursor_pos):
40
- return [] if self._native() else super()._get_autocomplete_suggestions(text, cursor_pos)
54
+ if not self._native():
55
+ return super()._get_autocomplete_suggestions(text, cursor_pos)
56
+ words = text[:cursor_pos].rpartition("\n")[2].lstrip().split(" ")
57
+ if len(words) == 1:
58
+ return sorted(self._commands) if words[0] else []
59
+ return self._commands.get(words[0].upper(), []) if len(words) == 2 else []
41
60
 
42
61
  def _sql_action(self, name):
43
62
  if self._native():
@@ -53,6 +53,9 @@ def test_command_responses(config_factory, protocol):
53
53
  assert run(command), command
54
54
  assert run("CONFIG GET maxmemory") == [("maxmemory", "0")]
55
55
  assert "tcp_port" in dict(run("INFO server"))
56
+ commands = adapter.get_commands(client)
57
+ assert {"GET", "SET", "HGETALL"} <= set(commands) and "SELECT" not in commands
58
+ assert {"GET", "SET"} <= set(commands["CONFIG"]) and commands["GET"] == []
56
59
 
57
60
 
58
61
  def test_authentication_and_tls(server, config_factory):
@@ -35,7 +35,22 @@ async def test_native_connection_editor_execution_and_alerts(config_factory, ser
35
35
  await app._query_worker.wait()
36
36
  assert app._last_result_rows == [("안녕 a;b",)]
37
37
  assert app.results_table.row_count == 1
38
- assert app._get_autocomplete_suggestions("SE", 2) == []
38
+ for _ in range(50):
39
+ if app._commands:
40
+ break
41
+ await pilot.pause(0.05)
42
+ suggestions = app._get_autocomplete_suggestions("SE", 2)
43
+ assert "SET" in suggestions and "SELECT" not in suggestions
44
+ assert "GET" in app._get_autocomplete_suggestions("config ", 7)
45
+ for text in ("", "GET ", "CONFIG GET "):
46
+ assert app._get_autocomplete_suggestions(text, len(text)) == []
47
+ app.query_input.text = "conf"
48
+ app.query_input.move_cursor((0, 4))
49
+ app._trigger_autocomplete(app.query_input)
50
+ assert app.autocomplete_dropdown.filtered_items == ["CONFIG"]
51
+ app._apply_autocomplete()
52
+ assert app.query_input.text == "CONFIG"
53
+ app.query_input.text = "GET ui-value"
39
54
  app.action_format_query()
40
55
  app.action_delete_row()
41
56
  app.action_edit_cell()