Skip to content

Commit 654faa1

Browse files
authored
Merge pull request #9 from addok/non-intrusive
Make plugin non-intrusive: don't auto-set DOCUMENT_STORE_PYPATH
2 parents 5ff5538 + d7bc398 commit 654faa1

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Addok plugin to store documents in SQLite instead of Redis to reduce memory usag
66

77
- **SQLite storage**: Store documents in a SQLite database instead of Redis
88
- **Memory optimization**: Reduce Redis RAM usage for large datasets
9-
- **Automatic registration**: Plugin registers itself when installed
109

1110
## Installation
1211

@@ -16,11 +15,23 @@ pip install addok-sqlite-store
1615

1716
## Configuration
1817

19-
The plugin will register itself when installed, by setting the correct
20-
`DOCUMENT_STORE_PYPATH`.
18+
Add the following to your Addok configuration file to activate the plugin:
2119

22-
Define the path where the SQLite database will be created:
20+
```python
21+
# Use SQLite as document store
22+
DOCUMENT_STORE_PYPATH = 'addok_sqlite_store.SQLiteStore'
23+
```
24+
25+
The SQLite database will be created at `addok.db` by default. You can customize the path:
2326

2427
```python
25-
SQLITE_DB_PATH = "/path/to/your/database.db"
28+
# Optional: customize the database path
29+
SQLITE_DB_PATH = '/path/to/your/database.db'
30+
```
31+
32+
Or use environment variables:
33+
34+
```bash
35+
export ADDOK_DOCUMENT_STORE_PYPATH='addok_sqlite_store.SQLiteStore'
36+
export ADDOK_SQLITE_DB_PATH='/path/to/your/database.db' # optional
2637
```

addok_sqlite_store/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def __init__(self, *args, **kwargs):
1111
self.init()
1212

1313
def init(self):
14-
self.conn = sqlite3.connect(os.environ.get('SQLITE_DB_PATH') or config.SQLITE_DB_PATH)
14+
self.db_path = (os.environ.get('ADDOK_SQLITE_DB_PATH') or
15+
os.environ.get('SQLITE_DB_PATH') or
16+
config.SQLITE_DB_PATH)
17+
self.conn = sqlite3.connect(self.db_path)
1518
self.lock = Lock()
1619
with self.conn as conn:
1720
conn.execute('CREATE TABLE IF NOT EXISTS '
@@ -45,10 +48,9 @@ def remove(self, *keys):
4548
self.lock.release()
4649

4750
def flushdb(self):
48-
os.unlink(config.SQLITE_DB_PATH)
51+
os.unlink(self.db_path)
4952
self.init()
5053

5154

5255
def preconfigure(config):
53-
config.DOCUMENT_STORE_PYPATH = 'addok_sqlite_store.SQLiteStore'
5456
config.SQLITE_DB_PATH = 'addok.db'

0 commit comments

Comments
 (0)