Skip to content

Commit 3a41859

Browse files
authored
Merge pull request #6 from rich-iannone/feat-db-sql-mode
feat: Add DB/SQL mode
2 parents e034544 + fb00d6a commit 3a41859

File tree

4 files changed

+2678
-432
lines changed

4 files changed

+2678
-432
lines changed

sweet/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
@click.command()
1111
@click.version_option()
1212
@click.option("--file", "-f", type=click.Path(exists=True), help="Load data file on startup")
13-
def main(file: str | None):
13+
@click.option(
14+
"--db", type=str, help="Connect to remote database (e.g., mysql://user:pass@host:port/db)"
15+
)
16+
def main(file: str | None, db: str | None):
1417
"""Sweet - Interactive data engineering CLI utility."""
1518
try:
1619
# Check if data is being piped from stdin
@@ -51,6 +54,9 @@ def main(file: str | None):
5154
Path(file).unlink()
5255
except OSError:
5356
pass
57+
elif db:
58+
click.echo(f"Starting Sweet with database: {db}")
59+
run_app(startup_db=db)
5460
else:
5561
click.echo("Starting Sweet...")
5662
run_app()

sweet/ui/app.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ class SweetApp(App):
4848
Binding("f1", "show_command_reference", "Command Reference", show=True),
4949
]
5050

51-
def __init__(self, startup_file: str | None = None, **kwargs):
52-
"""Initialize the app with optional startup file."""
51+
def __init__(self, startup_file: str | None = None, startup_db: str | None = None, **kwargs):
52+
"""Initialize the app with optional startup file or database connection."""
5353
super().__init__(**kwargs)
5454
self.startup_file = startup_file
55+
self.startup_db = startup_db
5556
self.command_mode = False
5657
self.current_filename = None
5758
self._update_title()
@@ -84,6 +85,11 @@ def on_mount(self) -> None:
8485
self._data_grid.load_file(self.startup_file)
8586
# Set the current filename and update title
8687
self.set_current_filename(self.startup_file)
88+
elif self.startup_db:
89+
# If a database connection string was provided, connect to it
90+
self._data_grid.connect_to_database(self.startup_db)
91+
# Set the connection info and update title
92+
self.set_current_filename(f"Database: {self.startup_db}")
8793

8894
def _update_title(self) -> None:
8995
"""Update the window title with current filename."""
@@ -399,7 +405,7 @@ def action_quit(self) -> None:
399405
self.exit()
400406

401407

402-
def run_app(startup_file: str | None = None) -> None:
408+
def run_app(startup_file: str | None = None, startup_db: str | None = None) -> None:
403409
"""Run the Sweet application."""
404-
app = SweetApp(startup_file=startup_file)
410+
app = SweetApp(startup_file=startup_file, startup_db=startup_db)
405411
app.run()

sweet/ui/sweet.tcss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,8 @@ ToolsPanel #llm-transform-content {
693693
ToolsPanel .panel-section {
694694
height: 1fr;
695695
}
696+
697+
/* Green border for approval-ready SQL code */
698+
.approval-ready {
699+
border: solid green;
700+
}

0 commit comments

Comments
 (0)