Skip to content

Commit

Permalink
APSW best practice
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-spencer committed Jan 21, 2025
1 parent c24bdce commit cf3d19f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/itn_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,21 @@
]


def _enable_best_practice(connection: sqlite.Connection):
"""Enable aspw best practice."""
apsw.bestpractice.connection_wal(connection)
apsw.bestpractice.library_logging()


@asynccontextmanager
async def lifespan(app: FastAPI):
"""Load the database connection for the life of the app.s"""
db_path = Path(os.environ["DATABASE_PATH"])
logger.info("validator database: %s", db_path)
app.state.connection = apsw.Connection(
str(db_path), flags=apsw.SQLITE_OPEN_READONLY
str(db_path), flags=apsw.SQLITE_OPEN_NOMUTEX | apsw.SQLITE_OPEN_READONLY
)
_enable_best_practice(app.state.connection)
app.state.kupo_url = os.environ["KUPO_URL"]
app.state.kupo_port = os.environ["KUPO_PORT"]
yield
Expand Down

0 comments on commit cf3d19f

Please sign in to comment.