Skip to content

Commit

Permalink
refactor: remove PERSISTENCE_URI, use first-class SQLITE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Nov 27, 2023
1 parent a0d1c20 commit e32297d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 14 additions & 1 deletion silverback/persistence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import sqlite3
from abc import ABC, abstractmethod
from datetime import datetime, timezone
Expand Down Expand Up @@ -86,6 +87,18 @@ async def add_result(self, v: HandlerResult):


class SQLitePersistentStorage(BasePersistentStorage):
"""
SQLite implementation of BasePersistentStorage used to store application state and handler
result data.
Usage:
To use SQLite persistent storage, you must configure the following env vars:
- `PERSISTENCE_CLASS`: `silverback.persistence.SQLitePersistentStorage`
- `SQLITE_PATH` (optional): A system file path or if blank it will be stored in-memory.
"""

SQL_GET_STATE = """
SELECT last_block_seen, last_block_processed, updated
FROM silverback_state
Expand Down Expand Up @@ -130,7 +143,7 @@ class SQLitePersistentStorage(BasePersistentStorage):
initialized: bool = False

async def init(self):
self.con = sqlite3.connect(self.settings.PERSISTENCE_URI or ":memory:")
self.con = sqlite3.connect(os.environ.get("SQLITE_PATH", ":memory:"))

cur = self.con.cursor()
cur.executescript(
Expand Down
1 change: 0 additions & 1 deletion silverback/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Settings(BaseSettings, ManagerAccessMixin):

# Used for persistent storage
PERSISTENCE_CLASS: Optional[str] = None
PERSISTENCE_URI: Optional[str] = None

class Config:
env_prefix = "SILVERBACK_"
Expand Down

0 comments on commit e32297d

Please sign in to comment.