Skip to content

Commit 0effb23

Browse files
committed
fix docker details and tidy README
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
1 parent ac7c6a4 commit 0effb23

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# Simple example how to use FastAPI with Async SQLAlchemy 2.0
1+
# Simple example how to use FastAPI with Async SQLAlchemy 2.0 <!-- omit from toc -->
2+
3+
- [Introduction](#introduction)
4+
- [Installation](#installation)
5+
- [Usage](#usage)
6+
- [Local Postgres server using Docker](#local-postgres-server-using-docker)
7+
- [License](#license)
8+
9+
## Introduction
210

311
I've been using [FastAPI](https://fastapi.tiangolo.com/) and
412
[SQLAlchemy](https://www.sqlalchemy.org/) combined with
@@ -21,43 +29,60 @@ Clone the repository and install the dependencies. This project uses
2129
[Poetry](https://python-poetry.org/) for dependency management which should be
2230
installed on your system first.
2331

24-
```bash
32+
```console
2533
poetry install
2634
```
2735

2836
Then switch to the virtual environment:
2937

30-
```bash
38+
```console
3139
poetry shell
3240
```
3341

3442
## Usage
3543

44+
Run the server using `Uvicorn`:
45+
46+
```console
47+
uvicorn main:app --reload
48+
```
49+
50+
Then open your browser at [http://localhost:8000](http://localhost:8000).
51+
52+
There is only one endpoint available: `/users`. It returns a list of all users
53+
for a `GET` request and creates a new user for a `POST` request.
54+
55+
### Local Postgres server using Docker
56+
3657
This example uses [PostgreSQL](https://www.postgresql.org/) as the database. If
3758
you dont have a local PostgreSQL database running, you can start one with
3859
[Docker](https://www.docker.com) using the following command:
3960

40-
```bash
41-
docker exec -it postgres psql -U postgres
61+
```console
62+
docker run \
63+
--rm \
64+
--name postgres \
65+
-p 5432:5432 \
66+
-e POSTGRES_USER=postgres \
67+
-e POSTGRES_PASSWORD=postgres \
68+
-e POSTGRES_DB=postgres \
69+
-d postgres
4270
```
4371

4472
This will run a PostgreSQL database in a Docker container in the background.
4573
When you are finished and want to stop the database, run:
4674

47-
```bash
75+
```console
4876
docker stop postgres
4977
```
5078

51-
Run the server using `Uvicorn`:
79+
If needed, you can connect to the database managment by :
5280

53-
```bash
54-
uvicorn main:app --reload
81+
```console
82+
docker exec -it postgres psql -U postgres
5583
```
5684

57-
Then open your browser at [http://localhost:8000](http://localhost:8000).
58-
59-
There is only one endpoint available: `/users`. It returns a list of all users
60-
for a `GET` request and creates a new user for a `POST` request.
85+
This will allow you to edit or delete the database or records.
6186

6287
## License
6388

0 commit comments

Comments
 (0)