Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Comment thread
jdesboeufs marked this conversation as resolved.
```
8 changes: 5 additions & 3 deletions addok_sqlite_store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down Expand Up @@ -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'