A *thead-local* DB session
Definition at line 39 of file sqlitedb.py.
◆ __init__()
searx.sqlitedb.DBSession.__init__ |
( |
| self, |
|
|
SQLiteAppl | app ) |
Definition at line 55 of file sqlitedb.py.
55 def __init__(self, app: SQLiteAppl):
56 self.uuid = uuid.uuid4()
57 self.app = app
58 self._conn = None
59
60 if getattr(THREAD_LOCAL, "DBSession_map", None) is None:
61 THREAD_LOCAL.DBSession_map = {}
62 THREAD_LOCAL.DBSession_map[self.app.db_url] = self
63
◆ __del__()
searx.sqlitedb.DBSession.__del__ |
( |
| self | ) |
|
Definition at line 75 of file sqlitedb.py.
75 def __del__(self):
76 try:
77 if self._conn is not None:
78
79
80
81
82
83
84 self._conn.close()
85 except Exception:
86 pass
87
88
References _conn.
◆ conn()
sqlite3.Connection searx.sqlitedb.DBSession.conn |
( |
| self | ) |
|
Definition at line 65 of file sqlitedb.py.
65 def conn(self) -> sqlite3.Connection:
66 msg = f"[{threading.current_thread().ident}] DBSession: " f"{self.app.__class__.__name__}({self.app.db_url})"
67 if self._conn is None:
68 self._conn = self.app.connect()
69 logger.debug("%s --> created new connection", msg)
70
71
72
73 return self._conn
74
References _conn, and app.
◆ get_connect()
sqlite3.Connection searx.sqlitedb.DBSession.get_connect |
( |
| cls, |
|
|
SQLiteAppl | app ) |
Returns a thread local DB connection. The connection is only
established once per thread.
Definition at line 43 of file sqlitedb.py.
43 def get_connect(cls, app: SQLiteAppl) -> sqlite3.Connection:
44 """Returns a thread local DB connection. The connection is only
45 established once per thread.
46 """
47 if getattr(THREAD_LOCAL, "DBSession_map", None) is None:
48 THREAD_LOCAL.DBSession_map = {}
49
50 session = THREAD_LOCAL.DBSession_map.get(app.db_url)
51 if session is None:
52 session = cls(app)
53 return session.conn
54
◆ _conn
searx.sqlitedb.DBSession._conn = None |
|
protected |
◆ app
searx.sqlitedb.DBSession.app = app |
◆ uuid
searx.sqlitedb.DBSession.uuid = uuid.uuid4() |
The documentation for this class was generated from the following file:
- /home/andrew/Documents/code/public/searxng/searx/sqlitedb.py