internal.queries.category

  1# Code generated by sqlc. DO NOT EDIT.
  2# versions:
  3#   sqlc v1.30.0
  4# source: category.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_CATEGORY = """-- name: add_bundles_category \\:one
 15INSERT INTO bundle_category (bundle_id, category_id)
 16VALUES (:p1,:p2)
 17RETURNING category_id, bundle_id
 18"""
 19
 20
 21class AddBundlesCategoryParams(pydantic.BaseModel):
 22    bundle_id: int
 23    category_id: int
 24
 25
 26CREATE_CATEGORY = """-- name: create_category \\:one
 27INSERT INTO category (category_name, category_coefficient)
 28VALUES (:p1, :p2)
 29RETURNING category_id, category_name, category_coefficient
 30"""
 31
 32
 33class CreateCategoryParams(pydantic.BaseModel):
 34    category_name: str
 35    category_coefficient: float
 36
 37
 38DELETE_BUNDLE_CATEGORY = """-- name: delete_bundle_category \\:one
 39DELETE FROM bundle_category
 40WHERE category_id=:p1 AND bundle_id=:p2
 41RETURNING category_id, bundle_id
 42"""
 43
 44
 45class DeleteBundleCategoryParams(pydantic.BaseModel):
 46    category_id: int
 47    bundle_id: int
 48
 49
 50DELETE_CATEGORY = """-- name: delete_category \\:one
 51DELETE FROM category
 52WHERE category_id = :p1
 53RETURNING category_id, category_name, category_coefficient
 54"""
 55
 56
 57GET_BUNDLE_CATEGORIES = """-- name: get_bundle_categories \\:many
 58SELECT c.category_id
 59FROM category c
 60JOIN bundle_category bc ON bc.category_id = c.category_id
 61JOIN bundles b ON b.bundle_id = bc.bundle_id
 62WHERE b.bundle_id=:p1
 63"""
 64
 65
 66GET_CATEGORIES = """-- name: get_categories \\:many
 67SELECT category_id, category_name, category_coefficient
 68FROM category
 69"""
 70
 71
 72GET_CATEGORY = """-- name: get_category \\:one
 73SELECT category_id, category_name, category_coefficient
 74FROM category
 75WHERE category_id=:p1
 76LIMIT 1
 77"""
 78
 79
 80UPDATE_CATEGORY = """-- name: update_category \\:one
 81UPDATE category
 82SET category_name = :p2, category_coefficient = :p3
 83WHERE category_id = :p1
 84RETURNING category_id, category_name, category_coefficient
 85"""
 86
 87
 88class UpdateCategoryParams(pydantic.BaseModel):
 89    category_id: int
 90    category_name: str
 91    category_coefficient: float
 92
 93
 94class AsyncQuerier:
 95    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 96        self._conn = conn
 97
 98    async def add_bundles_category(self, arg: AddBundlesCategoryParams) -> Optional[models.BundleCategory]:
 99        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_CATEGORY), {"p1": arg.bundle_id, "p2": arg.category_id})).first()
100        if row is None:
101            return None
102        return models.BundleCategory(
103            category_id=row[0],
104            bundle_id=row[1],
105        )
106
107    async def create_category(self, arg: CreateCategoryParams) -> Optional[models.Category]:
108        row = (await self._conn.execute(sqlalchemy.text(CREATE_CATEGORY), {"p1": arg.category_name, "p2": arg.category_coefficient})).first()
109        if row is None:
110            return None
111        return models.Category(
112            category_id=row[0],
113            category_name=row[1],
114            category_coefficient=row[2],
115        )
116
117    async def delete_bundle_category(self, arg: DeleteBundleCategoryParams) -> Optional[models.BundleCategory]:
118        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_CATEGORY), {"p1": arg.category_id, "p2": arg.bundle_id})).first()
119        if row is None:
120            return None
121        return models.BundleCategory(
122            category_id=row[0],
123            bundle_id=row[1],
124        )
125
126    async def delete_category(self, *, category_id: int) -> Optional[models.Category]:
127        row = (await self._conn.execute(sqlalchemy.text(DELETE_CATEGORY), {"p1": category_id})).first()
128        if row is None:
129            return None
130        return models.Category(
131            category_id=row[0],
132            category_name=row[1],
133            category_coefficient=row[2],
134        )
135
136    async def get_bundle_categories(self, *, bundle_id: int) -> AsyncIterator[int]:
137        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_CATEGORIES), {"p1": bundle_id})
138        async for row in result:
139            yield row[0]
140
141    async def get_categories(self) -> AsyncIterator[models.Category]:
142        result = await self._conn.stream(sqlalchemy.text(GET_CATEGORIES))
143        async for row in result:
144            yield models.Category(
145                category_id=row[0],
146                category_name=row[1],
147                category_coefficient=row[2],
148            )
149
150    async def get_category(self, *, category_id: int) -> Optional[models.Category]:
151        row = (await self._conn.execute(sqlalchemy.text(GET_CATEGORY), {"p1": category_id})).first()
152        if row is None:
153            return None
154        return models.Category(
155            category_id=row[0],
156            category_name=row[1],
157            category_coefficient=row[2],
158        )
159
160    async def update_category(self, arg: UpdateCategoryParams) -> Optional[models.Category]:
161        row = (await self._conn.execute(sqlalchemy.text(UPDATE_CATEGORY), {"p1": arg.category_id, "p2": arg.category_name, "p3": arg.category_coefficient})).first()
162        if row is None:
163            return None
164        return models.Category(
165            category_id=row[0],
166            category_name=row[1],
167            category_coefficient=row[2],
168        )
ADD_BUNDLES_CATEGORY = '-- name: add_bundles_category \\:one\nINSERT INTO bundle_category (bundle_id, category_id)\nVALUES (:p1,:p2)\nRETURNING category_id, bundle_id\n'
class AddBundlesCategoryParams(pydantic.main.BaseModel):
22class AddBundlesCategoryParams(pydantic.BaseModel):
23    bundle_id: int
24    category_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
category_id: int = PydanticUndefined
CREATE_CATEGORY = '-- name: create_category \\:one\nINSERT INTO category (category_name, category_coefficient)\nVALUES (:p1, :p2)\nRETURNING category_id, category_name, category_coefficient\n'
class CreateCategoryParams(pydantic.main.BaseModel):
34class CreateCategoryParams(pydantic.BaseModel):
35    category_name: str
36    category_coefficient: float

!!! 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.
category_name: str = PydanticUndefined
category_coefficient: float = PydanticUndefined
DELETE_BUNDLE_CATEGORY = '-- name: delete_bundle_category \\:one\nDELETE FROM bundle_category\nWHERE category_id=:p1 AND bundle_id=:p2\nRETURNING category_id, bundle_id\n'
class DeleteBundleCategoryParams(pydantic.main.BaseModel):
46class DeleteBundleCategoryParams(pydantic.BaseModel):
47    category_id: int
48    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.
category_id: int = PydanticUndefined
bundle_id: int = PydanticUndefined
DELETE_CATEGORY = '-- name: delete_category \\:one\nDELETE FROM category\nWHERE category_id = :p1\nRETURNING category_id, category_name, category_coefficient\n'
GET_BUNDLE_CATEGORIES = '-- name: get_bundle_categories \\:many\nSELECT c.category_id\nFROM category c\nJOIN bundle_category bc ON bc.category_id = c.category_id\nJOIN bundles b ON b.bundle_id = bc.bundle_id\nWHERE b.bundle_id=:p1\n'
GET_CATEGORIES = '-- name: get_categories \\:many\nSELECT category_id, category_name, category_coefficient\nFROM category\n'
GET_CATEGORY = '-- name: get_category \\:one\nSELECT category_id, category_name, category_coefficient\nFROM category\nWHERE category_id=:p1\nLIMIT 1\n'
UPDATE_CATEGORY = '-- name: update_category \\:one\nUPDATE category\nSET category_name = :p2, category_coefficient = :p3\nWHERE category_id = :p1\nRETURNING category_id, category_name, category_coefficient\n'
class UpdateCategoryParams(pydantic.main.BaseModel):
89class UpdateCategoryParams(pydantic.BaseModel):
90    category_id: int
91    category_name: str
92    category_coefficient: float

!!! 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.
category_id: int = PydanticUndefined
category_name: str = PydanticUndefined
category_coefficient: float = PydanticUndefined
class AsyncQuerier:
 95class AsyncQuerier:
 96    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 97        self._conn = conn
 98
 99    async def add_bundles_category(self, arg: AddBundlesCategoryParams) -> Optional[models.BundleCategory]:
100        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_CATEGORY), {"p1": arg.bundle_id, "p2": arg.category_id})).first()
101        if row is None:
102            return None
103        return models.BundleCategory(
104            category_id=row[0],
105            bundle_id=row[1],
106        )
107
108    async def create_category(self, arg: CreateCategoryParams) -> Optional[models.Category]:
109        row = (await self._conn.execute(sqlalchemy.text(CREATE_CATEGORY), {"p1": arg.category_name, "p2": arg.category_coefficient})).first()
110        if row is None:
111            return None
112        return models.Category(
113            category_id=row[0],
114            category_name=row[1],
115            category_coefficient=row[2],
116        )
117
118    async def delete_bundle_category(self, arg: DeleteBundleCategoryParams) -> Optional[models.BundleCategory]:
119        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_CATEGORY), {"p1": arg.category_id, "p2": arg.bundle_id})).first()
120        if row is None:
121            return None
122        return models.BundleCategory(
123            category_id=row[0],
124            bundle_id=row[1],
125        )
126
127    async def delete_category(self, *, category_id: int) -> Optional[models.Category]:
128        row = (await self._conn.execute(sqlalchemy.text(DELETE_CATEGORY), {"p1": category_id})).first()
129        if row is None:
130            return None
131        return models.Category(
132            category_id=row[0],
133            category_name=row[1],
134            category_coefficient=row[2],
135        )
136
137    async def get_bundle_categories(self, *, bundle_id: int) -> AsyncIterator[int]:
138        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_CATEGORIES), {"p1": bundle_id})
139        async for row in result:
140            yield row[0]
141
142    async def get_categories(self) -> AsyncIterator[models.Category]:
143        result = await self._conn.stream(sqlalchemy.text(GET_CATEGORIES))
144        async for row in result:
145            yield models.Category(
146                category_id=row[0],
147                category_name=row[1],
148                category_coefficient=row[2],
149            )
150
151    async def get_category(self, *, category_id: int) -> Optional[models.Category]:
152        row = (await self._conn.execute(sqlalchemy.text(GET_CATEGORY), {"p1": category_id})).first()
153        if row is None:
154            return None
155        return models.Category(
156            category_id=row[0],
157            category_name=row[1],
158            category_coefficient=row[2],
159        )
160
161    async def update_category(self, arg: UpdateCategoryParams) -> Optional[models.Category]:
162        row = (await self._conn.execute(sqlalchemy.text(UPDATE_CATEGORY), {"p1": arg.category_id, "p2": arg.category_name, "p3": arg.category_coefficient})).first()
163        if row is None:
164            return None
165        return models.Category(
166            category_id=row[0],
167            category_name=row[1],
168            category_coefficient=row[2],
169        )
AsyncQuerier(conn: sqlalchemy.ext.asyncio.engine.AsyncConnection)
96    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
97        self._conn = conn
async def add_bundles_category( self, arg: AddBundlesCategoryParams) -> internal.queries.models.BundleCategory | None:
 99    async def add_bundles_category(self, arg: AddBundlesCategoryParams) -> Optional[models.BundleCategory]:
100        row = (await self._conn.execute(sqlalchemy.text(ADD_BUNDLES_CATEGORY), {"p1": arg.bundle_id, "p2": arg.category_id})).first()
101        if row is None:
102            return None
103        return models.BundleCategory(
104            category_id=row[0],
105            bundle_id=row[1],
106        )
async def create_category( self, arg: CreateCategoryParams) -> internal.queries.models.Category | None:
108    async def create_category(self, arg: CreateCategoryParams) -> Optional[models.Category]:
109        row = (await self._conn.execute(sqlalchemy.text(CREATE_CATEGORY), {"p1": arg.category_name, "p2": arg.category_coefficient})).first()
110        if row is None:
111            return None
112        return models.Category(
113            category_id=row[0],
114            category_name=row[1],
115            category_coefficient=row[2],
116        )
async def delete_bundle_category( self, arg: DeleteBundleCategoryParams) -> internal.queries.models.BundleCategory | None:
118    async def delete_bundle_category(self, arg: DeleteBundleCategoryParams) -> Optional[models.BundleCategory]:
119        row = (await self._conn.execute(sqlalchemy.text(DELETE_BUNDLE_CATEGORY), {"p1": arg.category_id, "p2": arg.bundle_id})).first()
120        if row is None:
121            return None
122        return models.BundleCategory(
123            category_id=row[0],
124            bundle_id=row[1],
125        )
async def delete_category(self, *, category_id: int) -> internal.queries.models.Category | None:
127    async def delete_category(self, *, category_id: int) -> Optional[models.Category]:
128        row = (await self._conn.execute(sqlalchemy.text(DELETE_CATEGORY), {"p1": category_id})).first()
129        if row is None:
130            return None
131        return models.Category(
132            category_id=row[0],
133            category_name=row[1],
134            category_coefficient=row[2],
135        )
async def get_bundle_categories(self, *, bundle_id: int) -> AsyncIterator[int]:
137    async def get_bundle_categories(self, *, bundle_id: int) -> AsyncIterator[int]:
138        result = await self._conn.stream(sqlalchemy.text(GET_BUNDLE_CATEGORIES), {"p1": bundle_id})
139        async for row in result:
140            yield row[0]
async def get_categories(self) -> AsyncIterator[internal.queries.models.Category]:
142    async def get_categories(self) -> AsyncIterator[models.Category]:
143        result = await self._conn.stream(sqlalchemy.text(GET_CATEGORIES))
144        async for row in result:
145            yield models.Category(
146                category_id=row[0],
147                category_name=row[1],
148                category_coefficient=row[2],
149            )
async def get_category(self, *, category_id: int) -> internal.queries.models.Category | None:
151    async def get_category(self, *, category_id: int) -> Optional[models.Category]:
152        row = (await self._conn.execute(sqlalchemy.text(GET_CATEGORY), {"p1": category_id})).first()
153        if row is None:
154            return None
155        return models.Category(
156            category_id=row[0],
157            category_name=row[1],
158            category_coefficient=row[2],
159        )
async def update_category( self, arg: UpdateCategoryParams) -> internal.queries.models.Category | None:
161    async def update_category(self, arg: UpdateCategoryParams) -> Optional[models.Category]:
162        row = (await self._conn.execute(sqlalchemy.text(UPDATE_CATEGORY), {"p1": arg.category_id, "p2": arg.category_name, "p3": arg.category_coefficient})).first()
163        if row is None:
164            return None
165        return models.Category(
166            category_id=row[0],
167            category_name=row[1],
168            category_coefficient=row[2],
169        )