internal.queries.admin

  1# Code generated by sqlc. DO NOT EDIT.
  2# versions:
  3#   sqlc v1.30.0
  4# source: admin.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_ADMIN = """-- name: create_admin \\:one
 16INSERT INTO admins (user_id, fName, lName)
 17VALUES (:p1,:p2,:p3)
 18RETURNING user_id, fname, lname, active
 19"""
 20
 21
 22class CreateAdminParams(pydantic.BaseModel):
 23    user_id: int
 24    fname: str
 25    lname: str
 26
 27
 28GET_ADMIN = """-- name: get_admin \\:one
 29SELECT u.user_id, u.username, u.email, a.fName, a.lName, a.active, u.last_login, u.created_at
 30FROM admins a
 31INNER JOIN users u ON a.user_id = u.user_id
 32WHERE u.user_id = :p1
 33LIMIT 1
 34"""
 35
 36
 37class GetAdminRow(pydantic.BaseModel):
 38    user_id: int
 39    username: str
 40    email: str
 41    fname: str
 42    lname: str
 43    active: Optional[bool]
 44    last_login: datetime.datetime
 45    created_at: datetime.datetime
 46
 47
 48GET_ADMINS = """-- name: get_admins \\:many
 49SELECT u.user_id, u.username, u.email, a.fName, a.lName, a.active, u.last_login, u.created_at
 50FROM admins a
 51INNER JOIN users u ON a.user_id = u.user_id
 52"""
 53
 54
 55class GetAdminsRow(pydantic.BaseModel):
 56    user_id: int
 57    username: str
 58    email: str
 59    fname: str
 60    lname: str
 61    active: Optional[bool]
 62    last_login: datetime.datetime
 63    created_at: datetime.datetime
 64
 65
 66SET_IS_ADMIN_ACTIVE = """-- name: set_is_admin_active \\:one
 67UPDATE admins
 68SET active=:p2
 69WHERE user_id=:p1
 70RETURNING user_id, fname, lname, active
 71"""
 72
 73
 74class SetIsAdminActiveParams(pydantic.BaseModel):
 75    user_id: int
 76    active: Optional[bool]
 77
 78
 79UPDATE_ADMIN = """-- name: update_admin \\:one
 80UPDATE admins
 81SET fName = :p2, lName = :p3
 82WHERE user_id = :p1
 83RETURNING user_id, fname, lname, active
 84"""
 85
 86
 87class UpdateAdminParams(pydantic.BaseModel):
 88    user_id: int
 89    fname: str
 90    lname: str
 91
 92
 93class AsyncQuerier:
 94    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 95        self._conn = conn
 96
 97    async def create_admin(self, arg: CreateAdminParams) -> Optional[models.Admin]:
 98        row = (await self._conn.execute(sqlalchemy.text(CREATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
 99        if row is None:
100            return None
101        return models.Admin(
102            user_id=row[0],
103            fname=row[1],
104            lname=row[2],
105            active=row[3],
106        )
107
108    async def get_admin(self, *, user_id: int) -> Optional[GetAdminRow]:
109        row = (await self._conn.execute(sqlalchemy.text(GET_ADMIN), {"p1": user_id})).first()
110        if row is None:
111            return None
112        return GetAdminRow(
113            user_id=row[0],
114            username=row[1],
115            email=row[2],
116            fname=row[3],
117            lname=row[4],
118            active=row[5],
119            last_login=row[6],
120            created_at=row[7],
121        )
122
123    async def get_admins(self) -> AsyncIterator[GetAdminsRow]:
124        result = await self._conn.stream(sqlalchemy.text(GET_ADMINS))
125        async for row in result:
126            yield GetAdminsRow(
127                user_id=row[0],
128                username=row[1],
129                email=row[2],
130                fname=row[3],
131                lname=row[4],
132                active=row[5],
133                last_login=row[6],
134                created_at=row[7],
135            )
136
137    async def set_is_admin_active(self, arg: SetIsAdminActiveParams) -> Optional[models.Admin]:
138        row = (await self._conn.execute(sqlalchemy.text(SET_IS_ADMIN_ACTIVE), {"p1": arg.user_id, "p2": arg.active})).first()
139        if row is None:
140            return None
141        return models.Admin(
142            user_id=row[0],
143            fname=row[1],
144            lname=row[2],
145            active=row[3],
146        )
147
148    async def update_admin(self, arg: UpdateAdminParams) -> Optional[models.Admin]:
149        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
150        if row is None:
151            return None
152        return models.Admin(
153            user_id=row[0],
154            fname=row[1],
155            lname=row[2],
156            active=row[3],
157        )
CREATE_ADMIN = '-- name: create_admin \\:one\nINSERT INTO admins (user_id, fName, lName)\nVALUES (:p1,:p2,:p3)\nRETURNING user_id, fname, lname, active\n'
class CreateAdminParams(pydantic.main.BaseModel):
23class CreateAdminParams(pydantic.BaseModel):
24    user_id: int
25    fname: str
26    lname: 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.
user_id: int = PydanticUndefined
fname: str = PydanticUndefined
lname: str = PydanticUndefined
GET_ADMIN = '-- name: get_admin \\:one\nSELECT u.user_id, u.username, u.email, a.fName, a.lName, a.active, u.last_login, u.created_at\nFROM admins a\nINNER JOIN users u ON a.user_id = u.user_id\nWHERE u.user_id = :p1\nLIMIT 1\n'
class GetAdminRow(pydantic.main.BaseModel):
38class GetAdminRow(pydantic.BaseModel):
39    user_id: int
40    username: str
41    email: str
42    fname: str
43    lname: str
44    active: Optional[bool]
45    last_login: datetime.datetime
46    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__ 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.
user_id: int = PydanticUndefined
username: str = PydanticUndefined
email: str = PydanticUndefined
fname: str = PydanticUndefined
lname: str = PydanticUndefined
active: bool | None = PydanticUndefined
last_login: datetime.datetime = PydanticUndefined
created_at: datetime.datetime = PydanticUndefined
GET_ADMINS = '-- name: get_admins \\:many\nSELECT u.user_id, u.username, u.email, a.fName, a.lName, a.active, u.last_login, u.created_at\nFROM admins a\nINNER JOIN users u ON a.user_id = u.user_id\n'
class GetAdminsRow(pydantic.main.BaseModel):
56class GetAdminsRow(pydantic.BaseModel):
57    user_id: int
58    username: str
59    email: str
60    fname: str
61    lname: str
62    active: Optional[bool]
63    last_login: datetime.datetime
64    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__ 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.
user_id: int = PydanticUndefined
username: str = PydanticUndefined
email: str = PydanticUndefined
fname: str = PydanticUndefined
lname: str = PydanticUndefined
active: bool | None = PydanticUndefined
last_login: datetime.datetime = PydanticUndefined
created_at: datetime.datetime = PydanticUndefined
SET_IS_ADMIN_ACTIVE = '-- name: set_is_admin_active \\:one\nUPDATE admins\nSET active=:p2\nWHERE user_id=:p1\nRETURNING user_id, fname, lname, active\n'
class SetIsAdminActiveParams(pydantic.main.BaseModel):
75class SetIsAdminActiveParams(pydantic.BaseModel):
76    user_id: int
77    active: Optional[bool]

!!! 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.
user_id: int = PydanticUndefined
active: bool | None = PydanticUndefined
UPDATE_ADMIN = '-- name: update_admin \\:one\nUPDATE admins\nSET fName = :p2, lName = :p3\nWHERE user_id = :p1\nRETURNING user_id, fname, lname, active\n'
class UpdateAdminParams(pydantic.main.BaseModel):
88class UpdateAdminParams(pydantic.BaseModel):
89    user_id: int
90    fname: str
91    lname: 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.
user_id: int = PydanticUndefined
fname: str = PydanticUndefined
lname: str = PydanticUndefined
class AsyncQuerier:
 94class AsyncQuerier:
 95    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
 96        self._conn = conn
 97
 98    async def create_admin(self, arg: CreateAdminParams) -> Optional[models.Admin]:
 99        row = (await self._conn.execute(sqlalchemy.text(CREATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
100        if row is None:
101            return None
102        return models.Admin(
103            user_id=row[0],
104            fname=row[1],
105            lname=row[2],
106            active=row[3],
107        )
108
109    async def get_admin(self, *, user_id: int) -> Optional[GetAdminRow]:
110        row = (await self._conn.execute(sqlalchemy.text(GET_ADMIN), {"p1": user_id})).first()
111        if row is None:
112            return None
113        return GetAdminRow(
114            user_id=row[0],
115            username=row[1],
116            email=row[2],
117            fname=row[3],
118            lname=row[4],
119            active=row[5],
120            last_login=row[6],
121            created_at=row[7],
122        )
123
124    async def get_admins(self) -> AsyncIterator[GetAdminsRow]:
125        result = await self._conn.stream(sqlalchemy.text(GET_ADMINS))
126        async for row in result:
127            yield GetAdminsRow(
128                user_id=row[0],
129                username=row[1],
130                email=row[2],
131                fname=row[3],
132                lname=row[4],
133                active=row[5],
134                last_login=row[6],
135                created_at=row[7],
136            )
137
138    async def set_is_admin_active(self, arg: SetIsAdminActiveParams) -> Optional[models.Admin]:
139        row = (await self._conn.execute(sqlalchemy.text(SET_IS_ADMIN_ACTIVE), {"p1": arg.user_id, "p2": arg.active})).first()
140        if row is None:
141            return None
142        return models.Admin(
143            user_id=row[0],
144            fname=row[1],
145            lname=row[2],
146            active=row[3],
147        )
148
149    async def update_admin(self, arg: UpdateAdminParams) -> Optional[models.Admin]:
150        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
151        if row is None:
152            return None
153        return models.Admin(
154            user_id=row[0],
155            fname=row[1],
156            lname=row[2],
157            active=row[3],
158        )
AsyncQuerier(conn: sqlalchemy.ext.asyncio.engine.AsyncConnection)
95    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
96        self._conn = conn
async def create_admin( self, arg: CreateAdminParams) -> internal.queries.models.Admin | None:
 98    async def create_admin(self, arg: CreateAdminParams) -> Optional[models.Admin]:
 99        row = (await self._conn.execute(sqlalchemy.text(CREATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
100        if row is None:
101            return None
102        return models.Admin(
103            user_id=row[0],
104            fname=row[1],
105            lname=row[2],
106            active=row[3],
107        )
async def get_admin(self, *, user_id: int) -> GetAdminRow | None:
109    async def get_admin(self, *, user_id: int) -> Optional[GetAdminRow]:
110        row = (await self._conn.execute(sqlalchemy.text(GET_ADMIN), {"p1": user_id})).first()
111        if row is None:
112            return None
113        return GetAdminRow(
114            user_id=row[0],
115            username=row[1],
116            email=row[2],
117            fname=row[3],
118            lname=row[4],
119            active=row[5],
120            last_login=row[6],
121            created_at=row[7],
122        )
async def get_admins(self) -> AsyncIterator[GetAdminsRow]:
124    async def get_admins(self) -> AsyncIterator[GetAdminsRow]:
125        result = await self._conn.stream(sqlalchemy.text(GET_ADMINS))
126        async for row in result:
127            yield GetAdminsRow(
128                user_id=row[0],
129                username=row[1],
130                email=row[2],
131                fname=row[3],
132                lname=row[4],
133                active=row[5],
134                last_login=row[6],
135                created_at=row[7],
136            )
async def set_is_admin_active( self, arg: SetIsAdminActiveParams) -> internal.queries.models.Admin | None:
138    async def set_is_admin_active(self, arg: SetIsAdminActiveParams) -> Optional[models.Admin]:
139        row = (await self._conn.execute(sqlalchemy.text(SET_IS_ADMIN_ACTIVE), {"p1": arg.user_id, "p2": arg.active})).first()
140        if row is None:
141            return None
142        return models.Admin(
143            user_id=row[0],
144            fname=row[1],
145            lname=row[2],
146            active=row[3],
147        )
async def update_admin( self, arg: UpdateAdminParams) -> internal.queries.models.Admin | None:
149    async def update_admin(self, arg: UpdateAdminParams) -> Optional[models.Admin]:
150        row = (await self._conn.execute(sqlalchemy.text(UPDATE_ADMIN), {"p1": arg.user_id, "p2": arg.fname, "p3": arg.lname})).first()
151        if row is None:
152            return None
153        return models.Admin(
154            user_id=row[0],
155            fname=row[1],
156            lname=row[2],
157            active=row[3],
158        )