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
570571When 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)
573574user = await crud_users.get(db = db, email = user.email)
574575```
575576
576577To 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
579580user = 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+ 599+ " profile_image_url" : " https://profileimageurl.com"
600+ },
601+ {
602+ " id" : 5 ,
603+ " name" : " User Userson" ,
604+ " username" : " userson5" ,
605+ 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
587616To 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
606635crud_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+
609647To update you pass an ` object ` which may be a ` pydantic schema ` or just a regular ` dict ` , and the kwargs.
610648You 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
697735The 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
701739Another option is not passing the ` resource_id_name ` , but passing the ` resource_id_type ` (default int):
702740``` python
0 commit comments