|
sqlite3.Connection|None | _conn = None |
A *thead-local* DB session
Definition at line 39 of file sqlitedb.py.
◆ __init__()
searx.sqlitedb.DBSession.__init__ |
( |
| self, |
|
|
"SQLiteAppl" | app ) |
Definition at line 56 of file sqlitedb.py.
56 def __init__(self, app: "SQLiteAppl"):
57 self.uuid: uuid.UUID = uuid.uuid4()
58 self.app: SQLiteAppl = app
59 self._conn: sqlite3.Connection | None = None
60
61 if getattr(THREAD_LOCAL, "DBSession_map", None) is None:
62 url_to_session: dict[str, DBSession] = {}
63 THREAD_LOCAL.DBSession_map = url_to_session
64 THREAD_LOCAL.DBSession_map[self.app.db_url] = self
65
◆ __del__()
searx.sqlitedb.DBSession.__del__ |
( |
| self | ) |
|
Definition at line 77 of file sqlitedb.py.
77 def __del__(self):
78 try:
79 if self._conn is not None:
80
81
82
83
84
85
86 self._conn.close()
87 except Exception:
88 pass
89
90
References _conn.
◆ conn()
sqlite3.Connection searx.sqlitedb.DBSession.conn |
( |
| self | ) |
|
Definition at line 67 of file sqlitedb.py.
67 def conn(self) -> sqlite3.Connection:
68 msg = f"[{threading.current_thread().ident}] DBSession: " f"{self.app.__class__.__name__}({self.app.db_url})"
69 if self._conn is None:
70 self._conn = self.app.connect()
71 logger.debug("%s --> created new connection", msg)
72
73
74
75 return self._conn
76
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 url_to_session: dict[str, DBSession] = {}
49 THREAD_LOCAL.DBSession_map = url_to_session
50
51 session: DBSession | None = THREAD_LOCAL.DBSession_map.get(app.db_url)
52 if session is None:
53 session = cls(app)
54 return session.conn
55
◆ _conn
sqlite3.Connection | None searx.sqlitedb.DBSession._conn = None |
|
protected |
◆ app
◆ uuid
uuid.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