internal.queries.forecast
1# Code generated by sqlc. DO NOT EDIT. 2# versions: 3# sqlc v1.30.0 4# source: forecast.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_FORECAST_INPUT = """-- name: create_forecast_input \\:one 17INSERT INTO forecast_input (bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows) 18VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11) 19RETURNING input_id, bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows 20""" 21 22 23class CreateForecastInputParams(pydantic.BaseModel): 24 bundle_id: int 25 seller_id: int 26 category_id: int 27 day_of_week: models.DayOfWeek 28 window_start: datetime.datetime 29 window_end: datetime.datetime 30 is_holiday: bool 31 temperature: decimal.Decimal 32 weather_flag: models.WeatherFlag 33 observed_reservations: int 34 observed_no_shows: int 35 36 37GET_FORECAST_INPUTS_BY_SELLER = """-- name: get_forecast_inputs_by_seller \\:many 38SELECT input_id, bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows 39FROM forecast_input 40WHERE seller_id = :p1 41""" 42 43 44GET_FORECAST_OUTPUT_BY_BUNDLE = """-- name: get_forecast_output_by_bundle \\:one 45SELECT output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at 46FROM forecast_output 47WHERE bundle_id = :p1 48LIMIT 1 49""" 50 51 52GET_FORECAST_OUTPUTS_BY_SELLER = """-- name: get_forecast_outputs_by_seller \\:many 53SELECT output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at 54FROM forecast_output 55WHERE seller_id = :p1 56ORDER BY window_start 57""" 58 59 60UPSERT_FORECAST_OUTPUT = """-- name: upsert_forecast_output \\:one 61INSERT INTO forecast_output (bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale) 62VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8) 63ON CONFLICT (bundle_id) DO UPDATE SET 64 predicted_sales = EXCLUDED.predicted_sales, 65 posted_qty = EXCLUDED.posted_qty, 66 predicted_no_show_prob = EXCLUDED.predicted_no_show_prob, 67 confidence = EXCLUDED.confidence, 68 rationale = EXCLUDED.rationale, 69 generated_at = CURRENT_TIMESTAMP 70RETURNING output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at 71""" 72 73 74class UpsertForecastOutputParams(pydantic.BaseModel): 75 bundle_id: int 76 seller_id: int 77 window_start: datetime.datetime 78 predicted_sales: int 79 posted_qty: int 80 predicted_no_show_prob: decimal.Decimal 81 confidence: decimal.Decimal 82 rationale: Optional[str] 83 84 85class AsyncQuerier: 86 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 87 self._conn = conn 88 89 async def create_forecast_input(self, arg: CreateForecastInputParams) -> Optional[models.ForecastInput]: 90 row = (await self._conn.execute(sqlalchemy.text(CREATE_FORECAST_INPUT), { 91 "p1": arg.bundle_id, 92 "p2": arg.seller_id, 93 "p3": arg.category_id, 94 "p4": arg.day_of_week, 95 "p5": arg.window_start, 96 "p6": arg.window_end, 97 "p7": arg.is_holiday, 98 "p8": arg.temperature, 99 "p9": arg.weather_flag, 100 "p10": arg.observed_reservations, 101 "p11": arg.observed_no_shows, 102 })).first() 103 if row is None: 104 return None 105 return models.ForecastInput( 106 input_id=row[0], 107 bundle_id=row[1], 108 seller_id=row[2], 109 category_id=row[3], 110 day_of_week=row[4], 111 window_start=row[5], 112 window_end=row[6], 113 is_holiday=row[7], 114 temperature=row[8], 115 weather_flag=row[9], 116 observed_reservations=row[10], 117 observed_no_shows=row[11], 118 ) 119 120 async def get_forecast_inputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastInput]: 121 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_INPUTS_BY_SELLER), {"p1": seller_id}) 122 async for row in result: 123 yield models.ForecastInput( 124 input_id=row[0], 125 bundle_id=row[1], 126 seller_id=row[2], 127 category_id=row[3], 128 day_of_week=row[4], 129 window_start=row[5], 130 window_end=row[6], 131 is_holiday=row[7], 132 temperature=row[8], 133 weather_flag=row[9], 134 observed_reservations=row[10], 135 observed_no_shows=row[11], 136 ) 137 138 async def get_forecast_output_by_bundle(self, *, bundle_id: int) -> Optional[models.ForecastOutput]: 139 row = (await self._conn.execute(sqlalchemy.text(GET_FORECAST_OUTPUT_BY_BUNDLE), {"p1": bundle_id})).first() 140 if row is None: 141 return None 142 return models.ForecastOutput( 143 output_id=row[0], 144 bundle_id=row[1], 145 seller_id=row[2], 146 window_start=row[3], 147 predicted_sales=row[4], 148 posted_qty=row[5], 149 predicted_no_show_prob=row[6], 150 confidence=row[7], 151 rationale=row[8], 152 generated_at=row[9], 153 ) 154 155 async def get_forecast_outputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastOutput]: 156 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_OUTPUTS_BY_SELLER), {"p1": seller_id}) 157 async for row in result: 158 yield models.ForecastOutput( 159 output_id=row[0], 160 bundle_id=row[1], 161 seller_id=row[2], 162 window_start=row[3], 163 predicted_sales=row[4], 164 posted_qty=row[5], 165 predicted_no_show_prob=row[6], 166 confidence=row[7], 167 rationale=row[8], 168 generated_at=row[9], 169 ) 170 171 async def upsert_forecast_output(self, arg: UpsertForecastOutputParams) -> Optional[models.ForecastOutput]: 172 row = (await self._conn.execute(sqlalchemy.text(UPSERT_FORECAST_OUTPUT), { 173 "p1": arg.bundle_id, 174 "p2": arg.seller_id, 175 "p3": arg.window_start, 176 "p4": arg.predicted_sales, 177 "p5": arg.posted_qty, 178 "p6": arg.predicted_no_show_prob, 179 "p7": arg.confidence, 180 "p8": arg.rationale, 181 })).first() 182 if row is None: 183 return None 184 return models.ForecastOutput( 185 output_id=row[0], 186 bundle_id=row[1], 187 seller_id=row[2], 188 window_start=row[3], 189 predicted_sales=row[4], 190 posted_qty=row[5], 191 predicted_no_show_prob=row[6], 192 confidence=row[7], 193 rationale=row[8], 194 generated_at=row[9], 195 )
CREATE_FORECAST_INPUT =
'-- name: create_forecast_input \\:one\nINSERT INTO forecast_input (bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows)\nVALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11)\nRETURNING input_id, bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows\n'
class
CreateForecastInputParams(pydantic.main.BaseModel):
24class CreateForecastInputParams(pydantic.BaseModel): 25 bundle_id: int 26 seller_id: int 27 category_id: int 28 day_of_week: models.DayOfWeek 29 window_start: datetime.datetime 30 window_end: datetime.datetime 31 is_holiday: bool 32 temperature: decimal.Decimal 33 weather_flag: models.WeatherFlag 34 observed_reservations: int 35 observed_no_shows: 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.
GET_FORECAST_INPUTS_BY_SELLER =
'-- name: get_forecast_inputs_by_seller \\:many\nSELECT input_id, bundle_id, seller_id, category_id, day_of_week, window_start, window_end, is_holiday, temperature, weather_flag, observed_reservations, observed_no_shows\nFROM forecast_input\nWHERE seller_id = :p1\n'
GET_FORECAST_OUTPUT_BY_BUNDLE =
'-- name: get_forecast_output_by_bundle \\:one\nSELECT output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at\nFROM forecast_output\nWHERE bundle_id = :p1\nLIMIT 1\n'
GET_FORECAST_OUTPUTS_BY_SELLER =
'-- name: get_forecast_outputs_by_seller \\:many\nSELECT output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at\nFROM forecast_output\nWHERE seller_id = :p1\nORDER BY window_start\n'
UPSERT_FORECAST_OUTPUT =
'-- name: upsert_forecast_output \\:one\nINSERT INTO forecast_output (bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale)\nVALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8)\nON CONFLICT (bundle_id) DO UPDATE SET\n predicted_sales = EXCLUDED.predicted_sales,\n posted_qty = EXCLUDED.posted_qty,\n predicted_no_show_prob = EXCLUDED.predicted_no_show_prob,\n confidence = EXCLUDED.confidence,\n rationale = EXCLUDED.rationale,\n generated_at = CURRENT_TIMESTAMP\nRETURNING output_id, bundle_id, seller_id, window_start, predicted_sales, posted_qty, predicted_no_show_prob, confidence, rationale, generated_at\n'
class
UpsertForecastOutputParams(pydantic.main.BaseModel):
75class UpsertForecastOutputParams(pydantic.BaseModel): 76 bundle_id: int 77 seller_id: int 78 window_start: datetime.datetime 79 predicted_sales: int 80 posted_qty: int 81 predicted_no_show_prob: decimal.Decimal 82 confidence: decimal.Decimal 83 rationale: Optional[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.
class
AsyncQuerier:
86class AsyncQuerier: 87 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 88 self._conn = conn 89 90 async def create_forecast_input(self, arg: CreateForecastInputParams) -> Optional[models.ForecastInput]: 91 row = (await self._conn.execute(sqlalchemy.text(CREATE_FORECAST_INPUT), { 92 "p1": arg.bundle_id, 93 "p2": arg.seller_id, 94 "p3": arg.category_id, 95 "p4": arg.day_of_week, 96 "p5": arg.window_start, 97 "p6": arg.window_end, 98 "p7": arg.is_holiday, 99 "p8": arg.temperature, 100 "p9": arg.weather_flag, 101 "p10": arg.observed_reservations, 102 "p11": arg.observed_no_shows, 103 })).first() 104 if row is None: 105 return None 106 return models.ForecastInput( 107 input_id=row[0], 108 bundle_id=row[1], 109 seller_id=row[2], 110 category_id=row[3], 111 day_of_week=row[4], 112 window_start=row[5], 113 window_end=row[6], 114 is_holiday=row[7], 115 temperature=row[8], 116 weather_flag=row[9], 117 observed_reservations=row[10], 118 observed_no_shows=row[11], 119 ) 120 121 async def get_forecast_inputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastInput]: 122 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_INPUTS_BY_SELLER), {"p1": seller_id}) 123 async for row in result: 124 yield models.ForecastInput( 125 input_id=row[0], 126 bundle_id=row[1], 127 seller_id=row[2], 128 category_id=row[3], 129 day_of_week=row[4], 130 window_start=row[5], 131 window_end=row[6], 132 is_holiday=row[7], 133 temperature=row[8], 134 weather_flag=row[9], 135 observed_reservations=row[10], 136 observed_no_shows=row[11], 137 ) 138 139 async def get_forecast_output_by_bundle(self, *, bundle_id: int) -> Optional[models.ForecastOutput]: 140 row = (await self._conn.execute(sqlalchemy.text(GET_FORECAST_OUTPUT_BY_BUNDLE), {"p1": bundle_id})).first() 141 if row is None: 142 return None 143 return models.ForecastOutput( 144 output_id=row[0], 145 bundle_id=row[1], 146 seller_id=row[2], 147 window_start=row[3], 148 predicted_sales=row[4], 149 posted_qty=row[5], 150 predicted_no_show_prob=row[6], 151 confidence=row[7], 152 rationale=row[8], 153 generated_at=row[9], 154 ) 155 156 async def get_forecast_outputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastOutput]: 157 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_OUTPUTS_BY_SELLER), {"p1": seller_id}) 158 async for row in result: 159 yield models.ForecastOutput( 160 output_id=row[0], 161 bundle_id=row[1], 162 seller_id=row[2], 163 window_start=row[3], 164 predicted_sales=row[4], 165 posted_qty=row[5], 166 predicted_no_show_prob=row[6], 167 confidence=row[7], 168 rationale=row[8], 169 generated_at=row[9], 170 ) 171 172 async def upsert_forecast_output(self, arg: UpsertForecastOutputParams) -> Optional[models.ForecastOutput]: 173 row = (await self._conn.execute(sqlalchemy.text(UPSERT_FORECAST_OUTPUT), { 174 "p1": arg.bundle_id, 175 "p2": arg.seller_id, 176 "p3": arg.window_start, 177 "p4": arg.predicted_sales, 178 "p5": arg.posted_qty, 179 "p6": arg.predicted_no_show_prob, 180 "p7": arg.confidence, 181 "p8": arg.rationale, 182 })).first() 183 if row is None: 184 return None 185 return models.ForecastOutput( 186 output_id=row[0], 187 bundle_id=row[1], 188 seller_id=row[2], 189 window_start=row[3], 190 predicted_sales=row[4], 191 posted_qty=row[5], 192 predicted_no_show_prob=row[6], 193 confidence=row[7], 194 rationale=row[8], 195 generated_at=row[9], 196 )
async def
create_forecast_input( self, arg: CreateForecastInputParams) -> internal.queries.models.ForecastInput | None:
90 async def create_forecast_input(self, arg: CreateForecastInputParams) -> Optional[models.ForecastInput]: 91 row = (await self._conn.execute(sqlalchemy.text(CREATE_FORECAST_INPUT), { 92 "p1": arg.bundle_id, 93 "p2": arg.seller_id, 94 "p3": arg.category_id, 95 "p4": arg.day_of_week, 96 "p5": arg.window_start, 97 "p6": arg.window_end, 98 "p7": arg.is_holiday, 99 "p8": arg.temperature, 100 "p9": arg.weather_flag, 101 "p10": arg.observed_reservations, 102 "p11": arg.observed_no_shows, 103 })).first() 104 if row is None: 105 return None 106 return models.ForecastInput( 107 input_id=row[0], 108 bundle_id=row[1], 109 seller_id=row[2], 110 category_id=row[3], 111 day_of_week=row[4], 112 window_start=row[5], 113 window_end=row[6], 114 is_holiday=row[7], 115 temperature=row[8], 116 weather_flag=row[9], 117 observed_reservations=row[10], 118 observed_no_shows=row[11], 119 )
async def
get_forecast_inputs_by_seller( self, *, seller_id: int) -> AsyncIterator[internal.queries.models.ForecastInput]:
121 async def get_forecast_inputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastInput]: 122 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_INPUTS_BY_SELLER), {"p1": seller_id}) 123 async for row in result: 124 yield models.ForecastInput( 125 input_id=row[0], 126 bundle_id=row[1], 127 seller_id=row[2], 128 category_id=row[3], 129 day_of_week=row[4], 130 window_start=row[5], 131 window_end=row[6], 132 is_holiday=row[7], 133 temperature=row[8], 134 weather_flag=row[9], 135 observed_reservations=row[10], 136 observed_no_shows=row[11], 137 )
async def
get_forecast_output_by_bundle(self, *, bundle_id: int) -> internal.queries.models.ForecastOutput | None:
139 async def get_forecast_output_by_bundle(self, *, bundle_id: int) -> Optional[models.ForecastOutput]: 140 row = (await self._conn.execute(sqlalchemy.text(GET_FORECAST_OUTPUT_BY_BUNDLE), {"p1": bundle_id})).first() 141 if row is None: 142 return None 143 return models.ForecastOutput( 144 output_id=row[0], 145 bundle_id=row[1], 146 seller_id=row[2], 147 window_start=row[3], 148 predicted_sales=row[4], 149 posted_qty=row[5], 150 predicted_no_show_prob=row[6], 151 confidence=row[7], 152 rationale=row[8], 153 generated_at=row[9], 154 )
async def
get_forecast_outputs_by_seller( self, *, seller_id: int) -> AsyncIterator[internal.queries.models.ForecastOutput]:
156 async def get_forecast_outputs_by_seller(self, *, seller_id: int) -> AsyncIterator[models.ForecastOutput]: 157 result = await self._conn.stream(sqlalchemy.text(GET_FORECAST_OUTPUTS_BY_SELLER), {"p1": seller_id}) 158 async for row in result: 159 yield models.ForecastOutput( 160 output_id=row[0], 161 bundle_id=row[1], 162 seller_id=row[2], 163 window_start=row[3], 164 predicted_sales=row[4], 165 posted_qty=row[5], 166 predicted_no_show_prob=row[6], 167 confidence=row[7], 168 rationale=row[8], 169 generated_at=row[9], 170 )
async def
upsert_forecast_output( self, arg: UpsertForecastOutputParams) -> internal.queries.models.ForecastOutput | None:
172 async def upsert_forecast_output(self, arg: UpsertForecastOutputParams) -> Optional[models.ForecastOutput]: 173 row = (await self._conn.execute(sqlalchemy.text(UPSERT_FORECAST_OUTPUT), { 174 "p1": arg.bundle_id, 175 "p2": arg.seller_id, 176 "p3": arg.window_start, 177 "p4": arg.predicted_sales, 178 "p5": arg.posted_qty, 179 "p6": arg.predicted_no_show_prob, 180 "p7": arg.confidence, 181 "p8": arg.rationale, 182 })).first() 183 if row is None: 184 return None 185 return models.ForecastOutput( 186 output_id=row[0], 187 bundle_id=row[1], 188 seller_id=row[2], 189 window_start=row[3], 190 predicted_sales=row[4], 191 posted_qty=row[5], 192 predicted_no_show_prob=row[6], 193 confidence=row[7], 194 rationale=row[8], 195 generated_at=row[9], 196 )