diff options
author | Arun Isaac | 2022-09-01 15:51:43 +0530 |
---|---|---|
committer | Arun Isaac | 2022-09-26 13:39:45 +0530 |
commit | 66a6593daf4580f3056c96ccfc658b556ea619fc (patch) | |
tree | aad50103f078e2850cafebe17d1b5b8df8bf7d2d /wqflask | |
parent | fc01a05fe571730dd2cead071717dd5dfaf7a81e (diff) | |
download | genenetwork2-66a6593daf4580f3056c96ccfc658b556ea619fc.tar.gz |
Add xapian database connection utilities.
* etc/default_settings.py (XAPIAN_DB_PATH): New variable.
* wqflask/wqflask/database.py: Import xapian.
(xapian_database, xapian_writable_database): New functions.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/database.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index 505f4bd2..d392f1d1 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -8,6 +8,7 @@ import contextlib #: type: ignore import MySQLdb +import xapian class Connection(Protocol): @@ -65,3 +66,21 @@ def database_connection() -> Iterator[Connection]: connection.commit() finally: connection.close() + + +@contextlib.contextmanager +def xapian_database(): + """Open xapian database read-only.""" + # pylint: disable-next=invalid-name + db = xapian.Database(get_setting("XAPIAN_DB_PATH")) + yield db + db.close() + + +@contextlib.contextmanager +def xapian_writable_database(): + """Open xapian database for writing.""" + # pylint: disable-next=invalid-name + db = xapian.WritableDatabase(get_setting("XAPIAN_DB_PATH")) + yield db + db.close() |