43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.bot import Bot
|
|
from app.schemas.bot import BotCreate, BotUpdate
|
|
|
|
|
|
class CRUDBot(CRUDBase[Bot, BotCreate, BotUpdate]):
|
|
def get_active(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Bot]:
|
|
return (
|
|
db.query(Bot)
|
|
.filter(Bot.is_active)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_by_name(
|
|
self, db: Session, *, name: str
|
|
) -> Optional[Bot]:
|
|
return db.query(Bot).filter(Bot.name == name).first()
|
|
|
|
def get_all(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Bot]:
|
|
return db.query(Bot).offset(skip).limit(limit).all()
|
|
|
|
|
|
bot = CRUDBot(Bot)
|
|
|
|
|
|
# Aliases for convenience
|
|
get_bot = bot.get
|
|
create_bot = bot.create
|
|
update_bot = bot.update
|
|
delete_bot = bot.remove
|
|
get_active_bots = bot.get_active
|
|
get_bot_by_name = bot.get_by_name
|
|
get_all_bots = bot.get_all |