Skip to content

Commit

Permalink
Add dummy close method
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriousLearner committed Nov 27, 2024
1 parent 4800bf8 commit 00e0596
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/django_libsql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def convert_query(self, query, param_names=None):
- If `param_names` is None, replace '%s' with '?' (for positional style).
- If `param_names` is provided, convert to named style (e.g., ':param_name').
"""
import re
query = re.sub(r'\bREM\b', '--', query) # Handle REM keyword conflicts

if param_names is None:
# Replace unescaped `%s` with `?` for positional parameter style.
return SQL_PARAM_PLACEHOLDER_REGEX.sub("?", query).replace("%%", "%")
Expand Down Expand Up @@ -156,3 +153,22 @@ def disable_constraint_checking(self):
with self.cursor() as cursor:
cursor.execute("PRAGMA foreign_keys = OFF")
return True

def get_new_connection(self, conn_params):
"""Connect to the database."""
conn = libsql_client.connect(**self.connection_params())
# Add a dummy close method to the connection
conn.close = lambda: None # No-op since libsql connections don't require explicit closing
return conn

def _close(self):
"""Override the close method to handle missing close on connection."""
try:
# Attempt to close the connection if it exists
if self.connection:
self.connection.close()
except AttributeError:
# Ignore since `close` isn't required
pass
finally:
self.connection = None

0 comments on commit 00e0596

Please sign in to comment.