@@ -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 ()
0 commit comments