Skip to content

Commit

Permalink
Implement code attribute for Python connections (#2932)
Browse files Browse the repository at this point in the history
* Implement code attribute for Python connections

* Add line magic to automatic connect to the connections pane.
  • Loading branch information
dfalbel authored May 3, 2024
1 parent f42bdc6 commit 9ffa488
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ def __init__(self, conn: sqlite3.Connection):
self.display_name = "SQLite Connection"
self.host = self._find_path(conn)
self.type = "SQLite"
self.code = (
"import sqlite3\n" f'conn = sqlite3.connect("{self.host}")\n' "%connection_show conn\n"
)

def _find_path(self, conn: sqlite3.Connection):
"""
Expand Down Expand Up @@ -594,6 +597,11 @@ def __init__(self, conn):
self.display_name = f"SQLAlchemy ({conn.name})"
self.host = conn.url.render_as_string()
self.type = "SQLAlchemy"
self.code = (
"import sqlalchemy\n"
f"engine = sqlalchemy.create_engine('{self.host}')\n"
"%connection_show engine\n"
)

def list_objects(self, path: List[ObjectSchema]):
if sqlalchemy_ is None:
Expand Down

0 comments on commit 9ffa488

Please sign in to comment.