Single part at the root, COMPOSE_FILE in .env

This commit is contained in:
hh committed 2026-09-08 20:38:54 +02:00
1 parent 321e4b6b35
commit aac037676c
86 files changed
+68 -27

No files matched your search

@@ -0,0 +1,54 @@
{% if database == 'postgres' -%}
from datetime import datetime
from sqlalchemy import BigInteger, Column
from sqlmodel import Field as SQLField
from sqlmodel import SQLModel
from .base import created_at_col
class User(SQLModel, table=True):
__tablename__ = "user_account"
id: int | None = SQLField(default=None, primary_key=True)
tg_id: int = SQLField(sa_column=Column(BigInteger, unique=True, index=True))
username: str | None = None
first_name: str | None = None
last_name: str | None = None
created_at: datetime | None = created_at_col()
{%- else -%}
from beanie import Document
class User(Document):
id: int
balance: float = 0
class Settings:
name = "users"
@classmethod
async def get_by_id(cls, id_: int) -> "User | None":
return await cls.find_one(cls.id == id_)
@classmethod
async def get_or_create(cls, id_: int) -> "User":
user = await cls.get_by_id(id_)
if user is None:
user = cls(id=id_)
await user.insert()
return user
async def add_balance(self, amount: float) -> None:
self.balance += amount
await self.save()
async def subtract_balance(self, amount: float) -> bool:
if self.balance >= amount:
self.balance -= amount
await self.save()
return True
return False
{%- endif %}