diff --git a/README.md b/README.md index 67ccb5a..520a884 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Addok plugin to store documents in SQLite instead of Redis to reduce memory usag - **SQLite storage**: Store documents in a SQLite database instead of Redis - **Memory optimization**: Reduce Redis RAM usage for large datasets -- **Automatic registration**: Plugin registers itself when installed ## Installation @@ -16,11 +15,23 @@ pip install addok-sqlite-store ## Configuration -The plugin will register itself when installed, by setting the correct -`DOCUMENT_STORE_PYPATH`. +Add the following to your Addok configuration file to activate the plugin: -Define the path where the SQLite database will be created: +```python +# Use SQLite as document store +DOCUMENT_STORE_PYPATH = 'addok_sqlite_store.SQLiteStore' +``` + +The SQLite database will be created at `addok.db` by default. You can customize the path: ```python -SQLITE_DB_PATH = "/path/to/your/database.db" +# Optional: customize the database path +SQLITE_DB_PATH = '/path/to/your/database.db' +``` + +Or use environment variables: + +```bash +export ADDOK_DOCUMENT_STORE_PYPATH='addok_sqlite_store.SQLiteStore' +export ADDOK_SQLITE_DB_PATH='/path/to/your/database.db' # optional ``` diff --git a/addok_sqlite_store/__init__.py b/addok_sqlite_store/__init__.py index e512a8d..dc72b77 100644 --- a/addok_sqlite_store/__init__.py +++ b/addok_sqlite_store/__init__.py @@ -11,7 +11,10 @@ def __init__(self, *args, **kwargs): self.init() def init(self): - self.conn = sqlite3.connect(os.environ.get('SQLITE_DB_PATH') or config.SQLITE_DB_PATH) + self.db_path = (os.environ.get('ADDOK_SQLITE_DB_PATH') or + os.environ.get('SQLITE_DB_PATH') or + config.SQLITE_DB_PATH) + self.conn = sqlite3.connect(self.db_path) self.lock = Lock() with self.conn as conn: conn.execute('CREATE TABLE IF NOT EXISTS ' @@ -45,10 +48,9 @@ def remove(self, *keys): self.lock.release() def flushdb(self): - os.unlink(config.SQLITE_DB_PATH) + os.unlink(self.db_path) self.init() def preconfigure(config): - config.DOCUMENT_STORE_PYPATH = 'addok_sqlite_store.SQLiteStore' config.SQLITE_DB_PATH = 'addok.db'