internal.queries.bundle
1# Code generated by sqlc. DO NOT EDIT. 2# versions: 3# sqlc v1.30.0 4# source: bundle.sql 5import datetime 6import decimal 7import pydantic 8from typing import AsyncIterator, Optional 9 10import sqlalchemy 11import sqlalchemy.ext.asyncio 12 13from internal.queries import models 14 15 16CREATE_BUNDLE = """-- name: create_bundle \\:one 17INSERT INTO bundles (seller_id, bundle_name, description, total_qty, carbon_dioxide, price, discount_percentage, window_start, window_end) 18VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9) 19RETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 20""" 21 22 23class CreateBundleParams(pydantic.BaseModel): 24 seller_id: int 25 bundle_name: str 26 description: str 27 total_qty: int 28 carbon_dioxide: int 29 price: decimal.Decimal 30 discount_percentage: int 31 window_start: datetime.datetime 32 window_end: datetime.datetime 33 34 35DELETE_BUNDLE = """-- name: delete_bundle \\:one 36DELETE FROM bundles 37WHERE bundle_id = :p1 38RETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 39""" 40 41 42GET_BUNDLE = """-- name: get_bundle \\:one 43SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 44FROM bundles 45WHERE bundle_id=:p1 46LIMIT 1 47""" 48 49 50GET_BUNDLE_LOCK = """-- name: get_bundle_lock \\:one 51SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 52FROM bundles 53WHERE bundle_id=:p1 54FOR UPDATE 55LIMIT 1 56""" 57 58 59GET_BUNDLES = """-- name: get_bundles \\:many 60SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 61FROM bundles 62""" 63 64 65GET_SELLERS_ACTIVE_BUNDLES = """-- name: get_sellers_active_bundles \\:many 66SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 67FROM bundles 68WHERE seller_id=:p1 AND window_end >= NOW() 69""" 70 71 72GET_SELLERS_BUNDLE = """-- name: get_sellers_bundle \\:one 73SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 74FROM bundles 75WHERE seller_id=:p1 AND bundle_id=:p2 76LIMIT 1 77""" 78 79 80class GetSellersBundleParams(pydantic.BaseModel): 81 seller_id: int 82 bundle_id: int 83 84 85GET_SELLERS_BUNDLES = """-- name: get_sellers_bundles \\:many 86SELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 87FROM bundles 88WHERE seller_id=:p1 89""" 90 91 92UPDATE_BUNDLE = """-- name: update_bundle \\:one 93UPDATE bundles 94SET bundle_name=:p3, description=:p4, total_qty=:p5, price=:p6, discount_percentage=:p7, window_start=:p8, window_end=:p9, carbon_dioxide=:p10 95WHERE bundle_id=:p1 AND seller_id=:p2 96RETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at 97""" 98 99 100class UpdateBundleParams(pydantic.BaseModel): 101 bundle_id: int 102 seller_id: int 103 bundle_name: str 104 description: str 105 total_qty: int 106 price: decimal.Decimal 107 discount_percentage: int 108 window_start: datetime.datetime 109 window_end: datetime.datetime 110 carbon_dioxide: int 111 112 113class AsyncQuerier: 114 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 115 self._conn = conn 116 117 async def create_bundle(self, arg: CreateBundleParams) -> Optional[models.Bundle]: 118 row = (await self._conn.execute(sqlalchemy.text(CREATE_BUNDLE), { 119 "p1": arg.seller_id, 120 "p2": arg.bundle_name, 121 "p3": arg.description, 122 "p4": arg.total_qty, 123 "p5": arg.carbon_dioxide, 124 "p6": arg.price, 125 "p7": arg.discount_percentage, 126 "p8": arg.window_start, 127 "p9": arg.window_end, 128 })).first() 129 if row is None: 130 return None 131 return models.Bundle( 132 bundle_id=row[0], 133 seller_id=row[1], 134 bundle_name=row[2], 135 description=row[3], 136 carbon_dioxide=row[4], 137 total_qty=row[5], 138 price=row[6], 139 discount_percentage=row[7], 140 window_start=row[8], 141 window_end=row[9], 142 created_at=row[10], 143 ) 144 145 async def delete_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 146 row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE), {"p1": bundle_id})).first() 147 if row is None: 148 return None 149 return models.Bundle( 150 bundle_id=row[0], 151 seller_id=row[1], 152 bundle_name=row[2], 153 description=row[3], 154 carbon_dioxide=row[4], 155 total_qty=row[5], 156 price=row[6], 157 discount_percentage=row[7], 158 window_start=row[8], 159 window_end=row[9], 160 created_at=row[10], 161 ) 162 163 async def get_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 164 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE), {"p1": bundle_id})).first() 165 if row is None: 166 return None 167 return models.Bundle( 168 bundle_id=row[0], 169 seller_id=row[1], 170 bundle_name=row[2], 171 description=row[3], 172 carbon_dioxide=row[4], 173 total_qty=row[5], 174 price=row[6], 175 discount_percentage=row[7], 176 window_start=row[8], 177 window_end=row[9], 178 created_at=row[10], 179 ) 180 181 async def get_bundle_lock(self, *, bundle_id: int) -> Optional[models.Bundle]: 182 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE_LOCK), {"p1": bundle_id})).first() 183 if row is None: 184 return None 185 return models.Bundle( 186 bundle_id=row[0], 187 seller_id=row[1], 188 bundle_name=row[2], 189 description=row[3], 190 carbon_dioxide=row[4], 191 total_qty=row[5], 192 price=row[6], 193 discount_percentage=row[7], 194 window_start=row[8], 195 window_end=row[9], 196 created_at=row[10], 197 ) 198 199 async def get_bundles(self) -> AsyncIterator[models.Bundle]: 200 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLES)) 201 async for row in result: 202 yield models.Bundle( 203 bundle_id=row[0], 204 seller_id=row[1], 205 bundle_name=row[2], 206 description=row[3], 207 carbon_dioxide=row[4], 208 total_qty=row[5], 209 price=row[6], 210 discount_percentage=row[7], 211 window_start=row[8], 212 window_end=row[9], 213 created_at=row[10], 214 ) 215 216 async def get_sellers_active_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 217 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_ACTIVE_BUNDLES), {"p1": seller_id}) 218 async for row in result: 219 yield models.Bundle( 220 bundle_id=row[0], 221 seller_id=row[1], 222 bundle_name=row[2], 223 description=row[3], 224 carbon_dioxide=row[4], 225 total_qty=row[5], 226 price=row[6], 227 discount_percentage=row[7], 228 window_start=row[8], 229 window_end=row[9], 230 created_at=row[10], 231 ) 232 233 async def get_sellers_bundle(self, arg: GetSellersBundleParams) -> Optional[models.Bundle]: 234 row = (await self._conn.execute(sqlalchemy.text(GET_SELLERS_BUNDLE), {"p1": arg.seller_id, "p2": arg.bundle_id})).first() 235 if row is None: 236 return None 237 return models.Bundle( 238 bundle_id=row[0], 239 seller_id=row[1], 240 bundle_name=row[2], 241 description=row[3], 242 carbon_dioxide=row[4], 243 total_qty=row[5], 244 price=row[6], 245 discount_percentage=row[7], 246 window_start=row[8], 247 window_end=row[9], 248 created_at=row[10], 249 ) 250 251 async def get_sellers_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 252 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_BUNDLES), {"p1": seller_id}) 253 async for row in result: 254 yield models.Bundle( 255 bundle_id=row[0], 256 seller_id=row[1], 257 bundle_name=row[2], 258 description=row[3], 259 carbon_dioxide=row[4], 260 total_qty=row[5], 261 price=row[6], 262 discount_percentage=row[7], 263 window_start=row[8], 264 window_end=row[9], 265 created_at=row[10], 266 ) 267 268 async def update_bundle(self, arg: UpdateBundleParams) -> Optional[models.Bundle]: 269 row = (await self._conn.execute(sqlalchemy.text(UPDATE_BUNDLE), { 270 "p1": arg.bundle_id, 271 "p2": arg.seller_id, 272 "p3": arg.bundle_name, 273 "p4": arg.description, 274 "p5": arg.total_qty, 275 "p6": arg.price, 276 "p7": arg.discount_percentage, 277 "p8": arg.window_start, 278 "p9": arg.window_end, 279 "p10": arg.carbon_dioxide, 280 })).first() 281 if row is None: 282 return None 283 return models.Bundle( 284 bundle_id=row[0], 285 seller_id=row[1], 286 bundle_name=row[2], 287 description=row[3], 288 carbon_dioxide=row[4], 289 total_qty=row[5], 290 price=row[6], 291 discount_percentage=row[7], 292 window_start=row[8], 293 window_end=row[9], 294 created_at=row[10], 295 )
CREATE_BUNDLE =
'-- name: create_bundle \\:one\nINSERT INTO bundles (seller_id, bundle_name, description, total_qty, carbon_dioxide, price, discount_percentage, window_start, window_end)\nVALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9)\nRETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\n'
class
CreateBundleParams(pydantic.main.BaseModel):
24class CreateBundleParams(pydantic.BaseModel): 25 seller_id: int 26 bundle_name: str 27 description: str 28 total_qty: int 29 carbon_dioxide: int 30 price: decimal.Decimal 31 discount_percentage: int 32 window_start: datetime.datetime 33 window_end: datetime.datetime
!!! 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_BUNDLE =
'-- name: delete_bundle \\:one\nDELETE FROM bundles\nWHERE bundle_id = :p1\nRETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\n'
GET_BUNDLE =
'-- name: get_bundle \\:one\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\nWHERE bundle_id=:p1\nLIMIT 1\n'
GET_BUNDLE_LOCK =
'-- name: get_bundle_lock \\:one\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\nWHERE bundle_id=:p1\nFOR UPDATE\nLIMIT 1\n'
GET_BUNDLES =
'-- name: get_bundles \\:many\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\n'
GET_SELLERS_ACTIVE_BUNDLES =
'-- name: get_sellers_active_bundles \\:many\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\nWHERE seller_id=:p1 AND window_end >= NOW()\n'
GET_SELLERS_BUNDLE =
'-- name: get_sellers_bundle \\:one\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\nWHERE seller_id=:p1 AND bundle_id=:p2\nLIMIT 1\n'
class
GetSellersBundleParams(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_SELLERS_BUNDLES =
'-- name: get_sellers_bundles \\:many\nSELECT bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\nFROM bundles\nWHERE seller_id=:p1\n'
UPDATE_BUNDLE =
'-- name: update_bundle \\:one\nUPDATE bundles\nSET bundle_name=:p3, description=:p4, total_qty=:p5, price=:p6, discount_percentage=:p7, window_start=:p8, window_end=:p9, carbon_dioxide=:p10\nWHERE bundle_id=:p1 AND seller_id=:p2\nRETURNING bundle_id, seller_id, bundle_name, description, carbon_dioxide, total_qty, price, discount_percentage, window_start, window_end, created_at\n'
class
UpdateBundleParams(pydantic.main.BaseModel):
101class UpdateBundleParams(pydantic.BaseModel): 102 bundle_id: int 103 seller_id: int 104 bundle_name: str 105 description: str 106 total_qty: int 107 price: decimal.Decimal 108 discount_percentage: int 109 window_start: datetime.datetime 110 window_end: datetime.datetime 111 carbon_dioxide: 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.
class
AsyncQuerier:
114class AsyncQuerier: 115 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 116 self._conn = conn 117 118 async def create_bundle(self, arg: CreateBundleParams) -> Optional[models.Bundle]: 119 row = (await self._conn.execute(sqlalchemy.text(CREATE_BUNDLE), { 120 "p1": arg.seller_id, 121 "p2": arg.bundle_name, 122 "p3": arg.description, 123 "p4": arg.total_qty, 124 "p5": arg.carbon_dioxide, 125 "p6": arg.price, 126 "p7": arg.discount_percentage, 127 "p8": arg.window_start, 128 "p9": arg.window_end, 129 })).first() 130 if row is None: 131 return None 132 return models.Bundle( 133 bundle_id=row[0], 134 seller_id=row[1], 135 bundle_name=row[2], 136 description=row[3], 137 carbon_dioxide=row[4], 138 total_qty=row[5], 139 price=row[6], 140 discount_percentage=row[7], 141 window_start=row[8], 142 window_end=row[9], 143 created_at=row[10], 144 ) 145 146 async def delete_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 147 row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE), {"p1": bundle_id})).first() 148 if row is None: 149 return None 150 return models.Bundle( 151 bundle_id=row[0], 152 seller_id=row[1], 153 bundle_name=row[2], 154 description=row[3], 155 carbon_dioxide=row[4], 156 total_qty=row[5], 157 price=row[6], 158 discount_percentage=row[7], 159 window_start=row[8], 160 window_end=row[9], 161 created_at=row[10], 162 ) 163 164 async def get_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 165 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE), {"p1": bundle_id})).first() 166 if row is None: 167 return None 168 return models.Bundle( 169 bundle_id=row[0], 170 seller_id=row[1], 171 bundle_name=row[2], 172 description=row[3], 173 carbon_dioxide=row[4], 174 total_qty=row[5], 175 price=row[6], 176 discount_percentage=row[7], 177 window_start=row[8], 178 window_end=row[9], 179 created_at=row[10], 180 ) 181 182 async def get_bundle_lock(self, *, bundle_id: int) -> Optional[models.Bundle]: 183 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE_LOCK), {"p1": bundle_id})).first() 184 if row is None: 185 return None 186 return models.Bundle( 187 bundle_id=row[0], 188 seller_id=row[1], 189 bundle_name=row[2], 190 description=row[3], 191 carbon_dioxide=row[4], 192 total_qty=row[5], 193 price=row[6], 194 discount_percentage=row[7], 195 window_start=row[8], 196 window_end=row[9], 197 created_at=row[10], 198 ) 199 200 async def get_bundles(self) -> AsyncIterator[models.Bundle]: 201 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLES)) 202 async for row in result: 203 yield models.Bundle( 204 bundle_id=row[0], 205 seller_id=row[1], 206 bundle_name=row[2], 207 description=row[3], 208 carbon_dioxide=row[4], 209 total_qty=row[5], 210 price=row[6], 211 discount_percentage=row[7], 212 window_start=row[8], 213 window_end=row[9], 214 created_at=row[10], 215 ) 216 217 async def get_sellers_active_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 218 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_ACTIVE_BUNDLES), {"p1": seller_id}) 219 async for row in result: 220 yield models.Bundle( 221 bundle_id=row[0], 222 seller_id=row[1], 223 bundle_name=row[2], 224 description=row[3], 225 carbon_dioxide=row[4], 226 total_qty=row[5], 227 price=row[6], 228 discount_percentage=row[7], 229 window_start=row[8], 230 window_end=row[9], 231 created_at=row[10], 232 ) 233 234 async def get_sellers_bundle(self, arg: GetSellersBundleParams) -> Optional[models.Bundle]: 235 row = (await self._conn.execute(sqlalchemy.text(GET_SELLERS_BUNDLE), {"p1": arg.seller_id, "p2": arg.bundle_id})).first() 236 if row is None: 237 return None 238 return models.Bundle( 239 bundle_id=row[0], 240 seller_id=row[1], 241 bundle_name=row[2], 242 description=row[3], 243 carbon_dioxide=row[4], 244 total_qty=row[5], 245 price=row[6], 246 discount_percentage=row[7], 247 window_start=row[8], 248 window_end=row[9], 249 created_at=row[10], 250 ) 251 252 async def get_sellers_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 253 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_BUNDLES), {"p1": seller_id}) 254 async for row in result: 255 yield models.Bundle( 256 bundle_id=row[0], 257 seller_id=row[1], 258 bundle_name=row[2], 259 description=row[3], 260 carbon_dioxide=row[4], 261 total_qty=row[5], 262 price=row[6], 263 discount_percentage=row[7], 264 window_start=row[8], 265 window_end=row[9], 266 created_at=row[10], 267 ) 268 269 async def update_bundle(self, arg: UpdateBundleParams) -> Optional[models.Bundle]: 270 row = (await self._conn.execute(sqlalchemy.text(UPDATE_BUNDLE), { 271 "p1": arg.bundle_id, 272 "p2": arg.seller_id, 273 "p3": arg.bundle_name, 274 "p4": arg.description, 275 "p5": arg.total_qty, 276 "p6": arg.price, 277 "p7": arg.discount_percentage, 278 "p8": arg.window_start, 279 "p9": arg.window_end, 280 "p10": arg.carbon_dioxide, 281 })).first() 282 if row is None: 283 return None 284 return models.Bundle( 285 bundle_id=row[0], 286 seller_id=row[1], 287 bundle_name=row[2], 288 description=row[3], 289 carbon_dioxide=row[4], 290 total_qty=row[5], 291 price=row[6], 292 discount_percentage=row[7], 293 window_start=row[8], 294 window_end=row[9], 295 created_at=row[10], 296 )
118 async def create_bundle(self, arg: CreateBundleParams) -> Optional[models.Bundle]: 119 row = (await self._conn.execute(sqlalchemy.text(CREATE_BUNDLE), { 120 "p1": arg.seller_id, 121 "p2": arg.bundle_name, 122 "p3": arg.description, 123 "p4": arg.total_qty, 124 "p5": arg.carbon_dioxide, 125 "p6": arg.price, 126 "p7": arg.discount_percentage, 127 "p8": arg.window_start, 128 "p9": arg.window_end, 129 })).first() 130 if row is None: 131 return None 132 return models.Bundle( 133 bundle_id=row[0], 134 seller_id=row[1], 135 bundle_name=row[2], 136 description=row[3], 137 carbon_dioxide=row[4], 138 total_qty=row[5], 139 price=row[6], 140 discount_percentage=row[7], 141 window_start=row[8], 142 window_end=row[9], 143 created_at=row[10], 144 )
146 async def delete_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 147 row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE), {"p1": bundle_id})).first() 148 if row is None: 149 return None 150 return models.Bundle( 151 bundle_id=row[0], 152 seller_id=row[1], 153 bundle_name=row[2], 154 description=row[3], 155 carbon_dioxide=row[4], 156 total_qty=row[5], 157 price=row[6], 158 discount_percentage=row[7], 159 window_start=row[8], 160 window_end=row[9], 161 created_at=row[10], 162 )
164 async def get_bundle(self, *, bundle_id: int) -> Optional[models.Bundle]: 165 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE), {"p1": bundle_id})).first() 166 if row is None: 167 return None 168 return models.Bundle( 169 bundle_id=row[0], 170 seller_id=row[1], 171 bundle_name=row[2], 172 description=row[3], 173 carbon_dioxide=row[4], 174 total_qty=row[5], 175 price=row[6], 176 discount_percentage=row[7], 177 window_start=row[8], 178 window_end=row[9], 179 created_at=row[10], 180 )
182 async def get_bundle_lock(self, *, bundle_id: int) -> Optional[models.Bundle]: 183 row = (await self._conn.execute(sqlalchemy.text(GET_BUNDLE_LOCK), {"p1": bundle_id})).first() 184 if row is None: 185 return None 186 return models.Bundle( 187 bundle_id=row[0], 188 seller_id=row[1], 189 bundle_name=row[2], 190 description=row[3], 191 carbon_dioxide=row[4], 192 total_qty=row[5], 193 price=row[6], 194 discount_percentage=row[7], 195 window_start=row[8], 196 window_end=row[9], 197 created_at=row[10], 198 )
200 async def get_bundles(self) -> AsyncIterator[models.Bundle]: 201 result = await self._conn.stream(sqlalchemy.text(GET_BUNDLES)) 202 async for row in result: 203 yield models.Bundle( 204 bundle_id=row[0], 205 seller_id=row[1], 206 bundle_name=row[2], 207 description=row[3], 208 carbon_dioxide=row[4], 209 total_qty=row[5], 210 price=row[6], 211 discount_percentage=row[7], 212 window_start=row[8], 213 window_end=row[9], 214 created_at=row[10], 215 )
async def
get_sellers_active_bundles(self, *, seller_id: int) -> AsyncIterator[internal.queries.models.Bundle]:
217 async def get_sellers_active_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 218 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_ACTIVE_BUNDLES), {"p1": seller_id}) 219 async for row in result: 220 yield models.Bundle( 221 bundle_id=row[0], 222 seller_id=row[1], 223 bundle_name=row[2], 224 description=row[3], 225 carbon_dioxide=row[4], 226 total_qty=row[5], 227 price=row[6], 228 discount_percentage=row[7], 229 window_start=row[8], 230 window_end=row[9], 231 created_at=row[10], 232 )
async def
get_sellers_bundle( self, arg: GetSellersBundleParams) -> internal.queries.models.Bundle | None:
234 async def get_sellers_bundle(self, arg: GetSellersBundleParams) -> Optional[models.Bundle]: 235 row = (await self._conn.execute(sqlalchemy.text(GET_SELLERS_BUNDLE), {"p1": arg.seller_id, "p2": arg.bundle_id})).first() 236 if row is None: 237 return None 238 return models.Bundle( 239 bundle_id=row[0], 240 seller_id=row[1], 241 bundle_name=row[2], 242 description=row[3], 243 carbon_dioxide=row[4], 244 total_qty=row[5], 245 price=row[6], 246 discount_percentage=row[7], 247 window_start=row[8], 248 window_end=row[9], 249 created_at=row[10], 250 )
async def
get_sellers_bundles(self, *, seller_id: int) -> AsyncIterator[internal.queries.models.Bundle]:
252 async def get_sellers_bundles(self, *, seller_id: int) -> AsyncIterator[models.Bundle]: 253 result = await self._conn.stream(sqlalchemy.text(GET_SELLERS_BUNDLES), {"p1": seller_id}) 254 async for row in result: 255 yield models.Bundle( 256 bundle_id=row[0], 257 seller_id=row[1], 258 bundle_name=row[2], 259 description=row[3], 260 carbon_dioxide=row[4], 261 total_qty=row[5], 262 price=row[6], 263 discount_percentage=row[7], 264 window_start=row[8], 265 window_end=row[9], 266 created_at=row[10], 267 )
269 async def update_bundle(self, arg: UpdateBundleParams) -> Optional[models.Bundle]: 270 row = (await self._conn.execute(sqlalchemy.text(UPDATE_BUNDLE), { 271 "p1": arg.bundle_id, 272 "p2": arg.seller_id, 273 "p3": arg.bundle_name, 274 "p4": arg.description, 275 "p5": arg.total_qty, 276 "p6": arg.price, 277 "p7": arg.discount_percentage, 278 "p8": arg.window_start, 279 "p9": arg.window_end, 280 "p10": arg.carbon_dioxide, 281 })).first() 282 if row is None: 283 return None 284 return models.Bundle( 285 bundle_id=row[0], 286 seller_id=row[1], 287 bundle_name=row[2], 288 description=row[3], 289 carbon_dioxide=row[4], 290 total_qty=row[5], 291 price=row[6], 292 discount_percentage=row[7], 293 window_start=row[8], 294 window_end=row[9], 295 created_at=row[10], 296 )