aboutsummaryrefslogtreecommitdiff
path: root/gn3/db_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/db_utils.py')
-rw-r--r--gn3/db_utils.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index 69e88a5..ead0c5b 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -3,7 +3,8 @@ import contextlib
from typing import Any, Iterator, Protocol, Tuple
from urllib.parse import urlparse
import MySQLdb as mdb
-from gn3.settings import SQL_URI
+import xapian
+from gn3.settings import SQL_URI, XAPIAN_DB_PATH
def parse_db_url() -> Tuple:
@@ -42,3 +43,14 @@ def database_connection() -> Iterator[Connection]:
yield connection
finally:
connection.close()
+
+
+@contextlib.contextmanager
+def xapian_database():
+ """Open xapian database read-only."""
+ # pylint: disable-next=invalid-name
+ db = xapian.Database(XAPIAN_DB_PATH)
+ try:
+ yield db
+ finally:
+ db.close()