sql-engines.rst 3.3 KB

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