internal.queries.allergens

  1# Code generated by sqlc. DO NOT EDIT.
  2# versions:
  3#   sqlc v1.30.0
  4# source: allergens.sql
  5import pydantic
  6from typing import AsyncIterator, Optional
  7
  8import sqlalchemy
  9import sqlalchemy.ext.asyncio
 10
 11from internal.queries import models
 12
 13
 14ADD_BUNDLES_ALLERGEN = """-- name: add_bundles_allergen \\:one
 15INSERT INTO bundle_allergens (bundle_id, allergen_id)
 16VALUES (:p1,:p2)
 17RETURNING bundle_id, allergen_id
 18"""
 19
 20
 21class AddBundlesAllergenParams(pydantic.BaseModel):
 22    bundle_id: int
 23    allergen_id: int
 24
 25
 26CREATE_ALLERGEN = """-- name: create_allergen \\:one
 27INSERT INTO allergens (allergen_name)
 28VALUES (:p1)
 29RETURNING allergen_id, allergen_name
 30"""
 31
 32
 33DELETE_ALLERGEN = """-- name: delete_allergen \\:one
 34DELETE FROM allergens
 35WHERE allergen_id = :p1
 36RETURNING allergen_id, allergen_name
 37"""
 38
 39
 40DELETE_BUNDLE_ALLERGEN = """-- name: delete_bundle_allergen \\:one
 41DELETE FROM bundle_allergens
 42WHERE allergen_id=:p1 AND bundle_id=:p2
 43RETURNING bundle_id, allergen_id
 44"""
 45
 46
 47class DeleteBundleAllergenParams(pydantic.BaseModel):
 48    allergen_id: int
 49    bundle_id: int
 50
 51
 52GET_ALLERGENS = """-- name: get_allergens \\:many
 53SELECT allergen_id, allergen_name
 54FROM allergens
 55"""
 56
 57
 58GET_BUNDLE_ALLERGENS = """-- name: get_bundle_allergens \\:many
 59SELECT a.allergen_id
 60FROM allergens a
 61JOIN bundle_allergens ba ON ba.allergen_id = a.allergen_id
 62JOIN bundles b ON b.bundle_id = ba.bundle_id
 63WHERE b.bundle_id=:p1
 64"""
 65
 66
 67UPDATE_ALLERGEN = """-- name: update_allergen \\:one
 68UPDATE allergens
 69SET allergen_name = :p2
 70WHERE allergen_id = :p1
 71RETURNING allergen_id, allergen_name
 72"""
 73
 74
 75class UpdateAllergenParams(pydantic.BaseModel):
 76    allergen_id: int
 77    allergen_name: str
 78
 79
 80class AsyncQuerier:
 81    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 82        self._conn = conn
 83
 84    async def add_bundles_allergen(self, arg: AddBundlesAllergenParams) -> Optional[models.BundleAllergen]:
 85        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_ALLERGEN), {"p1": arg.bundle_id, "p2": arg.allergen_id})).first()
 86        if row is None:
 87            return None
 88        return models.BundleAllergen(
 89            bundle_id=row[0],
 90            allergen_id=row[1],
 91        )
 92
 93    async def create_allergen(self, *, allergen_name: str) -> Optional[models.Allergen]:
 94        row = (await self._conn.execute(sqlalchemy.text(CREATE_ALLERGEN), {"p1": allergen_name})).first()
 95        if row is None:
 96            return None
 97        return models.Allergen(
 98            allergen_id=row[0],
 99            allergen_name=row[1],
100        )
101
102    async def delete_allergen(self, *, allergen_id: int) -> Optional[models.Allergen]:
103        row = (await self._conn.execute(sqlalchemy.text(DELETE_ALLERGEN), {"p1": allergen_id})).first()
104        if row is None:
105            return None
106        return models.Allergen(
107            allergen_id=row[0],
108            allergen_name=row[1],
109        )
110
111    async def delete_bundle_allergen(self, arg: DeleteBundleAllergenParams) -> Optional[models.BundleAllergen]:
112        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.bundle_id})).first()
113        if row is None:
114            return None
115        return models.BundleAllergen(
116            bundle_id=row[0],
117            allergen_id=row[1],
118        )
119
120    async def get_allergens(self) -> AsyncIterator[models.Allergen]:
121        result = await self._conn.stream(sqlalchemy.text(GET_ALLERGENS))
122        async for row in result:
123            yield models.Allergen(
124                allergen_id=row[0],
125                allergen_name=row[1],
126            )
127
128    async def get_bundle_allergens(self, *, bundle_id: int) -> AsyncIterator[int]:
129        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_ALLERGENS), {"p1": bundle_id})
130        async for row in result:
131            yield row[0]
132
133    async def update_allergen(self, arg: UpdateAllergenParams) -> Optional[models.Allergen]:
134        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.allergen_name})).first()
135        if row is None:
136            return None
137        return models.Allergen(
138            allergen_id=row[0],
139            allergen_name=row[1],
140        )
ADD_BUNDLES_ALLERGEN = '-- name: add_bundles_allergen \\:one\nINSERT INTO bundle_allergens (bundle_id, allergen_id)\nVALUES (:p1,:p2)\nRETURNING bundle_id, allergen_id\n'
class AddBundlesAllergenParams(pydantic.main.BaseModel):
22class AddBundlesAllergenParams(pydantic.BaseModel):
23    bundle_id: int
24    allergen_id: 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__ and Model.__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-core SchemaSerializer used to dump instances of the model.
  • __pydantic_validator__: The pydantic-core SchemaValidator used 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.
bundle_id: int = PydanticUndefined
allergen_id: int = PydanticUndefined
CREATE_ALLERGEN = '-- name: create_allergen \\:one\nINSERT INTO allergens (allergen_name)\nVALUES (:p1)\nRETURNING allergen_id, allergen_name\n'
DELETE_ALLERGEN = '-- name: delete_allergen \\:one\nDELETE FROM allergens\nWHERE allergen_id = :p1\nRETURNING allergen_id, allergen_name\n'
DELETE_BUNDLE_ALLERGEN = '-- name: delete_bundle_allergen \\:one\nDELETE FROM bundle_allergens\nWHERE allergen_id=:p1 AND bundle_id=:p2\nRETURNING bundle_id, allergen_id\n'
class DeleteBundleAllergenParams(pydantic.main.BaseModel):
48class DeleteBundleAllergenParams(pydantic.BaseModel):
49    allergen_id: int
50    bundle_id: 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__ and Model.__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-core SchemaSerializer used to dump instances of the model.
  • __pydantic_validator__: The pydantic-core SchemaValidator used 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.
allergen_id: int = PydanticUndefined
bundle_id: int = PydanticUndefined
GET_ALLERGENS = '-- name: get_allergens \\:many\nSELECT allergen_id, allergen_name\nFROM allergens\n'
GET_BUNDLE_ALLERGENS = '-- name: get_bundle_allergens \\:many\nSELECT a.allergen_id\nFROM allergens a\nJOIN bundle_allergens ba ON ba.allergen_id = a.allergen_id\nJOIN bundles b ON b.bundle_id = ba.bundle_id\nWHERE b.bundle_id=:p1\n'
UPDATE_ALLERGEN = '-- name: update_allergen \\:one\nUPDATE allergens\nSET allergen_name = :p2\nWHERE allergen_id = :p1\nRETURNING allergen_id, allergen_name\n'
class UpdateAllergenParams(pydantic.main.BaseModel):
76class UpdateAllergenParams(pydantic.BaseModel):
77    allergen_id: int
78    allergen_name: 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__ and Model.__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-core SchemaSerializer used to dump instances of the model.
  • __pydantic_validator__: The pydantic-core SchemaValidator used 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.
allergen_id: int = PydanticUndefined
allergen_name: str = PydanticUndefined
class AsyncQuerier:
 81class AsyncQuerier:
 82    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 83        self._conn = conn
 84
 85    async def add_bundles_allergen(self, arg: AddBundlesAllergenParams) -> Optional[models.BundleAllergen]:
 86        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_ALLERGEN), {"p1": arg.bundle_id, "p2": arg.allergen_id})).first()
 87        if row is None:
 88            return None
 89        return models.BundleAllergen(
 90            bundle_id=row[0],
 91            allergen_id=row[1],
 92        )
 93
 94    async def create_allergen(self, *, allergen_name: str) -> Optional[models.Allergen]:
 95        row = (await self._conn.execute(sqlalchemy.text(CREATE_ALLERGEN), {"p1": allergen_name})).first()
 96        if row is None:
 97            return None
 98        return models.Allergen(
 99            allergen_id=row[0],
100            allergen_name=row[1],
101        )
102
103    async def delete_allergen(self, *, allergen_id: int) -> Optional[models.Allergen]:
104        row = (await self._conn.execute(sqlalchemy.text(DELETE_ALLERGEN), {"p1": allergen_id})).first()
105        if row is None:
106            return None
107        return models.Allergen(
108            allergen_id=row[0],
109            allergen_name=row[1],
110        )
111
112    async def delete_bundle_allergen(self, arg: DeleteBundleAllergenParams) -> Optional[models.BundleAllergen]:
113        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.bundle_id})).first()
114        if row is None:
115            return None
116        return models.BundleAllergen(
117            bundle_id=row[0],
118            allergen_id=row[1],
119        )
120
121    async def get_allergens(self) -> AsyncIterator[models.Allergen]:
122        result = await self._conn.stream(sqlalchemy.text(GET_ALLERGENS))
123        async for row in result:
124            yield models.Allergen(
125                allergen_id=row[0],
126                allergen_name=row[1],
127            )
128
129    async def get_bundle_allergens(self, *, bundle_id: int) -> AsyncIterator[int]:
130        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_ALLERGENS), {"p1": bundle_id})
131        async for row in result:
132            yield row[0]
133
134    async def update_allergen(self, arg: UpdateAllergenParams) -> Optional[models.Allergen]:
135        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.allergen_name})).first()
136        if row is None:
137            return None
138        return models.Allergen(
139            allergen_id=row[0],
140            allergen_name=row[1],
141        )
AsyncQuerier(conn: sqlalchemy.ext.asyncio.engine.AsyncConnection)
82    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
83        self._conn = conn
async def add_bundles_allergen( self, arg: AddBundlesAllergenParams) -> internal.queries.models.BundleAllergen | None:
85    async def add_bundles_allergen(self, arg: AddBundlesAllergenParams) -> Optional[models.BundleAllergen]:
86        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_ALLERGEN), {"p1": arg.bundle_id, "p2": arg.allergen_id})).first()
87        if row is None:
88            return None
89        return models.BundleAllergen(
90            bundle_id=row[0],
91            allergen_id=row[1],
92        )
async def create_allergen(self, *, allergen_name: str) -> internal.queries.models.Allergen | None:
 94    async def create_allergen(self, *, allergen_name: str) -> Optional[models.Allergen]:
 95        row = (await self._conn.execute(sqlalchemy.text(CREATE_ALLERGEN), {"p1": allergen_name})).first()
 96        if row is None:
 97            return None
 98        return models.Allergen(
 99            allergen_id=row[0],
100            allergen_name=row[1],
101        )
async def delete_allergen(self, *, allergen_id: int) -> internal.queries.models.Allergen | None:
103    async def delete_allergen(self, *, allergen_id: int) -> Optional[models.Allergen]:
104        row = (await self._conn.execute(sqlalchemy.text(DELETE_ALLERGEN), {"p1": allergen_id})).first()
105        if row is None:
106            return None
107        return models.Allergen(
108            allergen_id=row[0],
109            allergen_name=row[1],
110        )
async def delete_bundle_allergen( self, arg: DeleteBundleAllergenParams) -> internal.queries.models.BundleAllergen | None:
112    async def delete_bundle_allergen(self, arg: DeleteBundleAllergenParams) -> Optional[models.BundleAllergen]:
113        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.bundle_id})).first()
114        if row is None:
115            return None
116        return models.BundleAllergen(
117            bundle_id=row[0],
118            allergen_id=row[1],
119        )
async def get_allergens(self) -> AsyncIterator[internal.queries.models.Allergen]:
121    async def get_allergens(self) -> AsyncIterator[models.Allergen]:
122        result = await self._conn.stream(sqlalchemy.text(GET_ALLERGENS))
123        async for row in result:
124            yield models.Allergen(
125                allergen_id=row[0],
126                allergen_name=row[1],
127            )
async def get_bundle_allergens(self, *, bundle_id: int) -> AsyncIterator[int]:
129    async def get_bundle_allergens(self, *, bundle_id: int) -> AsyncIterator[int]:
130        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_ALLERGENS), {"p1": bundle_id})
131        async for row in result:
132            yield row[0]
async def update_allergen( self, arg: UpdateAllergenParams) -> internal.queries.models.Allergen | None:
134    async def update_allergen(self, arg: UpdateAllergenParams) -> Optional[models.Allergen]:
135        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ALLERGEN), {"p1": arg.allergen_id, "p2": arg.allergen_name})).first()
136        if row is None:
137            return None
138        return models.Allergen(
139            allergen_id=row[0],
140            allergen_name=row[1],
141        )