internal.queries.reservations
1# Code generated by sqlc. DO NOT EDIT. 2# versions: 3# sqlc v1.30.0 4# source: reservations.sql 5import datetime 6import pydantic 7from typing import Any, AsyncIterator, Optional 8 9import sqlalchemy 10import sqlalchemy.ext.asyncio 11 12from internal.queries import models 13 14 15COLLECT_RESERVATION = """-- name: collect_reservation \\:one 16UPDATE reservations 17SET collected_at=NOW() 18WHERE reservation_id=:p1 19RETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 20""" 21 22 23COUNT_CONSUMER_COLLECTED_RESERVATIONS = """-- name: count_consumer_collected_reservations \\:one 24SELECT COUNT(*) AS collected_count, CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS has_collected 25FROM reservations 26WHERE consumer_id=:p1 AND collected_at IS NOT NULL 27""" 28 29 30class CountConsumerCollectedReservationsRow(pydantic.BaseModel): 31 collected_count: int 32 has_collected: int 33 34 35CREATE_RESERVATION = """-- name: create_reservation \\:one 36INSERT INTO reservations (bundle_id, consumer_id, claim_code) 37VALUES (:p1,:p2,:p3) 38RETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 39""" 40 41 42class CreateReservationParams(pydantic.BaseModel): 43 bundle_id: int 44 consumer_id: int 45 claim_code: str 46 47 48DELETE_RESERVATION = """-- name: delete_reservation \\:one 49DELETE FROM reservations 50WHERE reservation_id = :p1 51RETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 52""" 53 54 55GET_BUNDLE_RESERVATIONS = """-- name: get_bundle_reservations \\:many 56SELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 57FROM reservations 58WHERE bundle_id=:p1 59""" 60 61 62GET_CONSUMERS_RESERVATIONS = """-- name: get_consumers_reservations \\:many 63SELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 64FROM reservations 65WHERE consumer_id=:p1 66""" 67 68 69GET_CONSUMERS_RESERVATIONS_FULL = """-- name: get_consumers_reservations_full \\:many 70SELECT r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.seller_id, b.carbon_dioxide, b.window_start, b.window_end, array_agg(bc.category_id) AS category_ids 71FROM reservations r 72INNER JOIN bundles b ON b.bundle_id = r.bundle_id 73LEFT JOIN bundle_category bc ON bc.bundle_id = r.bundle_id 74WHERE consumer_id=:p1 75GROUP BY r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.seller_id, b.carbon_dioxide, b.window_start, b.window_end 76""" 77 78 79class GetConsumersReservationsFullRow(pydantic.BaseModel): 80 reservation_id: int 81 bundle_id: int 82 reserved_at: datetime.datetime 83 collected_at: Optional[datetime.datetime] 84 seller_id: int 85 carbon_dioxide: int 86 window_start: datetime.datetime 87 window_end: datetime.datetime 88 category_ids: Any 89 90 91GET_RESERVATION = """-- name: get_reservation \\:one 92SELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 93FROM reservations 94WHERE reservation_id=:p1 95""" 96 97 98GET_RESERVATION_COLLECTION = """-- name: get_reservation_collection \\:one 99SELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at 100FROM reservations 101WHERE bundle_id=:p1 AND claim_code=:p2 AND collected_at IS NULL 102LIMIT 1 103""" 104 105 106class GetReservationCollectionParams(pydantic.BaseModel): 107 bundle_id: int 108 claim_code: str 109 110 111GET_RESERVATIONS = """-- name: get_reservations \\:many 112SELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at FROM reservations 113""" 114 115 116GET_SELLER_RESERVATIONS_FULL = """-- name: get_seller_reservations_full \\:many 117SELECT r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.carbon_dioxide, b.window_start, b.window_end, array_agg(bc.category_id) AS category_ids 118FROM reservations r 119INNER JOIN bundles b ON b.bundle_id = r.bundle_id 120LEFT JOIN bundle_category bc ON bc.bundle_id = r.bundle_id 121WHERE b.seller_id=:p1 122GROUP BY r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.carbon_dioxide, b.window_start, b.window_end 123""" 124 125 126class GetSellerReservationsFullRow(pydantic.BaseModel): 127 reservation_id: int 128 bundle_id: int 129 reserved_at: datetime.datetime 130 collected_at: Optional[datetime.datetime] 131 carbon_dioxide: int 132 window_start: datetime.datetime 133 window_end: datetime.datetime 134 category_ids: Any 135 136 137class AsyncQuerier: 138 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 139 self._conn = conn 140 141 async def collect_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 142 row = (await self._conn.execute(sqlalchemy.text(COLLECT_RESERVATION), {"p1": reservation_id})).first() 143 if row is None: 144 return None 145 return models.Reservation( 146 reservation_id=row[0], 147 bundle_id=row[1], 148 consumer_id=row[2], 149 reserved_at=row[3], 150 claim_code=row[4], 151 collected_at=row[5], 152 ) 153 154 async def count_consumer_collected_reservations(self, *, consumer_id: int) -> Optional[CountConsumerCollectedReservationsRow]: 155 row = (await self._conn.execute(sqlalchemy.text(COUNT_CONSUMER_COLLECTED_RESERVATIONS), {"p1": consumer_id})).first() 156 if row is None: 157 return None 158 return CountConsumerCollectedReservationsRow( 159 collected_count=row[0], 160 has_collected=row[1], 161 ) 162 163 async def create_reservation(self, arg: CreateReservationParams) -> Optional[models.Reservation]: 164 row = (await self._conn.execute(sqlalchemy.text(CREATE_RESERVATION), {"p1": arg.bundle_id, "p2": arg.consumer_id, "p3": arg.claim_code})).first() 165 if row is None: 166 return None 167 return models.Reservation( 168 reservation_id=row[0], 169 bundle_id=row[1], 170 consumer_id=row[2], 171 reserved_at=row[3], 172 claim_code=row[4], 173 collected_at=row[5], 174 ) 175 176 async def delete_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 177 row = (await self._conn.execute(sqlalchemy.text(DELETE_RESERVATION), {"p1": reservation_id})).first() 178 if row is None: 179 return None 180 return models.Reservation( 181 reservation_id=row[0], 182 bundle_id=row[1], 183 consumer_id=row[2], 184 reserved_at=row[3], 185 claim_code=row[4], 186 collected_at=row[5], 187 ) 188 189 async def get_bundle_reservations(self, *, bundle_id: int) -> AsyncIterator[models.Reservation]: 190 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_RESERVATIONS), {"p1": bundle_id}) 191 async for row in result: 192 yield models.Reservation( 193 reservation_id=row[0], 194 bundle_id=row[1], 195 consumer_id=row[2], 196 reserved_at=row[3], 197 claim_code=row[4], 198 collected_at=row[5], 199 ) 200 201 async def get_consumers_reservations(self, *, consumer_id: int) -> AsyncIterator[models.Reservation]: 202 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS), {"p1": consumer_id}) 203 async for row in result: 204 yield models.Reservation( 205 reservation_id=row[0], 206 bundle_id=row[1], 207 consumer_id=row[2], 208 reserved_at=row[3], 209 claim_code=row[4], 210 collected_at=row[5], 211 ) 212 213 async def get_consumers_reservations_full(self, *, consumer_id: int) -> AsyncIterator[GetConsumersReservationsFullRow]: 214 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS_FULL), {"p1": consumer_id}) 215 async for row in result: 216 yield GetConsumersReservationsFullRow( 217 reservation_id=row[0], 218 bundle_id=row[1], 219 reserved_at=row[2], 220 collected_at=row[3], 221 seller_id=row[4], 222 carbon_dioxide=row[5], 223 window_start=row[6], 224 window_end=row[7], 225 category_ids=row[8], 226 ) 227 228 async def get_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 229 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION), {"p1": reservation_id})).first() 230 if row is None: 231 return None 232 return models.Reservation( 233 reservation_id=row[0], 234 bundle_id=row[1], 235 consumer_id=row[2], 236 reserved_at=row[3], 237 claim_code=row[4], 238 collected_at=row[5], 239 ) 240 241 async def get_reservation_collection(self, arg: GetReservationCollectionParams) -> Optional[models.Reservation]: 242 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION_COLLECTION), {"p1": arg.bundle_id, "p2": arg.claim_code})).first() 243 if row is None: 244 return None 245 return models.Reservation( 246 reservation_id=row[0], 247 bundle_id=row[1], 248 consumer_id=row[2], 249 reserved_at=row[3], 250 claim_code=row[4], 251 collected_at=row[5], 252 ) 253 254 async def get_reservations(self) -> AsyncIterator[models.Reservation]: 255 result = await self._conn.stream(sqlalchemy.text(GET_RESERVATIONS)) 256 async for row in result: 257 yield models.Reservation( 258 reservation_id=row[0], 259 bundle_id=row[1], 260 consumer_id=row[2], 261 reserved_at=row[3], 262 claim_code=row[4], 263 collected_at=row[5], 264 ) 265 266 async def get_seller_reservations_full(self, *, seller_id: int) -> AsyncIterator[GetSellerReservationsFullRow]: 267 result = await self._conn.stream(sqlalchemy.text(GET_SELLER_RESERVATIONS_FULL), {"p1": seller_id}) 268 async for row in result: 269 yield GetSellerReservationsFullRow( 270 reservation_id=row[0], 271 bundle_id=row[1], 272 reserved_at=row[2], 273 collected_at=row[3], 274 carbon_dioxide=row[4], 275 window_start=row[5], 276 window_end=row[6], 277 category_ids=row[7], 278 )
COLLECT_RESERVATION =
'-- name: collect_reservation \\:one\nUPDATE reservations\nSET collected_at=NOW()\nWHERE reservation_id=:p1\nRETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\n'
COUNT_CONSUMER_COLLECTED_RESERVATIONS =
'-- name: count_consumer_collected_reservations \\:one\nSELECT COUNT(*) AS collected_count, CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS has_collected\nFROM reservations\nWHERE consumer_id=:p1 AND collected_at IS NOT NULL\n'
class
CountConsumerCollectedReservationsRow(pydantic.main.BaseModel):
31class CountConsumerCollectedReservationsRow(pydantic.BaseModel): 32 collected_count: int 33 has_collected: int
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
CREATE_RESERVATION =
'-- name: create_reservation \\:one\nINSERT INTO reservations (bundle_id, consumer_id, claim_code)\nVALUES (:p1,:p2,:p3)\nRETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\n'
class
CreateReservationParams(pydantic.main.BaseModel):
43class CreateReservationParams(pydantic.BaseModel): 44 bundle_id: int 45 consumer_id: int 46 claim_code: str
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
DELETE_RESERVATION =
'-- name: delete_reservation \\:one\nDELETE FROM reservations\nWHERE reservation_id = :p1\nRETURNING reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\n'
GET_BUNDLE_RESERVATIONS =
'-- name: get_bundle_reservations \\:many\nSELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\nFROM reservations\nWHERE bundle_id=:p1\n'
GET_CONSUMERS_RESERVATIONS =
'-- name: get_consumers_reservations \\:many\nSELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\nFROM reservations\nWHERE consumer_id=:p1\n'
GET_CONSUMERS_RESERVATIONS_FULL =
'-- name: get_consumers_reservations_full \\:many\nSELECT r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.seller_id, b.carbon_dioxide, b.window_start, b.window_end, array_agg(bc.category_id) AS category_ids\nFROM reservations r\nINNER JOIN bundles b ON b.bundle_id = r.bundle_id\nLEFT JOIN bundle_category bc ON bc.bundle_id = r.bundle_id\nWHERE consumer_id=:p1\nGROUP BY r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.seller_id, b.carbon_dioxide, b.window_start, b.window_end\n'
class
GetConsumersReservationsFullRow(pydantic.main.BaseModel):
80class GetConsumersReservationsFullRow(pydantic.BaseModel): 81 reservation_id: int 82 bundle_id: int 83 reserved_at: datetime.datetime 84 collected_at: Optional[datetime.datetime] 85 seller_id: int 86 carbon_dioxide: int 87 window_start: datetime.datetime 88 window_end: datetime.datetime 89 category_ids: Any
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
GET_RESERVATION =
'-- name: get_reservation \\:one\nSELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\nFROM reservations\nWHERE reservation_id=:p1\n'
GET_RESERVATION_COLLECTION =
'-- name: get_reservation_collection \\:one\nSELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at\nFROM reservations\nWHERE bundle_id=:p1 AND claim_code=:p2 AND collected_at IS NULL\nLIMIT 1\n'
class
GetReservationCollectionParams(pydantic.main.BaseModel):
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
GET_RESERVATIONS =
'-- name: get_reservations \\:many\nSELECT reservation_id, bundle_id, consumer_id, reserved_at, claim_code, collected_at FROM reservations\n'
GET_SELLER_RESERVATIONS_FULL =
'-- name: get_seller_reservations_full \\:many\nSELECT r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.carbon_dioxide, b.window_start, b.window_end, array_agg(bc.category_id) AS category_ids\nFROM reservations r\nINNER JOIN bundles b ON b.bundle_id = r.bundle_id\nLEFT JOIN bundle_category bc ON bc.bundle_id = r.bundle_id\nWHERE b.seller_id=:p1\nGROUP BY r.reservation_id, r.bundle_id, r.reserved_at, r.collected_at, b.carbon_dioxide, b.window_start, b.window_end\n'
class
GetSellerReservationsFullRow(pydantic.main.BaseModel):
127class GetSellerReservationsFullRow(pydantic.BaseModel): 128 reservation_id: int 129 bundle_id: int 130 reserved_at: datetime.datetime 131 collected_at: Optional[datetime.datetime] 132 carbon_dioxide: int 133 window_start: datetime.datetime 134 window_end: datetime.datetime 135 category_ids: Any
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
- __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
class
AsyncQuerier:
138class AsyncQuerier: 139 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 140 self._conn = conn 141 142 async def collect_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 143 row = (await self._conn.execute(sqlalchemy.text(COLLECT_RESERVATION), {"p1": reservation_id})).first() 144 if row is None: 145 return None 146 return models.Reservation( 147 reservation_id=row[0], 148 bundle_id=row[1], 149 consumer_id=row[2], 150 reserved_at=row[3], 151 claim_code=row[4], 152 collected_at=row[5], 153 ) 154 155 async def count_consumer_collected_reservations(self, *, consumer_id: int) -> Optional[CountConsumerCollectedReservationsRow]: 156 row = (await self._conn.execute(sqlalchemy.text(COUNT_CONSUMER_COLLECTED_RESERVATIONS), {"p1": consumer_id})).first() 157 if row is None: 158 return None 159 return CountConsumerCollectedReservationsRow( 160 collected_count=row[0], 161 has_collected=row[1], 162 ) 163 164 async def create_reservation(self, arg: CreateReservationParams) -> Optional[models.Reservation]: 165 row = (await self._conn.execute(sqlalchemy.text(CREATE_RESERVATION), {"p1": arg.bundle_id, "p2": arg.consumer_id, "p3": arg.claim_code})).first() 166 if row is None: 167 return None 168 return models.Reservation( 169 reservation_id=row[0], 170 bundle_id=row[1], 171 consumer_id=row[2], 172 reserved_at=row[3], 173 claim_code=row[4], 174 collected_at=row[5], 175 ) 176 177 async def delete_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 178 row = (await self._conn.execute(sqlalchemy.text(DELETE_RESERVATION), {"p1": reservation_id})).first() 179 if row is None: 180 return None 181 return models.Reservation( 182 reservation_id=row[0], 183 bundle_id=row[1], 184 consumer_id=row[2], 185 reserved_at=row[3], 186 claim_code=row[4], 187 collected_at=row[5], 188 ) 189 190 async def get_bundle_reservations(self, *, bundle_id: int) -> AsyncIterator[models.Reservation]: 191 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_RESERVATIONS), {"p1": bundle_id}) 192 async for row in result: 193 yield models.Reservation( 194 reservation_id=row[0], 195 bundle_id=row[1], 196 consumer_id=row[2], 197 reserved_at=row[3], 198 claim_code=row[4], 199 collected_at=row[5], 200 ) 201 202 async def get_consumers_reservations(self, *, consumer_id: int) -> AsyncIterator[models.Reservation]: 203 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS), {"p1": consumer_id}) 204 async for row in result: 205 yield models.Reservation( 206 reservation_id=row[0], 207 bundle_id=row[1], 208 consumer_id=row[2], 209 reserved_at=row[3], 210 claim_code=row[4], 211 collected_at=row[5], 212 ) 213 214 async def get_consumers_reservations_full(self, *, consumer_id: int) -> AsyncIterator[GetConsumersReservationsFullRow]: 215 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS_FULL), {"p1": consumer_id}) 216 async for row in result: 217 yield GetConsumersReservationsFullRow( 218 reservation_id=row[0], 219 bundle_id=row[1], 220 reserved_at=row[2], 221 collected_at=row[3], 222 seller_id=row[4], 223 carbon_dioxide=row[5], 224 window_start=row[6], 225 window_end=row[7], 226 category_ids=row[8], 227 ) 228 229 async def get_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 230 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION), {"p1": reservation_id})).first() 231 if row is None: 232 return None 233 return models.Reservation( 234 reservation_id=row[0], 235 bundle_id=row[1], 236 consumer_id=row[2], 237 reserved_at=row[3], 238 claim_code=row[4], 239 collected_at=row[5], 240 ) 241 242 async def get_reservation_collection(self, arg: GetReservationCollectionParams) -> Optional[models.Reservation]: 243 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION_COLLECTION), {"p1": arg.bundle_id, "p2": arg.claim_code})).first() 244 if row is None: 245 return None 246 return models.Reservation( 247 reservation_id=row[0], 248 bundle_id=row[1], 249 consumer_id=row[2], 250 reserved_at=row[3], 251 claim_code=row[4], 252 collected_at=row[5], 253 ) 254 255 async def get_reservations(self) -> AsyncIterator[models.Reservation]: 256 result = await self._conn.stream(sqlalchemy.text(GET_RESERVATIONS)) 257 async for row in result: 258 yield models.Reservation( 259 reservation_id=row[0], 260 bundle_id=row[1], 261 consumer_id=row[2], 262 reserved_at=row[3], 263 claim_code=row[4], 264 collected_at=row[5], 265 ) 266 267 async def get_seller_reservations_full(self, *, seller_id: int) -> AsyncIterator[GetSellerReservationsFullRow]: 268 result = await self._conn.stream(sqlalchemy.text(GET_SELLER_RESERVATIONS_FULL), {"p1": seller_id}) 269 async for row in result: 270 yield GetSellerReservationsFullRow( 271 reservation_id=row[0], 272 bundle_id=row[1], 273 reserved_at=row[2], 274 collected_at=row[3], 275 carbon_dioxide=row[4], 276 window_start=row[5], 277 window_end=row[6], 278 category_ids=row[7], 279 )
async def
collect_reservation( self, *, reservation_id: int) -> internal.queries.models.Reservation | None:
142 async def collect_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 143 row = (await self._conn.execute(sqlalchemy.text(COLLECT_RESERVATION), {"p1": reservation_id})).first() 144 if row is None: 145 return None 146 return models.Reservation( 147 reservation_id=row[0], 148 bundle_id=row[1], 149 consumer_id=row[2], 150 reserved_at=row[3], 151 claim_code=row[4], 152 collected_at=row[5], 153 )
async def
count_consumer_collected_reservations( self, *, consumer_id: int) -> CountConsumerCollectedReservationsRow | None:
155 async def count_consumer_collected_reservations(self, *, consumer_id: int) -> Optional[CountConsumerCollectedReservationsRow]: 156 row = (await self._conn.execute(sqlalchemy.text(COUNT_CONSUMER_COLLECTED_RESERVATIONS), {"p1": consumer_id})).first() 157 if row is None: 158 return None 159 return CountConsumerCollectedReservationsRow( 160 collected_count=row[0], 161 has_collected=row[1], 162 )
async def
create_reservation( self, arg: CreateReservationParams) -> internal.queries.models.Reservation | None:
164 async def create_reservation(self, arg: CreateReservationParams) -> Optional[models.Reservation]: 165 row = (await self._conn.execute(sqlalchemy.text(CREATE_RESERVATION), {"p1": arg.bundle_id, "p2": arg.consumer_id, "p3": arg.claim_code})).first() 166 if row is None: 167 return None 168 return models.Reservation( 169 reservation_id=row[0], 170 bundle_id=row[1], 171 consumer_id=row[2], 172 reserved_at=row[3], 173 claim_code=row[4], 174 collected_at=row[5], 175 )
async def
delete_reservation( self, *, reservation_id: int) -> internal.queries.models.Reservation | None:
177 async def delete_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 178 row = (await self._conn.execute(sqlalchemy.text(DELETE_RESERVATION), {"p1": reservation_id})).first() 179 if row is None: 180 return None 181 return models.Reservation( 182 reservation_id=row[0], 183 bundle_id=row[1], 184 consumer_id=row[2], 185 reserved_at=row[3], 186 claim_code=row[4], 187 collected_at=row[5], 188 )
async def
get_bundle_reservations( self, *, bundle_id: int) -> AsyncIterator[internal.queries.models.Reservation]:
190 async def get_bundle_reservations(self, *, bundle_id: int) -> AsyncIterator[models.Reservation]: 191 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_RESERVATIONS), {"p1": bundle_id}) 192 async for row in result: 193 yield models.Reservation( 194 reservation_id=row[0], 195 bundle_id=row[1], 196 consumer_id=row[2], 197 reserved_at=row[3], 198 claim_code=row[4], 199 collected_at=row[5], 200 )
async def
get_consumers_reservations( self, *, consumer_id: int) -> AsyncIterator[internal.queries.models.Reservation]:
202 async def get_consumers_reservations(self, *, consumer_id: int) -> AsyncIterator[models.Reservation]: 203 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS), {"p1": consumer_id}) 204 async for row in result: 205 yield models.Reservation( 206 reservation_id=row[0], 207 bundle_id=row[1], 208 consumer_id=row[2], 209 reserved_at=row[3], 210 claim_code=row[4], 211 collected_at=row[5], 212 )
async def
get_consumers_reservations_full( self, *, consumer_id: int) -> AsyncIterator[GetConsumersReservationsFullRow]:
214 async def get_consumers_reservations_full(self, *, consumer_id: int) -> AsyncIterator[GetConsumersReservationsFullRow]: 215 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS_RESERVATIONS_FULL), {"p1": consumer_id}) 216 async for row in result: 217 yield GetConsumersReservationsFullRow( 218 reservation_id=row[0], 219 bundle_id=row[1], 220 reserved_at=row[2], 221 collected_at=row[3], 222 seller_id=row[4], 223 carbon_dioxide=row[5], 224 window_start=row[6], 225 window_end=row[7], 226 category_ids=row[8], 227 )
async def
get_reservation( self, *, reservation_id: int) -> internal.queries.models.Reservation | None:
229 async def get_reservation(self, *, reservation_id: int) -> Optional[models.Reservation]: 230 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION), {"p1": reservation_id})).first() 231 if row is None: 232 return None 233 return models.Reservation( 234 reservation_id=row[0], 235 bundle_id=row[1], 236 consumer_id=row[2], 237 reserved_at=row[3], 238 claim_code=row[4], 239 collected_at=row[5], 240 )
async def
get_reservation_collection( self, arg: GetReservationCollectionParams) -> internal.queries.models.Reservation | None:
242 async def get_reservation_collection(self, arg: GetReservationCollectionParams) -> Optional[models.Reservation]: 243 row = (await self._conn.execute(sqlalchemy.text(GET_RESERVATION_COLLECTION), {"p1": arg.bundle_id, "p2": arg.claim_code})).first() 244 if row is None: 245 return None 246 return models.Reservation( 247 reservation_id=row[0], 248 bundle_id=row[1], 249 consumer_id=row[2], 250 reserved_at=row[3], 251 claim_code=row[4], 252 collected_at=row[5], 253 )
255 async def get_reservations(self) -> AsyncIterator[models.Reservation]: 256 result = await self._conn.stream(sqlalchemy.text(GET_RESERVATIONS)) 257 async for row in result: 258 yield models.Reservation( 259 reservation_id=row[0], 260 bundle_id=row[1], 261 consumer_id=row[2], 262 reserved_at=row[3], 263 claim_code=row[4], 264 collected_at=row[5], 265 )
async def
get_seller_reservations_full( self, *, seller_id: int) -> AsyncIterator[GetSellerReservationsFullRow]:
267 async def get_seller_reservations_full(self, *, seller_id: int) -> AsyncIterator[GetSellerReservationsFullRow]: 268 result = await self._conn.stream(sqlalchemy.text(GET_SELLER_RESERVATIONS_FULL), {"p1": seller_id}) 269 async for row in result: 270 yield GetSellerReservationsFullRow( 271 reservation_id=row[0], 272 bundle_id=row[1], 273 reserved_at=row[2], 274 collected_at=row[3], 275 carbon_dioxide=row[4], 276 window_start=row[5], 277 window_end=row[6], 278 category_ids=row[7], 279 )