Skip to content

Revert to FavoriteQueries singleton #1335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
1.38.0 (2025/08/19)
1.38.2 (2025/08/19)
======================

Bug Fixes
--------
* Fix failure to save Favorite Queries.


1.38.1 (2025/08/19)
======================

Bug Fixes
Expand Down
3 changes: 3 additions & 0 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from mycli.packages.hybrid_redirection import get_redirect_components, is_redirect_command
from mycli.packages.parseutils import is_destructive, is_dropping_database
from mycli.packages.prompt_utils import confirm, confirm_destructive_query
from mycli.packages.special.favoritequeries import FavoriteQueries
from mycli.packages.special.main import ArgType
from mycli.packages.tabular_output import sql_format
from mycli.packages.toolkit.history import FileHistoryWithTimestamp
Expand Down Expand Up @@ -132,6 +133,8 @@ def __init__(
special.set_timing_enabled(c["main"].as_bool("timing"))
self.beep_after_seconds = float(c["main"]["beep_after_seconds"] or 0)

FavoriteQueries.instance = FavoriteQueries.from_config(self.config)

self.dsn_alias: str | None = None
self.main_formatter = TabularOutputFormatter(format_name=c["main"]["table_format"])
self.redirect_formatter = TabularOutputFormatter(format_name=c["main"].get("redirect_format", "csv"))
Expand Down
14 changes: 7 additions & 7 deletions mycli/packages/special/iocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def execute_favorite_query(cur: Cursor, arg: str, **_) -> Generator[tuple, None,
name, _separator, arg_str = arg.partition(" ")
args = shlex.split(arg_str)

query = favoritequeries.get(name)
query = FavoriteQueries.instance.get(name)
if query is None:
message = f"No favorite query: {name}"
yield (None, None, None, message)
Expand All @@ -274,10 +274,10 @@ def list_favorite_queries() -> list[tuple]:
Returns (title, rows, headers, status)"""

headers = ["Name", "Query"]
rows = [(r, favoritequeries.get(r)) for r in favoritequeries.list()]
rows = [(r, FavoriteQueries.instance.get(r)) for r in FavoriteQueries.instance.list()]

if not rows:
status = "\nNo favorite queries found." + favoritequeries.usage
status = "\nNo favorite queries found." + FavoriteQueries.instance.usage
else:
status = ""
return [("", rows, headers, status)]
Expand All @@ -304,7 +304,7 @@ def save_favorite_query(arg: str, **_) -> list[tuple]:
"""Save a new favorite query.
Returns (title, rows, headers, status)"""

usage = "Syntax: \\fs name query.\n\n" + favoritequeries.usage
usage = "Syntax: \\fs name query.\n\n" + FavoriteQueries.instance.usage
if not arg:
return [(None, None, None, usage)]

Expand All @@ -314,18 +314,18 @@ def save_favorite_query(arg: str, **_) -> list[tuple]:
if (not name) or (not query):
return [(None, None, None, usage + "Err: Both name and query are required.")]

favoritequeries.save(name, query)
FavoriteQueries.instance.save(name, query)
return [(None, None, None, "Saved.")]


@special_command("\\fd", "\\fd [name]", "Delete a favorite query.")
def delete_favorite_query(arg: str, **_) -> list[tuple]:
"""Delete an existing favorite query."""
usage = "Syntax: \\fd name.\n\n" + favoritequeries.usage
usage = "Syntax: \\fd name.\n\n" + FavoriteQueries.instance.usage
if not arg:
return [(None, None, None, usage)]

status = favoritequeries.delete(arg)
status = FavoriteQueries.instance.delete(arg)

return [(None, None, None, status)]

Expand Down