mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 23:55:46 +02:00
Check for free games
This commit is contained in:
parent
41b5efd12d
commit
deefeb1106
11 changed files with 297 additions and 75 deletions
20
database/crud/free_games.py
Normal file
20
database/crud/free_games.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.schemas import FreeGame
|
||||
|
||||
__all__ = ["add_free_games", "filter_present_games"]
|
||||
|
||||
|
||||
async def add_free_games(session: AsyncSession, game_ids: list[int]):
|
||||
"""Bulk-add a list of IDs into the database"""
|
||||
games = [FreeGame(free_game_id=game_id) for game_id in game_ids]
|
||||
session.add_all(games)
|
||||
await session.commit()
|
||||
|
||||
|
||||
async def filter_present_games(session: AsyncSession, game_ids: list[int]) -> list[int]:
|
||||
"""Filter a list of game IDs down to the ones that aren't in the database yet"""
|
||||
query = select(FreeGame.free_game_id).where(FreeGame.free_game_id.in_(game_ids))
|
||||
matches: list[int] = (await session.execute(query)).scalars().all()
|
||||
return list(set(game_ids).difference(matches))
|
||||
Loading…
Add table
Add a link
Reference in a new issue