Skip to content

Commit

Permalink
📦️v0.1.3 - Cached Sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu-panwar committed Oct 8, 2023
1 parent 5b088d4 commit 20314e2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ INFO: :: Average Response Time :: 0.97 ms
```


* **Cached Sessions**: Now use cached sessions along with context manager instead of `get_db`.

```
from fastapi import FastAPI
from .db import Base, engine
from fastapi_utilities import FastAPISessionMaker, repeat_every
from .models import User
import random
app = FastAPI()
Base.metadata.create_all(bind=engine)
session_maker = FastAPISessionMaker("sqlite:///db.sqlite3")
@app.on_event("startup")
@repeat_every(seconds=5, raise_exceptions=True)
async def startup():
print("Starting up...")
with session_maker.context_session() as session:
x = User(id=random.randint(0, 10000))
session.add(x)
print("Startup complete!")
```


---

Expand Down
26 changes: 26 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ INFO: :: Average Response Time :: 0.97 ms
```


* **Cached Sessions**: Now use cached sessions along with context manager instead of `get_db`.

```
from fastapi import FastAPI
from .db import Base, engine
from fastapi_utilities import FastAPISessionMaker, repeat_every
from .models import User
import random
app = FastAPI()
Base.metadata.create_all(bind=engine)
session_maker = FastAPISessionMaker("sqlite:///db.sqlite3")
@app.on_event("startup")
@repeat_every(seconds=5, raise_exceptions=True)
async def startup():
print("Starting up...")
with session_maker.context_session() as session:
x = User(id=random.randint(0, 10000))
session.add(x)
print("Startup complete!")
```


---

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-utilities"
version = "0.1.2"
version = "0.1.3"
description = "Reusable utilities for FastAPI"
authors = ["Priyanshu Panwar <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 20314e2

Please sign in to comment.