From 72cc983848404f5b9d57a59257cd4d8902e031ed Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Sat, 3 Feb 2024 13:34:55 +0100 Subject: [PATCH] add name to get highscore --- notes.md | 27 +++++++++++++-------------- src/app/repositories/highscore.py | 9 ++++++--- src/app/repositories/player.py | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/notes.md b/notes.md index 599cade..371cfee 100644 --- a/notes.md +++ b/notes.md @@ -1,22 +1,26 @@ -# kubectl -```sh -kubectl port-forward -n kafka svc/bd-prd-kafka-service 9094:9094 -kubectl port-forward -n database svc/mysql 3306:3306 -``` +# setup +## windows ```sh python -m venv .venv .venv\Scripts\activate python -m pip install --upgrade pip pip install -r requirements.txt ``` +## linux +```sh +python3 -m venv .venv +source .venv/bin/activate +python -m pip install --upgrade pip +pip install -r requirements.txt +``` ```sh .venv\Scripts\activate pip freeze > requirements.txt ``` -# linux / wsl +### tips linux / wsl to open vscode in wsl just open vs code, type `wsl` in the terminal than type `code .` tip: you can trim your command line path with @@ -27,14 +31,9 @@ add at the botom, exit nano with ctrl + x then press y to save ```sh PROMPT_DIRTRIM=3 ``` -restart your shell +# kubectl ```sh -sudo apt update -y && sudo apt upgrade -y -sudo apt install python3.10-venv -y -``` -```sh -python3 -m venv .venv -touch .venv\bin\activate +kubectl port-forward -n kafka svc/bd-prd-kafka-service 9094:9094 +kubectl port-forward -n database svc/mysql 3306:3306 ``` -```sh diff --git a/src/app/repositories/highscore.py b/src/app/repositories/highscore.py index 00f661f..01a24e1 100644 --- a/src/app/repositories/highscore.py +++ b/src/app/repositories/highscore.py @@ -3,10 +3,11 @@ PlayerHiscoreDataLatest, # PlayerHiscoreDataXPChange, ) +from src.core.database.models.player import Player from src.core.database.database import SessionFactory from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy import select -from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession +from sqlalchemy.ext.asyncio import AsyncResult from sqlalchemy.sql.expression import Select from fastapi.encoders import jsonable_encoder from src.app.repositories.abstract_repo import AbstractAPI @@ -26,12 +27,14 @@ async def _simple_execute(self, sql) -> dict: return jsonable_encoder(result) async def get(self, id: int): - sql: Select = select(self.table) + sql: Select = select(self.table, Player.name) + sql = sql.join(target=Player, onclause=self.table.Player_id == Player.id) sql = sql.where(self.table.Player_id == id) return await self._simple_execute(sql) async def get_many(self, start: int, limit: int = 5000): - sql: Select = select(self.table) + sql: Select = select(self.table, Player.name) + sql = sql.join(target=Player, onclause=self.table.Player_id == Player.id) sql = sql.where(self.table.Player_id > start) sql = sql.limit(limit) return await self._simple_execute(sql) diff --git a/src/app/repositories/player.py b/src/app/repositories/player.py index ab17090..60b244d 100644 --- a/src/app/repositories/player.py +++ b/src/app/repositories/player.py @@ -2,7 +2,7 @@ from src.core.database.database import SessionFactory from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy import select -from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession +from sqlalchemy.ext.asyncio import AsyncResult from sqlalchemy.sql.expression import Select from fastapi.encoders import jsonable_encoder