functions
database.functions.page_to_offset(page_size, page_number)
async
Calculate the database offset based on page size and number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_size |
PositiveInt
|
How many elements in each page |
required |
page_number |
PositiveInt
|
Number of the page |
required |
Returns:
Name | Type | Description |
---|---|---|
PositiveInt |
PositiveInt
|
The database offset |
Source code in database/functions.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
database.functions.get_address_by_dc_join_state_join_city(session, filter, page_size=10, page_number=1)
async
Query addresses by the strawberry dataclass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
get the session of database from get_session |
required |
filter |
AddressFilterInput
|
Strawberry input dataclass, everything can be None (based on sqlmodel model) |
required |
page_size |
PositiveInt
|
How many elements in each page. Defaults to 10. |
10
|
page_number |
PositiveInt
|
Number of the page. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
list[Address]
|
list[Address]: All addresses (db model) based on filter or empty list |
Todo
Fix joins with async client
Source code in database/functions.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
database.functions.insert_address_by_dc(session, address)
async
Create address by the strawberry dataclass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
get the session of database from get_session |
required |
address |
AddressInsertInput
|
Strawberry input dataclass, strict (based on sqlmodel model) |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
If city.ibge is not found on database: 404 error |
Returns:
Name | Type | Description |
---|---|---|
Address |
Address
|
Single model instance |
Source code in database/functions.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
database.functions.insert_address(session, address)
async
Insert addresses and city if not exists in background.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
AsyncSession
|
the session of database from get_session |
required |
address |
Address
|
Address instance based on database models |
required |
Source code in database/functions.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|