|
.oO SearXNG Developer Documentation Oo.
|
Public Member Functions | |
| __init__ (self, str db_url) | |
| sqlite3.Connection | connect (self) |
| register_functions (self, sqlite3.Connection conn) | |
| sqlite3.Connection | DB (self) |
| bool | init (self, sqlite3.Connection conn) |
| create_schema (self, sqlite3.Connection conn) | |
Public Attributes | |
| str | db_url = db_url |
| SQLiteProperties | properties = SQLiteProperties(db_url) |
Static Public Attributes | |
| dict | DDL_CREATE_TABLES = {} |
| int | DB_SCHEMA = 1 |
| dict | SQLITE_THREADING_MODE |
| str | SQLITE_JOURNAL_MODE = "WAL" |
| dict | SQLITE_CONNECT_ARGS |
Protected Member Functions | |
| _compatibility (self) | |
| sqlite3.Connection | _connect (self) |
Protected Attributes | |
| bool | _init_done = False |
| sqlite3.Connection|None | _DB = None |
Abstract base class for implementing convenient DB access in SQLite applications. In the constructor, a :py:obj:`SQLiteProperties` instance is already aggregated under ``self.properties``.
Definition at line 91 of file sqlitedb.py.
| searx.sqlitedb.SQLiteAppl.__init__ | ( | self, | |
| str | db_url ) |
Definition at line 154 of file sqlitedb.py.
|
protected |
Definition at line 170 of file sqlitedb.py.
References SQLITE_THREADING_MODE.
|
protected |
Definition at line 190 of file sqlitedb.py.
References searx.cache.ExpireCacheCfg.db_url, searx.favicons.cache.FaviconCacheConfig.db_url, db_url, register_functions(), and SQLITE_CONNECT_ARGS.
Referenced by connect().
| sqlite3.Connection searx.sqlitedb.SQLiteAppl.connect | ( | self | ) |
Creates a new DB connection (:py:obj:`SQLITE_CONNECT_ARGS`). If not already done, the DB schema is set up. The caller must take care of closing the resource. Alternatively, :py:obj:`SQLiteAppl.DB` can also be used (the resource behind `self.DB` is automatically closed when the process or thread is terminated).
Definition at line 196 of file sqlitedb.py.
References _connect(), searx.cache.ExpireCacheSQLite.init(), searx.data.currencies.CurrenciesDB.init(), searx.data.tracker_patterns.TrackerPatternsDB.init(), searx.enginelib.Engine.init(), searx.plugins._core.Plugin.init(), searx.plugins._core.PluginStorage.init(), searx.plugins.ahmia_filter.SXNGPlugin.init(), searx.plugins.hostnames.SXNGPlugin.init(), searx.plugins.tracker_url_remover.SXNGPlugin.init(), searx.search.processors.ProcessorMap.init(), init(), and SQLITE_CONNECT_ARGS.
Referenced by searx.cache.ExpireCacheSQLite.create_table(), searx.favicons.cache.FaviconCacheSQLite.set(), and searx.cache.ExpireCacheSQLite.truncate_tables().
| searx.sqlitedb.SQLiteAppl.create_schema | ( | self, | |
| sqlite3.Connection | conn ) |
Reimplemented in searx.sqlitedb.SQLiteProperties.
Definition at line 308 of file sqlitedb.py.
References searx.cache.ExpireCacheSQLite.DB_SCHEMA, searx.favicons.cache.FaviconCacheSQLite.DB_SCHEMA, DB_SCHEMA, searx.cache.ExpireCacheSQLite.DDL_CREATE_TABLES, searx.favicons.cache.FaviconCacheSQLite.DDL_CREATE_TABLES, DDL_CREATE_TABLES, and properties.
Referenced by init(), and searx.sqlitedb.SQLiteProperties.init().
| sqlite3.Connection searx.sqlitedb.SQLiteAppl.DB | ( | self | ) |
Provides a DB connection. The connection is a *singleton* and
therefore well suited for read access. If
:py:obj:`SQLITE_THREADING_MODE` is ``serialized`` only one DB connection
is created for all threads.
.. note::
For dedicated `transaction control`_, it is recommended to create a
new connection (:py:obj:`SQLiteAppl.connect`).
.. _transaction control:
https://docs.python.org/3/library/sqlite3.html#sqlite3-controlling-transactions
Definition at line 242 of file sqlitedb.py.
References searx.cache.ExpireCacheSQLite.init(), searx.data.currencies.CurrenciesDB.init(), searx.data.tracker_patterns.TrackerPatternsDB.init(), searx.enginelib.Engine.init(), searx.plugins._core.Plugin.init(), searx.plugins._core.PluginStorage.init(), searx.plugins.ahmia_filter.SXNGPlugin.init(), searx.plugins.hostnames.SXNGPlugin.init(), searx.plugins.tracker_url_remover.SXNGPlugin.init(), searx.search.processors.ProcessorMap.init(), init(), and SQLITE_THREADING_MODE.
Referenced by searx.favicons.cache.FaviconCacheSQLite.__call__(), and searx.favicons.cache.FaviconCacheSQLite._query_val().
| bool searx.sqlitedb.SQLiteAppl.init | ( | self, | |
| sqlite3.Connection | conn ) |
Initializes the DB schema and properties, is only executed once even if called several times. If the initialization has not yet taken place, it is carried out and a `True` is returned to the caller at the end. If the initialization has already been carried out in the past, `False` is returned.
Reimplemented in searx.cache.ExpireCacheSQLite, and searx.sqlitedb.SQLiteProperties.
Definition at line 280 of file sqlitedb.py.
References _init_done, create_schema(), searx.cache.ExpireCacheSQLite.DB_SCHEMA, searx.favicons.cache.FaviconCacheSQLite.DB_SCHEMA, DB_SCHEMA, searx.cache.ExpireCacheCfg.db_url, searx.favicons.cache.FaviconCacheConfig.db_url, db_url, init(), and properties.
Referenced by connect(), DB(), and init().
| searx.sqlitedb.SQLiteAppl.register_functions | ( | self, | |
| sqlite3.Connection | conn ) |
Create user-defined_ SQL functions.
``REGEXP(<pattern>, <field>)`` : 0 | 1
`re.search`_ returns (int) 1 for a match and 0 for none match of
``<pattern>`` in ``<field>``.
.. code:: sql
SELECT '12' AS field WHERE REGEXP('^[0-9][0-9]$', field)
-- 12
SELECT REGEXP('[0-9][0-9]', 'X12Y')
-- 1
SELECT REGEXP('[0-9][0-9]', 'X1Y')
-- 0
.. _user-defined: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
.. _deterministic: https://sqlite.org/deterministic.html
.. _re.search: https://docs.python.org/3/library/re.html#re.search
Definition at line 217 of file sqlitedb.py.
Referenced by _connect().
|
protected |
Definition at line 173 of file sqlitedb.py.
|
protected |
Definition at line 158 of file sqlitedb.py.
Referenced by init(), and searx.sqlitedb.SQLiteProperties.init().
|
static |
Definition at line 98 of file sqlitedb.py.
Referenced by create_schema(), and init().
| searx.sqlitedb.SQLiteAppl.db_url = db_url |
Definition at line 156 of file sqlitedb.py.
Referenced by _connect(), init(), and searx.sqlitedb.SQLiteProperties.init().
|
static |
Definition at line 96 of file sqlitedb.py.
Referenced by create_schema().
| SQLiteProperties searx.sqlitedb.SQLiteAppl.properties = SQLiteProperties(db_url) |
Definition at line 157 of file sqlitedb.py.
Referenced by create_schema(), searx.cache.ExpireCacheSQLite.create_table(), searx.cache.ExpireCacheSQLite.init(), init(), searx.cache.ExpireCacheSQLite.next_maintenance_time(), and searx.favicons.cache.FaviconCacheSQLite.next_maintenance_time().
|
static |
Definition at line 124 of file sqlitedb.py.
Referenced by _connect(), and connect().
|
static |
Definition at line 118 of file sqlitedb.py.
|
static |
Definition at line 103 of file sqlitedb.py.
Referenced by _compatibility(), and DB().