Skip to content

Commit f09cd4c

Browse files
committed
readme fixes, documentation fixes
1 parent 05db751 commit f09cd4c

File tree

2 files changed

+68
-30
lines changed

2 files changed

+68
-30
lines changed

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- 👜 Easy client-side caching
4949
- 🚦 ARQ integration for task queue
5050
- ⚙️ Efficient querying (only queries what's needed)
51+
- ⎘ Out of the box pagination support
5152
- 👮 FastAPI docs behind authentication and hidden based on the environment
5253
- 🦾 Easily extendable
5354
- 🤸‍♂️ Flexible
@@ -569,20 +570,48 @@ crud_users = CRUDUser(User)
569570

570571
When actually using the crud in an endpoint, to get data you just pass the database connection and the attributes as kwargs:
571572
```python
572-
# Here I'm getting the users with email == user.email
573+
# Here I'm getting the first user with email == user.email (email is unique in this case)
573574
user = await crud_users.get(db=db, email=user.email)
574575
```
575576

576577
To get a list of objects with the attributes, you should use the get_multi:
577578
```python
578-
# Here I'm getting 100 users with the name David except for the first 3
579+
# Here I'm getting at most 10 users with the name 'User Userson' except for the first 3
579580
user = await crud_users.get_multi(
580581
db=db,
581582
offset=3,
582583
limit=100,
583-
name="David"
584+
name="User Userson"
584585
)
585586
```
587+
> **Warning**
588+
> Note that get_multi returns a python `dict`.
589+
590+
Which will return a python dict with the following structure:
591+
```javascript
592+
{
593+
"data": [
594+
{
595+
"id": 4,
596+
"name": "User Userson",
597+
"username": "userson4",
598+
"email": "[email protected]",
599+
"profile_image_url": "https://profileimageurl.com"
600+
},
601+
{
602+
"id": 5,
603+
"name": "User Userson",
604+
"username": "userson5",
605+
"email": "[email protected]",
606+
"profile_image_url": "https://profileimageurl.com"
607+
}
608+
],
609+
"total_count": 2,
610+
"has_more": false,
611+
"page": 1,
612+
"items_per_page": 10
613+
}
614+
```
586615

587616
To create, you pass a `CreateSchemaType` object with the attributes, such as a `UserCreate` pydantic schema:
588617
```python
@@ -606,6 +635,15 @@ To just check if there is at least one row that matches a certain set of attribu
606635
crud_users.exists(db=db, email=user@example.com)
607636
```
608637

638+
You can also get the count of a certain object with the specified filter:
639+
```python
640+
# Here I'm getting the count of users with the name 'User Userson'
641+
user = await crud_users.count(
642+
db=db,
643+
name="User Userson"
644+
)
645+
```
646+
609647
To update you pass an `object` which may be a `pydantic schema` or just a regular `dict`, and the kwargs.
610648
You will update with `objects` the rows that match your `kwargs`.
611649
```python
@@ -696,7 +734,7 @@ async def sample_endpoint(request: Request, my_id: int):
696734

697735
The way it works is:
698736
- the data is saved in redis with the following cache key: `sample_data:{my_id}`
699-
- then the the time to expire is set as 3600 seconds (that's the default)
737+
- then the time to expire is set as 3600 seconds (that's the default)
700738

701739
Another option is not passing the `resource_id_name`, but passing the `resource_id_type` (default int):
702740
```python

docker-compose.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,33 @@ services:
4545
volumes:
4646
- redis-data:/data
4747

48-
#-------- uncomment to create first superuser --------
49-
create_superuser:
50-
build:
51-
context: .
52-
dockerfile: Dockerfile
53-
env_file:
54-
- ./src/.env
55-
depends_on:
56-
- db
57-
command: python -m src.scripts.create_first_superuser
58-
volumes:
59-
- ./src:/code/src
48+
# #-------- uncomment to create first superuser --------
49+
# create_superuser:
50+
# build:
51+
# context: .
52+
# dockerfile: Dockerfile
53+
# env_file:
54+
# - ./src/.env
55+
# depends_on:
56+
# - db
57+
# command: python -m src.scripts.create_first_superuser
58+
# volumes:
59+
# - ./src:/code/src
6060

61-
#-------- uncomment to run tests --------
62-
pytest:
63-
build:
64-
context: .
65-
dockerfile: Dockerfile
66-
env_file:
67-
- ./src/.env
68-
depends_on:
69-
- db
70-
- create_superuser
71-
- redis
72-
command: python -m pytest
73-
volumes:
74-
- ./src:/code/src
61+
# #-------- uncomment to run tests --------
62+
# pytest:
63+
# build:
64+
# context: .
65+
# dockerfile: Dockerfile
66+
# env_file:
67+
# - ./src/.env
68+
# depends_on:
69+
# - db
70+
# - create_superuser
71+
# - redis
72+
# command: python -m pytest
73+
# volumes:
74+
# - ./src:/code/src
7575

7676
volumes:
7777
postgres-data:

0 commit comments

Comments
 (0)