searx.sqlitedb.html 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>SQLite DB &#8212; SearXNG Documentation (2025.5.31+93751b637)</title>
  8. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=6625fa76" />
  9. <link rel="stylesheet" type="text/css" href="../_static/searxng.css?v=52e4ff28" />
  10. <script src="../_static/documentation_options.js?v=275a1f99"></script>
  11. <script src="../_static/doctools.js?v=9a2dae69"></script>
  12. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  13. <script data-project="searxng" data-version="2025.5.31+93751b637" src="../_static/describe_version.js?v=fa7f30d0"></script>
  14. <link rel="index" title="Index" href="../genindex.html" />
  15. <link rel="search" title="Search" href="../search.html" />
  16. <link rel="next" title="Utility functions for the engines" href="searx.utils.html" />
  17. <link rel="prev" title="Settings Loader" href="searx.settings.html" />
  18. </head><body>
  19. <div class="related" role="navigation" aria-label="Related">
  20. <h3>Navigation</h3>
  21. <ul>
  22. <li class="right" style="margin-right: 10px">
  23. <a href="../genindex.html" title="General Index"
  24. accesskey="I">index</a></li>
  25. <li class="right" >
  26. <a href="../py-modindex.html" title="Python Module Index"
  27. >modules</a> |</li>
  28. <li class="right" >
  29. <a href="searx.utils.html" title="Utility functions for the engines"
  30. accesskey="N">next</a> |</li>
  31. <li class="right" >
  32. <a href="searx.settings.html" title="Settings Loader"
  33. accesskey="P">previous</a> |</li>
  34. <li class="nav-item nav-item-0"><a href="../index.html">SearXNG Documentation (2025.5.31+93751b637)</a> &#187;</li>
  35. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Source-Code</a> &#187;</li>
  36. <li class="nav-item nav-item-this"><a href="">SQLite DB</a></li>
  37. </ul>
  38. </div>
  39. <div class="document">
  40. <div class="documentwrapper">
  41. <div class="bodywrapper">
  42. <div class="body" role="main">
  43. <section id="sqlite-db">
  44. <span id="id1"></span><h1>SQLite DB<a class="headerlink" href="#sqlite-db" title="Link to this heading">¶</a></h1>
  45. <p id="module-searx.sqlitedb">Implementations to make access to SQLite databases a little more convenient.</p>
  46. <dl class="simple">
  47. <dt><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl" title="searx.sqlitedb.SQLiteAppl"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl</span></code></a></dt><dd><p>Abstract class with which DB applications can be implemented.</p>
  48. </dd>
  49. <dt><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties" title="searx.sqlitedb.SQLiteProperties"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteProperties</span></code></a>:</dt><dd><p>Class to manage properties stored in a database.</p>
  50. </dd>
  51. </dl>
  52. <p>Examplarical implementations based on <a class="reference internal" href="#searx.sqlitedb.SQLiteAppl" title="searx.sqlitedb.SQLiteAppl"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl</span></code></a>:</p>
  53. <dl class="simple">
  54. <dt><a class="reference internal" href="searx.cache.html#searx.cache.ExpireCacheSQLite" title="searx.cache.ExpireCacheSQLite"><code class="xref py py-obj docutils literal notranslate"><span class="pre">searx.cache.ExpireCacheSQLite</span></code></a> :</dt><dd><p>Cache that manages key/value pairs in a SQLite DB, in which the key/value
  55. pairs are deleted after an “expire” time. This type of cache is used, for
  56. example, for the engines, see <a class="reference internal" href="../dev/engines/enginelib.html#searx.enginelib.EngineCache" title="searx.enginelib.EngineCache"><code class="xref py py-obj docutils literal notranslate"><span class="pre">searx.enginelib.EngineCache</span></code></a>.</p>
  57. </dd>
  58. <dt><a class="reference internal" href="searx.favicons.html#searx.favicons.cache.FaviconCacheSQLite" title="searx.favicons.cache.FaviconCacheSQLite"><code class="xref py py-obj docutils literal notranslate"><span class="pre">searx.favicons.cache.FaviconCacheSQLite</span></code></a> :</dt><dd><p>Favicon cache that manages the favicon BLOBs in a SQLite DB.</p>
  59. </dd>
  60. </dl>
  61. <hr class="docutils" />
  62. <dl class="py class">
  63. <dt class="sig sig-object py" id="searx.sqlitedb.DBSession">
  64. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">searx.sqlitedb.</span></span><span class="sig-name descname"><span class="pre">DBSession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl" title="searx.sqlitedb.SQLiteAppl"><span class="pre">SQLiteAppl</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#DBSession"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.DBSession" title="Link to this definition">¶</a></dt>
  65. <dd><p>A <em>thead-local</em> DB session</p>
  66. <dl class="py method">
  67. <dt class="sig sig-object py" id="searx.sqlitedb.DBSession.get_connect">
  68. <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">get_connect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl" title="searx.sqlitedb.SQLiteAppl"><span class="pre">SQLiteAppl</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection" title="(in Python v3.13)"><span class="pre">Connection</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#DBSession.get_connect"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.DBSession.get_connect" title="Link to this definition">¶</a></dt>
  69. <dd><p>Returns a thread local DB connection. The connection is only
  70. established once per thread.</p>
  71. </dd></dl>
  72. </dd></dl>
  73. <dl class="py class">
  74. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl">
  75. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">searx.sqlitedb.</span></span><span class="sig-name descname"><span class="pre">SQLiteAppl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">db_url</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteAppl"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl" title="Link to this definition">¶</a></dt>
  76. <dd><p>Abstract base class for implementing convenient DB access in SQLite
  77. applications. In the constructor, a <a class="reference internal" href="#searx.sqlitedb.SQLiteProperties" title="searx.sqlitedb.SQLiteProperties"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteProperties</span></code></a> instance is
  78. already aggregated under <code class="docutils literal notranslate"><span class="pre">self.properties</span></code>.</p>
  79. <dl class="py attribute">
  80. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.DB_SCHEMA">
  81. <span class="sig-name descname"><span class="pre">DB_SCHEMA</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">1</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.DB_SCHEMA" title="Link to this definition">¶</a></dt>
  82. <dd><p>As soon as changes are made to the DB schema, the version number must be
  83. increased. Changes to the version number require the DB to be recreated (or
  84. migrated / if an migration path exists and is implemented).</p>
  85. </dd></dl>
  86. <dl class="py attribute">
  87. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE">
  88. <span class="sig-name descname"><span class="pre">SQLITE_THREADING_MODE</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'serialized'</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE" title="Link to this definition">¶</a></dt>
  89. <dd><p>Threading mode of the SQLite library. Depends on the options used at
  90. compile time and is different for different distributions and architectures.</p>
  91. <p>Possible values are 0:<code class="docutils literal notranslate"><span class="pre">single-thread</span></code>, 1:<code class="docutils literal notranslate"><span class="pre">multi-thread</span></code>,
  92. 3:<code class="docutils literal notranslate"><span class="pre">serialized</span></code> (see <a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.threadsafety" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sqlite3.threadsafety</span></code></a>). Pre- Python 3.11
  93. this value was hard coded to 1.</p>
  94. <p>Depending on this value, optimizations are made, e.g. in “serialized” mode
  95. it is not necessary to create a separate DB connector for each thread.</p>
  96. </dd></dl>
  97. <dl class="py attribute">
  98. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.SQLITE_JOURNAL_MODE">
  99. <span class="sig-name descname"><span class="pre">SQLITE_JOURNAL_MODE</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'WAL'</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.SQLITE_JOURNAL_MODE" title="Link to this definition">¶</a></dt>
  100. <dd><p><code class="docutils literal notranslate"><span class="pre">SQLiteAppl</span></code> applications are optimized for <a class="reference external" href="https://sqlite.org/wal.html">WAL</a> mode, its not recommend
  101. to change the journal mode (see <code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl.tear_down</span></code>).</p>
  102. </dd></dl>
  103. <dl class="py attribute">
  104. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.SQLITE_CONNECT_ARGS">
  105. <span class="sig-name descname"><span class="pre">SQLITE_CONNECT_ARGS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{'cached_statements':</span> <span class="pre">0,</span> <span class="pre">'check_same_thread':</span> <span class="pre">False,</span> <span class="pre">'isolation_level':</span> <span class="pre">None}</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.SQLITE_CONNECT_ARGS" title="Link to this definition">¶</a></dt>
  106. <dd><p>Connection arguments (<a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.connect" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sqlite3.connect</span></code></a>)</p>
  107. <dl>
  108. <dt><code class="docutils literal notranslate"><span class="pre">check_same_thread</span></code>:</dt><dd><p>Is disabled by default when <a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE" title="searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLITE_THREADING_MODE</span></code></a> is
  109. <code class="docutils literal notranslate"><span class="pre">serialized</span></code>. The check is more of a hindrance in this case because it
  110. would prevent a DB connector from being used in multiple threads.</p>
  111. </dd>
  112. <dt><code class="docutils literal notranslate"><span class="pre">cached_statements</span></code>:</dt><dd><p>Is set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by default. Note: Python 3.12+ fetch result are not
  113. consistent in multi-threading application and causing an API misuse error.</p>
  114. <p>The multithreading use in SQLiteAppl is intended and supported if
  115. threadsafety is set to 3 (aka “serialized”). CPython supports “serialized”
  116. from version 3.12 on, but unfortunately only with errors:</p>
  117. <ul class="simple">
  118. <li><p><a class="reference external" href="https://github.com/python/cpython/issues/118172">https://github.com/python/cpython/issues/118172</a></p></li>
  119. <li><p><a class="reference external" href="https://github.com/python/cpython/issues/123873">https://github.com/python/cpython/issues/123873</a></p></li>
  120. </ul>
  121. <p>The workaround for SQLite3 multithreading cache inconsistency is to set
  122. option <code class="docutils literal notranslate"><span class="pre">cached_statements</span></code> to <code class="docutils literal notranslate"><span class="pre">0</span></code> by default.</p>
  123. </dd>
  124. </dl>
  125. </dd></dl>
  126. <dl class="py method">
  127. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.connect">
  128. <span class="sig-name descname"><span class="pre">connect</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection" title="(in Python v3.13)"><span class="pre">Connection</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteAppl.connect"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.connect" title="Link to this definition">¶</a></dt>
  129. <dd><p>Creates a new DB connection (<a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_CONNECT_ARGS" title="searx.sqlitedb.SQLiteAppl.SQLITE_CONNECT_ARGS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLITE_CONNECT_ARGS</span></code></a>). If not
  130. already done, the DB schema is set up. The caller must take care of
  131. closing the resource. Alternatively, <a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.DB" title="searx.sqlitedb.SQLiteAppl.DB"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl.DB</span></code></a> can also
  132. be used (the resource behind <cite>self.DB</cite> is automatically closed when the
  133. process or thread is terminated).</p>
  134. </dd></dl>
  135. <dl class="py method">
  136. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.register_functions">
  137. <span class="sig-name descname"><span class="pre">register_functions</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">conn</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteAppl.register_functions"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.register_functions" title="Link to this definition">¶</a></dt>
  138. <dd><p>Create <a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function">user-defined</a> SQL functions.</p>
  139. <dl>
  140. <dt><code class="docutils literal notranslate"><span class="pre">REGEXP(&lt;pattern&gt;,</span> <span class="pre">&lt;field&gt;)</span></code><span class="classifier">0 | 1</span></dt><dd><p><a class="reference external" href="https://docs.python.org/3/library/re.html#re.search">re.search</a> returns (int) 1 for a match and 0 for none match of
  141. <code class="docutils literal notranslate"><span class="pre">&lt;pattern&gt;</span></code> in <code class="docutils literal notranslate"><span class="pre">&lt;field&gt;</span></code>.</p>
  142. <div class="highlight-sql notranslate"><div class="highlight"><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="s1">&#39;12&#39;</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="n">field</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">REGEXP</span><span class="p">(</span><span class="s1">&#39;^[0-9][0-9]$&#39;</span><span class="p">,</span><span class="w"> </span><span class="n">field</span><span class="p">)</span>
  143. <span class="c1">-- 12</span>
  144. <span class="k">SELECT</span><span class="w"> </span><span class="n">REGEXP</span><span class="p">(</span><span class="s1">&#39;[0-9][0-9]&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;X12Y&#39;</span><span class="p">)</span>
  145. <span class="c1">-- 1</span>
  146. <span class="k">SELECT</span><span class="w"> </span><span class="n">REGEXP</span><span class="p">(</span><span class="s1">&#39;[0-9][0-9]&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;X1Y&#39;</span><span class="p">)</span>
  147. <span class="c1">-- 0</span>
  148. </pre></div>
  149. </div>
  150. </dd>
  151. </dl>
  152. </dd></dl>
  153. <dl class="py property">
  154. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.DB">
  155. <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">DB</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection" title="(in Python v3.13)"><span class="pre">Connection</span></a></em><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.DB" title="Link to this definition">¶</a></dt>
  156. <dd><p>Provides a DB connection. The connection is a <em>singleton</em> and
  157. therefore well suited for read access. If
  158. <a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE" title="searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLITE_THREADING_MODE</span></code></a> is <code class="docutils literal notranslate"><span class="pre">serialized</span></code> only one DB connection
  159. is created for all threads.</p>
  160. <div class="admonition note">
  161. <p class="admonition-title">Note</p>
  162. <p>For dedicated <a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3-controlling-transactions">transaction control</a>, it is recommended to create a
  163. new connection (<a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.connect" title="searx.sqlitedb.SQLiteAppl.connect"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl.connect</span></code></a>).</p>
  164. </div>
  165. </dd></dl>
  166. <dl class="py method">
  167. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteAppl.init">
  168. <span class="sig-name descname"><span class="pre">init</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">conn</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection" title="(in Python v3.13)"><span class="pre">Connection</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteAppl.init"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteAppl.init" title="Link to this definition">¶</a></dt>
  169. <dd><p>Initializes the DB schema and properties, is only executed once even
  170. if called several times.</p>
  171. <p>If the initialization has not yet taken place, it is carried out and a
  172. <cite>True</cite> is returned to the caller at the end. If the initialization has
  173. already been carried out in the past, <cite>False</cite> is returned.</p>
  174. </dd></dl>
  175. </dd></dl>
  176. <dl class="py class">
  177. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties">
  178. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">searx.sqlitedb.</span></span><span class="sig-name descname"><span class="pre">SQLiteProperties</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">db_url</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties" title="Link to this definition">¶</a></dt>
  179. <dd><p>Simple class to manage properties of a DB application in the DB. The
  180. object has its own DB connection and transaction area.</p>
  181. <div class="highlight-sql notranslate"><div class="highlight"><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">properties</span><span class="w"> </span><span class="p">(</span>
  182. <span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="nb">TEXT</span><span class="p">,</span>
  183. <span class="w"> </span><span class="n">value</span><span class="w"> </span><span class="nb">TEXT</span><span class="p">,</span>
  184. <span class="w"> </span><span class="n">m_time</span><span class="w"> </span><span class="nb">INTEGER</span><span class="w"> </span><span class="k">DEFAULT</span><span class="w"> </span><span class="p">(</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%s&#39;</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;now&#39;</span><span class="p">)),</span>
  185. <span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
  186. </pre></div>
  187. </div>
  188. <dl class="py attribute">
  189. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.SQLITE_JOURNAL_MODE">
  190. <span class="sig-name descname"><span class="pre">SQLITE_JOURNAL_MODE</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'WAL'</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.SQLITE_JOURNAL_MODE" title="Link to this definition">¶</a></dt>
  191. <dd><p><code class="docutils literal notranslate"><span class="pre">SQLiteAppl</span></code> applications are optimized for <a class="reference external" href="https://sqlite.org/wal.html">WAL</a> mode, its not recommend
  192. to change the journal mode (see <code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLiteAppl.tear_down</span></code>).</p>
  193. </dd></dl>
  194. <dl class="py attribute">
  195. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.DDL_PROPERTIES">
  196. <span class="sig-name descname"><span class="pre">DDL_PROPERTIES</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">&quot;CREATE</span> <span class="pre">TABLE</span> <span class="pre">IF</span> <span class="pre">NOT</span> <span class="pre">EXISTS</span> <span class="pre">properties</span> <span class="pre">(\n</span>&#160; <span class="pre">name</span>&#160;&#160;&#160;&#160;&#160;&#160; <span class="pre">TEXT,\n</span>&#160; <span class="pre">value</span>&#160;&#160;&#160;&#160;&#160; <span class="pre">TEXT,\n</span>&#160; <span class="pre">m_time</span>&#160;&#160;&#160;&#160; <span class="pre">INTEGER</span> <span class="pre">DEFAULT</span> <span class="pre">(strftime('%s',</span> <span class="pre">'now')),</span>&#160; <span class="pre">--</span> <span class="pre">last</span> <span class="pre">modified</span> <span class="pre">(unix</span> <span class="pre">epoch)</span> <span class="pre">time</span> <span class="pre">in</span> <span class="pre">sec.\n</span>&#160; <span class="pre">PRIMARY</span> <span class="pre">KEY</span> <span class="pre">(name))&quot;</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.DDL_PROPERTIES" title="Link to this definition">¶</a></dt>
  197. <dd><p>Table to store properties of the DB application</p>
  198. </dd></dl>
  199. <dl class="py attribute">
  200. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.SQLITE_CONNECT_ARGS">
  201. <span class="sig-name descname"><span class="pre">SQLITE_CONNECT_ARGS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{'cached_statements':</span> <span class="pre">0,</span> <span class="pre">'check_same_thread':</span> <span class="pre">False,</span> <span class="pre">'isolation_level':</span> <span class="pre">None}</span></em><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.SQLITE_CONNECT_ARGS" title="Link to this definition">¶</a></dt>
  202. <dd><p>Connection arguments (<a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.connect" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sqlite3.connect</span></code></a>)</p>
  203. <dl>
  204. <dt><code class="docutils literal notranslate"><span class="pre">check_same_thread</span></code>:</dt><dd><p>Is disabled by default when <code class="xref py py-obj docutils literal notranslate"><span class="pre">SQLITE_THREADING_MODE</span></code> is
  205. <code class="docutils literal notranslate"><span class="pre">serialized</span></code>. The check is more of a hindrance in this case because it
  206. would prevent a DB connector from being used in multiple threads.</p>
  207. </dd>
  208. <dt><code class="docutils literal notranslate"><span class="pre">cached_statements</span></code>:</dt><dd><p>Is set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by default. Note: Python 3.12+ fetch result are not
  209. consistent in multi-threading application and causing an API misuse error.</p>
  210. <p>The multithreading use in SQLiteAppl is intended and supported if
  211. threadsafety is set to 3 (aka “serialized”). CPython supports “serialized”
  212. from version 3.12 on, but unfortunately only with errors:</p>
  213. <ul class="simple">
  214. <li><p><a class="reference external" href="https://github.com/python/cpython/issues/118172">https://github.com/python/cpython/issues/118172</a></p></li>
  215. <li><p><a class="reference external" href="https://github.com/python/cpython/issues/123873">https://github.com/python/cpython/issues/123873</a></p></li>
  216. </ul>
  217. <p>The workaround for SQLite3 multithreading cache inconsistency is to set
  218. option <code class="docutils literal notranslate"><span class="pre">cached_statements</span></code> to <code class="docutils literal notranslate"><span class="pre">0</span></code> by default.</p>
  219. </dd>
  220. </dl>
  221. </dd></dl>
  222. <dl class="py method">
  223. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.init">
  224. <span class="sig-name descname"><span class="pre">init</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">conn</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection" title="(in Python v3.13)"><span class="pre">Connection</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties.init"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.init" title="Link to this definition">¶</a></dt>
  225. <dd><p>Initializes DB schema of the properties in the DB.</p>
  226. </dd></dl>
  227. <dl class="py method">
  228. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.set">
  229. <span class="sig-name descname"><span class="pre">set</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties.set"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.set" title="Link to this definition">¶</a></dt>
  230. <dd><p>Set <code class="docutils literal notranslate"><span class="pre">value</span></code> of property <code class="docutils literal notranslate"><span class="pre">name</span></code> in DB. If property already
  231. exists, update the <code class="docutils literal notranslate"><span class="pre">m_time</span></code> (and the value).</p>
  232. </dd></dl>
  233. <dl class="py method">
  234. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.delete">
  235. <span class="sig-name descname"><span class="pre">delete</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties.delete"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.delete" title="Link to this definition">¶</a></dt>
  236. <dd><p>Delete of property <code class="docutils literal notranslate"><span class="pre">name</span></code> from DB.</p>
  237. </dd></dl>
  238. <dl class="py method">
  239. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.row">
  240. <span class="sig-name descname"><span class="pre">row</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties.row"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.row" title="Link to this definition">¶</a></dt>
  241. <dd><p>Returns the DB row of property <code class="docutils literal notranslate"><span class="pre">name</span></code> or <code class="docutils literal notranslate"><span class="pre">default</span></code> if property
  242. not exists in DB.</p>
  243. </dd></dl>
  244. <dl class="py method">
  245. <dt class="sig sig-object py" id="searx.sqlitedb.SQLiteProperties.m_time">
  246. <span class="sig-name descname"><span class="pre">m_time</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></span></span><a class="reference internal" href="../_modules/searx/sqlitedb.html#SQLiteProperties.m_time"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.sqlitedb.SQLiteProperties.m_time" title="Link to this definition">¶</a></dt>
  247. <dd><p>Last modification time of this property.</p>
  248. </dd></dl>
  249. </dd></dl>
  250. </section>
  251. <div class="clearer"></div>
  252. </div>
  253. </div>
  254. </div>
  255. <span id="sidebar-top"></span>
  256. <div class="sphinxsidebar" role="navigation" aria-label="Main">
  257. <div class="sphinxsidebarwrapper">
  258. <p class="logo"><a href="../index.html">
  259. <img class="logo" src="../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/>
  260. </a></p>
  261. <h3><a href="../index.html">Table of Contents</a></h3>
  262. <ul class="current">
  263. <li class="toctree-l1"><a class="reference internal" href="../user/index.html">User information</a></li>
  264. <li class="toctree-l1"><a class="reference internal" href="../own-instance.html">Why use a private instance?</a></li>
  265. <li class="toctree-l1"><a class="reference internal" href="../admin/index.html">Administrator documentation</a></li>
  266. <li class="toctree-l1"><a class="reference internal" href="../dev/index.html">Developer documentation</a></li>
  267. <li class="toctree-l1"><a class="reference internal" href="../utils/index.html">DevOps tooling box</a></li>
  268. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Source-Code</a><ul class="current">
  269. <li class="toctree-l2"><a class="reference internal" href="searx.babel_extract.html">Custom message extractor (i18n)</a></li>
  270. <li class="toctree-l2"><a class="reference internal" href="searx.botdetection.html">Bot Detection</a></li>
  271. <li class="toctree-l2"><a class="reference internal" href="searx.cache.html">Caches</a></li>
  272. <li class="toctree-l2"><a class="reference internal" href="searx.exceptions.html">SearXNG Exceptions</a></li>
  273. <li class="toctree-l2"><a class="reference internal" href="searx.favicons.html">Favicons (source)</a></li>
  274. <li class="toctree-l2"><a class="reference internal" href="searx.infopage.html">Online <code class="docutils literal notranslate"><span class="pre">/info</span></code></a></li>
  275. <li class="toctree-l2"><a class="reference internal" href="searx.locales.html">Locales</a></li>
  276. <li class="toctree-l2"><a class="reference internal" href="searx.redisdb.html">Redis DB</a></li>
  277. <li class="toctree-l2"><a class="reference internal" href="searx.redislib.html">Redis Library</a></li>
  278. <li class="toctree-l2"><a class="reference internal" href="searx.search.html">Search</a></li>
  279. <li class="toctree-l2"><a class="reference internal" href="searx.search.processors.html">Search processors</a></li>
  280. <li class="toctree-l2"><a class="reference internal" href="searx.settings.html">Settings Loader</a></li>
  281. <li class="toctree-l2 current"><a class="current reference internal" href="#">SQLite DB</a><ul>
  282. <li class="toctree-l3"><a class="reference internal" href="#searx.sqlitedb.DBSession"><code class="docutils literal notranslate"><span class="pre">DBSession</span></code></a><ul>
  283. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.DBSession.get_connect"><code class="docutils literal notranslate"><span class="pre">DBSession.get_connect()</span></code></a></li>
  284. </ul>
  285. </li>
  286. <li class="toctree-l3"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl</span></code></a><ul>
  287. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.DB_SCHEMA"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.DB_SCHEMA</span></code></a></li>
  288. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_THREADING_MODE"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.SQLITE_THREADING_MODE</span></code></a></li>
  289. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_JOURNAL_MODE"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.SQLITE_JOURNAL_MODE</span></code></a></li>
  290. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.SQLITE_CONNECT_ARGS"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.SQLITE_CONNECT_ARGS</span></code></a></li>
  291. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.connect"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.connect()</span></code></a></li>
  292. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.register_functions"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.register_functions()</span></code></a></li>
  293. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.DB"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.DB</span></code></a></li>
  294. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteAppl.init"><code class="docutils literal notranslate"><span class="pre">SQLiteAppl.init()</span></code></a></li>
  295. </ul>
  296. </li>
  297. <li class="toctree-l3"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties</span></code></a><ul>
  298. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.SQLITE_JOURNAL_MODE"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.SQLITE_JOURNAL_MODE</span></code></a></li>
  299. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.DDL_PROPERTIES"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.DDL_PROPERTIES</span></code></a></li>
  300. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.SQLITE_CONNECT_ARGS"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.SQLITE_CONNECT_ARGS</span></code></a></li>
  301. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.init"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.init()</span></code></a></li>
  302. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.set"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.set()</span></code></a></li>
  303. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.delete"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.delete()</span></code></a></li>
  304. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.row"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.row()</span></code></a></li>
  305. <li class="toctree-l4"><a class="reference internal" href="#searx.sqlitedb.SQLiteProperties.m_time"><code class="docutils literal notranslate"><span class="pre">SQLiteProperties.m_time()</span></code></a></li>
  306. </ul>
  307. </li>
  308. </ul>
  309. </li>
  310. <li class="toctree-l2"><a class="reference internal" href="searx.utils.html">Utility functions for the engines</a></li>
  311. <li class="toctree-l2"><a class="reference internal" href="searx.weather.html">Weather</a></li>
  312. </ul>
  313. </li>
  314. </ul>
  315. <h3>Project Links</h3>
  316. <ul>
  317. <li><a href="https://github.com/searxng/searxng/tree/master">Source</a>
  318. <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a>
  319. <li><a href="https://searx.space">Public instances</a>
  320. <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a>
  321. </ul><h3>Navigation</h3>
  322. <ul>
  323. <li><a href="../index.html">Overview</a>
  324. <ul>
  325. <li><a href="index.html">Source-Code</a>
  326. <ul>
  327. <li>Previous: <a href="searx.settings.html" title="previous chapter">Settings Loader</a>
  328. <li>Next: <a href="searx.utils.html" title="next chapter">Utility functions for the engines</a></ul>
  329. </li>
  330. </ul>
  331. </li>
  332. </ul>
  333. <search id="searchbox" style="display: none" role="search">
  334. <h3 id="searchlabel">Quick search</h3>
  335. <div class="searchformwrapper">
  336. <form class="search" action="../search.html" method="get">
  337. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  338. <input type="submit" value="Go" />
  339. </form>
  340. </div>
  341. </search>
  342. <script>document.getElementById('searchbox').style.display = "block"</script>
  343. <div role="note" aria-label="source link">
  344. <h3>This Page</h3>
  345. <ul class="this-page-menu">
  346. <li><a href="../_sources/src/searx.sqlitedb.rst.txt"
  347. rel="nofollow">Show Source</a></li>
  348. </ul>
  349. </div>
  350. </div>
  351. </div>
  352. <div class="clearer"></div>
  353. </div>
  354. <div class="footer" role="contentinfo">
  355. &#169; Copyright SearXNG team.
  356. </div>
  357. </body>
  358. </html>