@@ -25,15 +25,16 @@ def __init__(
2525 self ,
2626 cloud_account : Optional [SqliteCloudAccount ] = None ,
2727 connection_str : Optional [str ] = None ,
28- # pub_subs: SQCloudPubSubCallback = [],
2928 ) -> None :
3029 """Initializes a new instance of the class with connection information.
3130
3231 Args:
33- connection_str (str): The connection string for the database.
32+ cloud_account (SqliteCloudAccount): The account information for the SQlite Cloud database.
33+ connection_str (str): The connection string for the SQlite Cloud database.
34+ Eg: sqlitecloud://user:[email protected] :port/dbname?timeout=10&apikey=abcd123 3435
3536 """
36- self .driver = Driver ()
37+ self ._driver = Driver ()
3738
3839 self .config = SQCloudConfig ()
3940
@@ -53,18 +54,29 @@ def open_connection(self) -> SQCloudConnect:
5354 Raises:
5455 SQCloudException: If an error occurs while opening the connection.
5556 """
56- connection = self .driver .connect (
57+ connection = self ._driver .connect (
5758 self .config .account .hostname , self .config .account .port , self .config
5859 )
5960
6061 return connection
6162
6263 def disconnect (self , conn : SQCloudConnect ) -> None :
6364 """Close the connection to the database."""
64- self .driver .disconnect (conn )
65+ self ._driver .disconnect (conn )
66+
67+ def is_connected (self , conn : SQCloudConnect ) -> bool :
68+ """Check if the connection is still open.
69+
70+ Args:
71+ conn (SQCloudConnect): The connection to the database.
72+
73+ Returns:
74+ bool: True if the connection is open, False otherwise.
75+ """
76+ return self ._driver .is_connected (conn )
6577
6678 def exec_query (
67- self , query : str , conn : SQCloudConnect = None
79+ self , query : str , conn : SQCloudConnect
6880 ) -> SqliteCloudResultSet :
6981 """Executes a SQL query on the SQLite Cloud database.
7082
@@ -73,15 +85,11 @@ def exec_query(
7385
7486 Returns:
7587 SqliteCloudResultSet: The result set of the executed query.
76- """
77- provided_connection = conn is not None
78- if not provided_connection :
79- conn = self .open_connection ()
80-
81- result = self .driver .execute (query , conn )
8288
83- if not provided_connection :
84- self .disconnect (conn )
89+ Raises:
90+ SQCloudException: If an error occurs while executing the query.
91+ """
92+ result = self ._driver .execute (query , conn )
8593
8694 return SqliteCloudResultSet (result )
8795
@@ -92,7 +100,7 @@ def sendblob(self, blob: bytes, conn: SQCloudConnect) -> SqliteCloudResultSet:
92100 blob (bytes): The blob to be sent to the database.
93101 conn (SQCloudConnect): The connection to the database.
94102 """
95- return self .driver . sendblob (blob , conn )
103+ return self ._driver . send_blob (blob , conn )
96104
97105 def _parse_connection_string (self , connection_string ) -> SQCloudConfig :
98106 # URL STRING FORMAT
0 commit comments