mirror of
https://github.com/searxng/searxng.git
synced 2026-09-03 04:51:24 +00:00
[mod] engines: migrate to setup() from init() for simple tasks
This commit is contained in:
@@ -21,6 +21,8 @@ Implementations
|
||||
|
||||
"""
|
||||
|
||||
import typing as t
|
||||
|
||||
try:
|
||||
import psycopg2 # type: ignore
|
||||
except ImportError:
|
||||
@@ -55,15 +57,17 @@ paging = True
|
||||
_connection = None
|
||||
|
||||
|
||||
def init(engine_settings):
|
||||
global _connection # pylint: disable=global-statement
|
||||
|
||||
def setup(engine_settings: dict[str, t.Any]) -> bool | None:
|
||||
if 'query_str' not in engine_settings:
|
||||
raise ValueError('query_str cannot be empty')
|
||||
|
||||
if not engine_settings['query_str'].lower().startswith('select '):
|
||||
raise ValueError('only SELECT query is supported')
|
||||
|
||||
|
||||
def init(_):
|
||||
global _connection # pylint: disable=global-statement
|
||||
|
||||
_connection = psycopg2.connect(
|
||||
database=database,
|
||||
user=username,
|
||||
|
||||
Reference in New Issue
Block a user