internal.queries.consumer
1# Code generated by sqlc. DO NOT EDIT. 2# versions: 3# sqlc v1.30.0 4# source: consumer.sql 5import datetime 6import pydantic 7from typing import AsyncIterator, Optional 8 9import sqlalchemy 10import sqlalchemy.ext.asyncio 11 12from internal.queries import models 13 14 15CREATE_CONSUMER = """-- name: create_consumer \\:one 16INSERT INTO consumers (user_id, fName, lName) 17VALUES (:p1, :p2, :p3) 18RETURNING user_id, fname, lname 19""" 20 21 22class CreateConsumerParams(pydantic.BaseModel): 23 user_id: int 24 fname: str 25 lname: str 26 27 28GET_CONSUMER = """-- name: get_consumer \\:one 29SELECT u.user_id, u.username, u.email, c.fName, c.lName, u.last_login, u.created_at 30FROM consumers c 31INNER JOIN users u ON c.user_id = u.user_id 32WHERE u.user_id=:p1 33LIMIT 1 34""" 35 36 37class GetConsumerRow(pydantic.BaseModel): 38 user_id: int 39 username: str 40 email: str 41 fname: str 42 lname: str 43 last_login: datetime.datetime 44 created_at: datetime.datetime 45 46 47GET_CONSUMERS = """-- name: get_consumers \\:many 48SELECT u.user_id, u.username, u.email, c.fName, c.lName, u.last_login, u.created_at 49FROM consumers c 50INNER JOIN users u ON c.user_id = u.user_id 51""" 52 53 54class GetConsumersRow(pydantic.BaseModel): 55 user_id: int 56 username: str 57 email: str 58 fname: str 59 lname: str 60 last_login: datetime.datetime 61 created_at: datetime.datetime 62 63 64UPDATE_CONSUMER = """-- name: update_consumer \\:one 65UPDATE consumers 66SET fName=:p2, lName=:p3 67WHERE user_id=:p1 68RETURNING user_id, fname, lname 69""" 70 71 72class UpdateConsumerParams(pydantic.BaseModel): 73 user_id: int 74 fname: str 75 lname: str 76 77 78class AsyncQuerier: 79 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 80 self._conn = conn 81 82 async def create_consumer(self, arg: CreateConsumerParams) -> Optional[models.Consumer]: 83 row = (await self._conn.execute(sqlalchemy.text(CREATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 84 if row is None: 85 return None 86 return models.Consumer( 87 user_id=row[0], 88 fname=row[1], 89 lname=row[2], 90 ) 91 92 async def get_consumer(self, *, user_id: int) -> Optional[GetConsumerRow]: 93 row = (await self._conn.execute(sqlalchemy.text(GET_CONSUMER), {"p1": user_id})).first() 94 if row is None: 95 return None 96 return GetConsumerRow( 97 user_id=row[0], 98 username=row[1], 99 email=row[2], 100 fname=row[3], 101 lname=row[4], 102 last_login=row[5], 103 created_at=row[6], 104 ) 105 106 async def get_consumers(self) -> AsyncIterator[GetConsumersRow]: 107 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS)) 108 async for row in result: 109 yield GetConsumersRow( 110 user_id=row[0], 111 username=row[1], 112 email=row[2], 113 fname=row[3], 114 lname=row[4], 115 last_login=row[5], 116 created_at=row[6], 117 ) 118 119 async def update_consumer(self, arg: UpdateConsumerParams) -> Optional[models.Consumer]: 120 row = (await self._conn.execute(sqlalchemy.text(UPDATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 121 if row is None: 122 return None 123 return models.Consumer( 124 user_id=row[0], 125 fname=row[1], 126 lname=row[2], 127 )
CREATE_CONSUMER =
'-- name: create_consumer \\:one\nINSERT INTO consumers (user_id, fName, lName)\nVALUES (:p1, :p2, :p3)\nRETURNING user_id, fname, lname\n'
class
CreateConsumerParams(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_CONSUMER =
'-- name: get_consumer \\:one\nSELECT u.user_id, u.username, u.email, c.fName, c.lName, u.last_login, u.created_at\nFROM consumers c\nINNER JOIN users u ON c.user_id = u.user_id\nWHERE u.user_id=:p1\nLIMIT 1\n'
class
GetConsumerRow(pydantic.main.BaseModel):
38class GetConsumerRow(pydantic.BaseModel): 39 user_id: int 40 username: str 41 email: str 42 fname: str 43 lname: str 44 last_login: datetime.datetime 45 created_at: 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.
GET_CONSUMERS =
'-- name: get_consumers \\:many\nSELECT u.user_id, u.username, u.email, c.fName, c.lName, u.last_login, u.created_at\nFROM consumers c\nINNER JOIN users u ON c.user_id = u.user_id\n'
class
GetConsumersRow(pydantic.main.BaseModel):
55class GetConsumersRow(pydantic.BaseModel): 56 user_id: int 57 username: str 58 email: str 59 fname: str 60 lname: str 61 last_login: datetime.datetime 62 created_at: 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.
UPDATE_CONSUMER =
'-- name: update_consumer \\:one\nUPDATE consumers\nSET fName=:p2, lName=:p3\nWHERE user_id=:p1\nRETURNING user_id, fname, lname\n'
class
UpdateConsumerParams(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.
class
AsyncQuerier:
79class AsyncQuerier: 80 def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): 81 self._conn = conn 82 83 async def create_consumer(self, arg: CreateConsumerParams) -> Optional[models.Consumer]: 84 row = (await self._conn.execute(sqlalchemy.text(CREATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 85 if row is None: 86 return None 87 return models.Consumer( 88 user_id=row[0], 89 fname=row[1], 90 lname=row[2], 91 ) 92 93 async def get_consumer(self, *, user_id: int) -> Optional[GetConsumerRow]: 94 row = (await self._conn.execute(sqlalchemy.text(GET_CONSUMER), {"p1": user_id})).first() 95 if row is None: 96 return None 97 return GetConsumerRow( 98 user_id=row[0], 99 username=row[1], 100 email=row[2], 101 fname=row[3], 102 lname=row[4], 103 last_login=row[5], 104 created_at=row[6], 105 ) 106 107 async def get_consumers(self) -> AsyncIterator[GetConsumersRow]: 108 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS)) 109 async for row in result: 110 yield GetConsumersRow( 111 user_id=row[0], 112 username=row[1], 113 email=row[2], 114 fname=row[3], 115 lname=row[4], 116 last_login=row[5], 117 created_at=row[6], 118 ) 119 120 async def update_consumer(self, arg: UpdateConsumerParams) -> Optional[models.Consumer]: 121 row = (await self._conn.execute(sqlalchemy.text(UPDATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 122 if row is None: 123 return None 124 return models.Consumer( 125 user_id=row[0], 126 fname=row[1], 127 lname=row[2], 128 )
async def
create_consumer( self, arg: CreateConsumerParams) -> internal.queries.models.Consumer | None:
83 async def create_consumer(self, arg: CreateConsumerParams) -> Optional[models.Consumer]: 84 row = (await self._conn.execute(sqlalchemy.text(CREATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 85 if row is None: 86 return None 87 return models.Consumer( 88 user_id=row[0], 89 fname=row[1], 90 lname=row[2], 91 )
93 async def get_consumer(self, *, user_id: int) -> Optional[GetConsumerRow]: 94 row = (await self._conn.execute(sqlalchemy.text(GET_CONSUMER), {"p1": user_id})).first() 95 if row is None: 96 return None 97 return GetConsumerRow( 98 user_id=row[0], 99 username=row[1], 100 email=row[2], 101 fname=row[3], 102 lname=row[4], 103 last_login=row[5], 104 created_at=row[6], 105 )
107 async def get_consumers(self) -> AsyncIterator[GetConsumersRow]: 108 result = await self._conn.stream(sqlalchemy.text(GET_CONSUMERS)) 109 async for row in result: 110 yield GetConsumersRow( 111 user_id=row[0], 112 username=row[1], 113 email=row[2], 114 fname=row[3], 115 lname=row[4], 116 last_login=row[5], 117 created_at=row[6], 118 )
async def
update_consumer( self, arg: UpdateConsumerParams) -> internal.queries.models.Consumer | None:
120 async def update_consumer(self, arg: UpdateConsumerParams) -> Optional[models.Consumer]: 121 row = (await self._conn.execute(sqlalchemy.text(UPDATE_CONSUMER), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first() 122 if row is None: 123 return None 124 return models.Consumer( 125 user_id=row[0], 126 fname=row[1], 127 lname=row[2], 128 )