MCPcopy
hub / github.com/ModelEngine-Group/nexent / get_db_session

Function get_db_session

backend/database/client.py:304–321  ·  view source on GitHub ↗

param db_session: Optional session to use, if None, a new session will be created. Provide a transactional scope around a series of operations.

(db_session=None)

Source from the content-addressed store, hash-verified

302
303@contextmanager
304def get_db_session(db_session=None):
305 """
306 param db_session: Optional session to use, if None, a new session will be created.
307 Provide a transactional scope around a series of operations.
308 """
309 session = db_client.session_maker() if db_session is None else db_session
310 try:
311 yield session
312 if db_session is None:
313 session.commit()
314 except Exception as e:
315 if db_session is None:
316 session.rollback()
317 logger.error(f"Database operation failed: {str(e)}")
318 raise e
319 finally:
320 if db_session is None:
321 session.close()
322
323
324def as_dict(obj):

Callers 15

get_tenant_config_infoFunction · 0.90
get_single_config_infoFunction · 0.90
insert_configFunction · 0.90
delete_configFunction · 0.90
get_all_tenant_idsFunction · 0.90
query_invitation_by_codeFunction · 0.90
query_invitation_by_idFunction · 0.90

Calls 4

commitMethod · 0.80
rollbackMethod · 0.80
errorMethod · 0.80
closeMethod · 0.45