MCPcopy
hub / github.com/HKUDS/AI-Trader / DatabaseConnection

Class DatabaseConnection

service/server/database.py:261–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259
260
261class DatabaseConnection:
262 def __init__(self, connection: Any, backend: str):
263 self._connection = connection
264 self._backend = backend
265
266 @property
267 def autocommit(self):
268 return getattr(self._connection, "autocommit", None)
269
270 @autocommit.setter
271 def autocommit(self, value):
272 setattr(self._connection, "autocommit", value)
273
274 def cursor(self):
275 return DatabaseCursor(self._connection.cursor(), self._backend)
276
277 def commit(self):
278 self._connection.commit()
279
280 def rollback(self):
281 self._connection.rollback()
282
283 def close(self):
284 self._connection.close()
285
286 def __enter__(self):
287 return self
288
289 def __exit__(self, exc_type, exc, tb):
290 if exc is not None:
291 try:
292 self.rollback()
293 finally:
294 self.close()
295 return False
296
297 self.commit()
298 self.close()
299 return False
300
301 def __getattr__(self, name: str):
302 return getattr(self._connection, name)
303
304
305def get_db_connection():

Callers 1

get_db_connectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected