Skip to content

Commit a37e3d3

Browse files
authored
Merge pull request #1 from seapagan/add-sqlite-option
add option to use SQLite instead of PostgreSQL
2 parents b340201 + 33fd7fe commit a37e3d3

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,4 @@ cython_debug/
207207
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,python
208208

209209
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
210+
test.db

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Installation](#installation)
55
- [Usage](#usage)
66
- [Local Postgres server using Docker](#local-postgres-server-using-docker)
7+
- [Use SQLite instead of PostgreSQL](#use-sqlite-instead-of-postgresql)
78
- [License](#license)
89

910
## Introduction
@@ -84,6 +85,17 @@ docker exec -it postgres psql -U postgres
8485

8586
This will allow you to edit or delete the database or records.
8687

88+
### Use SQLite instead of PostgreSQL
89+
90+
For testing purposes, you can also use SQLite instead of PostgreSQL. To do so,
91+
open the [dp.py](db.py) file and comment out the PostgreSQL database in the
92+
`DATABASE_URL` environment variable and uncomment the SQLite database.
93+
94+
```python
95+
# DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost/postgres"
96+
DATABASE_URL = "sqlite+aiosqlite:///./test.db"
97+
```
98+
8799
## License
88100

89101
This project is licensed under the terms of the MIT license.

db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from sqlalchemy.orm import declarative_base
44

55
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost/postgres"
6+
# DATABASE_URL = "sqlite+aiosqlite:///./test.db"
7+
# Note that (as far as I can tell from the docs and searching) there is no need
8+
# to add 'check_same_thread=False' to the sqlite connection string, as
9+
# SQLAlchemy version 1.4+ will automatically add it for you when using SQLite.
610

711
engine = create_async_engine(DATABASE_URL, echo=False)
812
Base = declarative_base()

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fastapi = "^0.97.0"
1212
asyncpg = "^0.27.0"
1313
sqlalchemy = {extras = ["asyncio"], version = "^2.0.16"}
1414
uvicorn = {extras = ["standard"], version = "^0.22.0"}
15+
aiosqlite = "^0.19.0"
1516

1617
[tool.poetry.group.dev.dependencies]
1718
# linting and formatting tools

0 commit comments

Comments
 (0)