def get(self, auction_id: AuctionId) -> Auction: row = self._conn.execute( auctions.select().where(auctions.c.id == auction_id)).first() if not row: raise Exception("Not found") bid_rows = self._conn.execute( bids.select().where(bids.c.auction_id == auction_id)).fetchall() return self._row_to_entity(row, bid_rows)
def expired_auction(connection: Connection, past_date: datetime) -> RowProxy: connection.execute(auctions.insert().values({ "id": 0, "title": "Nothing interesting", "starting_price": Decimal("1.99"), "current_price": Decimal("1.99"), "ends_at": past_date, "ended": False, })) return connection.execute( auctions.select(whereclause=auctions.c.id == 0)).first()
def auction_model_with_a_bid(connection: Connection, winning_bid_amount: Decimal, bidder_id: int, ends_at: datetime) -> RowProxy: connection.execute(auctions.insert().values({ "id": 1, "title": "Cool socks", "starting_price": winning_bid_amount / 2, "current_price": winning_bid_amount, "ends_at": ends_at, "ended": False, })) connection.execute(bids.insert().values({ "amount": winning_bid_amount, "auction_id": 1, "bidder_id": bidder_id })) return connection.execute( auctions.select(whereclause=auctions.c.id == 1)).first()
def query(self, auction_id: int) -> AuctionDto: row = self._conn.execute( auctions.select().where(auctions.c.id == auction_id)).first() return _row_to_dto(row)
def query(self) -> List[AuctionDto]: return [ _row_to_dto(row) for row in self._conn.execute(auctions.select().where( auctions.c.ends_at > func.now())) ]