on master help sign in
searx/docs/blog/sql-engines.rst
117 lines 3.4 kB history raw
1=================
2Query SQL servers
3=================
5Now you can query SQL servers using searx. The following ones are supported:
7* `PostgreSQL`_
8* `MySQL`_
9* `SQLite`_
11All of the engines above are added to ``settings.yml`` just commented out, as you have to
12set the required attributes for the engines, e.g. ``database``. By default, the engines use
13``key-value`` template for displaying results. If you are not satisfied with the original result layout,
14you can use your owm template by placing the template under
15``searx/templates/{theme_name}/result_templates/{template_name}`` and setting
16``result_template`` attribute to ``{template_name}``.
18As mentioned in previous blog posts, if you do not wish to expose these engines on a
19public instance, you can still add them and limit the access by setting ``tokens``
20as described in the `blog post about private engines`_.
22Configure the engines
23=====================
25The configuration of the new database engines are similar. You must put a valid
26SELECT SQL query in ``query_str``. At the moment you can only bind at most
27one parameter in your query. By setting the attribute ``limit`` you can
28define how many results you want from the SQL server. Basically, it
29is the same as the LIMIT keyword in SQL.
31Please, do not include LIMIT or OFFSET in your SQL query as the engines
32rely on these keywords during paging. If you want to configure the number of returned results
33use the option ``limit``.
35PostgreSQL
36----------
38PostgreSQL is a powerful and robust open source database.
40Before configuring the PostgreSQL engine, you must install the dependency ``psychopg2``.
42You can find an example configuration below:
44.. code:: yaml
46 - name : postgresql
47 engine : postgresql
48 database : my_database
49 username : searx
50 password : password
51 query_str : 'SELECT * from my_table WHERE my_column = %(query)s'
52 shortcut : psql
55MySQL
56-----
58MySQL is said to be the most popular open source database.
60Before enabling MySQL engine, you must install the package ``mysql-connector-python``.
62The authentication plugin is configurable by setting ``auth_plugin`` in the attributes.
63By default it is set to ``caching_sha2_password``.
65This is an example configuration for quering a MySQL server:
67.. code:: yaml
69 - name : mysql
70 engine : mysql_server
71 database : my_database
72 username : searx
73 password : password
74 limit : 5
75 query_str : 'SELECT * from my_table WHERE my_column=%(query)s'
76 shortcut : mysql
79SQLite
80------
82SQLite is a small, fast and reliable SQL database engine. It does not require
83any extra dependency.
85You can read from your database ``my_database`` using this example configuration:
87.. code:: yaml
89 - name : sqlite
90 engine : sqlite
91 shortcut: sq
92 database : my_database
93 query_str : 'SELECT * FROM my_table WHERE my_column=:query'
96Next steps
97==========
99The next step is to add support for more data stores, e.g. Redis and MongoDB.
101Acknowledgement
102===============
104This development was sponsored by `Search and Discovery Fund`_ of `NLnet Foundation`_ .
106.. _PostgreSQL: https://www.postgresql.org/
107.. _MySQL: https://www.mysql.com/
108.. _SQLite: https://www.sqlite.org/index.html
109.. _blog post about private engines: private-engines.html#private-engines
110.. _Search and Discovery Fund: https://nlnet.nl/discovery
111.. _NLnet Foundation: https://nlnet.nl/
114| Happy hacking.
115| kvch // 2021.05.23 23:16