Skip to content

Commit

Permalink
param type and style normalization across all repos
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Feb 9, 2024
1 parent f2d1972 commit 09c2499
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 34 deletions.
10 changes: 6 additions & 4 deletions app/repositories/achievements.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def create(
FROM achievements
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
rec = await app.state.services.database.fetch_one(query, params)
Expand Down Expand Up @@ -176,8 +176,10 @@ async def update(
SET {",".join(f"{k} = COALESCE(:{k}, {k})" for k in update_fields)}
WHERE id = :id
"""
values = {"id": id} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": id,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down Expand Up @@ -215,7 +217,7 @@ async def delete(
DELETE FROM achievements
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": id,
}
await app.state.services.database.execute(query, params)
Expand Down
10 changes: 6 additions & 4 deletions app/repositories/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def create(
FROM channels
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}

Expand Down Expand Up @@ -185,8 +185,10 @@ async def update(
SET {",".join(f"{k} = COALESCE(:{k}, {k})" for k in update_fields)}
WHERE name = :name
"""
values = {"name": name} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"name": name,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down Expand Up @@ -220,7 +222,7 @@ async def delete(
DELETE FROM channels
WHERE name = :name
"""
params = {
params: dict[str, Any] = {
"name": name,
}
channel = await app.state.services.database.execute(query, params)
Expand Down
17 changes: 12 additions & 5 deletions app/repositories/clans.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def create(
FROM clans
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
clan = await app.state.services.database.fetch_one(query, params)
Expand All @@ -90,7 +90,12 @@ async def fetch_one(
AND tag = COALESCE(:tag, tag)
AND owner = COALESCE(:owner, owner)
"""
params: dict[str, Any] = {"id": id, "name": name, "tag": tag, "owner": owner}
params: dict[str, Any] = {
"id": id,
"name": name,
"tag": tag,
"owner": owner,
}
clan = await app.state.services.database.fetch_one(query, params)

return cast(Clan, dict(clan._mapping)) if clan is not None else None
Expand Down Expand Up @@ -150,8 +155,10 @@ async def update(
SET {",".join(f"{k} = :{k}" for k in update_fields)}
WHERE id = :id
"""
values = {"id": id} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": id,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down Expand Up @@ -183,6 +190,6 @@ async def delete(id: int) -> Clan | None:
DELETE FROM clans
WHERE id = :id
"""
params = {"id": id}
params: dict[str, Any] = {"id": id}
clan = await app.state.services.database.execute(query, params)
return cast(Clan, dict(clan._mapping)) if clan is not None else None
4 changes: 2 additions & 2 deletions app/repositories/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def create(
INSERT INTO comments (target_id, target_type, userid, time, comment, colour)
VALUES (:target_id, :target_type, :userid, :time, :comment, :colour)
"""
params = {
params: dict[str, Any] = {
"target_id": target_id,
"target_type": target_type,
"userid": userid,
Expand All @@ -71,7 +71,7 @@ async def create(
FROM comments c
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
_comment = await app.state.services.database.fetch_one(query, params)
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/ingame_logins.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def create(
FROM ingame_logins
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
ingame_login = await app.state.services.database.fetch_one(query, params)
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def create(
FROM logs
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
rec = await app.state.services.database.fetch_one(query, params)
Expand Down
10 changes: 6 additions & 4 deletions app/repositories/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ async def create(
FROM maps
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
map = await app.state.services.database.fetch_one(query, params)
Expand Down Expand Up @@ -364,8 +364,10 @@ async def update(
SET {",".join(f"{k} = COALESCE(:{k}, {k})" for k in update_fields)}
WHERE id = :id
"""
values = {"id": id} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": id,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down Expand Up @@ -397,7 +399,7 @@ async def delete(id: int) -> Map | None:
DELETE FROM maps
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": id,
}
map = await app.state.services.database.execute(query, params)
Expand Down
8 changes: 5 additions & 3 deletions app/repositories/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def create(
FROM users
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
player = await app.state.services.database.fetch_one(query, params)
Expand Down Expand Up @@ -278,8 +278,10 @@ async def update(
SET {",".join(f"{k} = COALESCE(:{k}, {k})" for k in update_fields)}
WHERE id = :id
"""
values = {"id": id} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": id,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down
18 changes: 13 additions & 5 deletions app/repositories/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ async def create(
FROM scores
WHERE id = :id
"""
params = {"id": rec_id}
params: dict[str, Any] = {
"id": rec_id,
}
rec = await app.state.services.database.fetch_one(query, params)

assert rec is not None
Expand All @@ -170,7 +172,9 @@ async def fetch_one(id: int) -> Score | None:
FROM scores
WHERE id = :id
"""
params: dict[str, Any] = {"id": id}
params: dict[str, Any] = {
"id": id,
}
rec = await app.state.services.database.fetch_one(query, params)

return cast(Score, dict(rec._mapping)) if rec is not None else None
Expand Down Expand Up @@ -258,15 +262,19 @@ async def update(
SET {",".join(f"{k} = COALESCE(:{k}, {k})" for k in update_fields)}
WHERE id = :id
"""
values = {"id": id} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": id,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
FROM scores
WHERE id = :id
"""
params: dict[str, Any] = {"id": id}
params: dict[str, Any] = {
"id": id,
}
rec = await app.state.services.database.fetch_one(query, params)
return cast(Score, dict(rec._mapping)) if rec is not None else None

Expand Down
9 changes: 6 additions & 3 deletions app/repositories/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def create(
FROM stats
WHERE id = :id
"""
params = {
params: dict[str, Any] = {
"id": rec_id,
}
stat = await app.state.services.database.fetch_one(query, params)
Expand Down Expand Up @@ -257,8 +257,11 @@ async def update(
WHERE id = :id
AND mode = :mode
"""
values = {"id": player_id, "mode": mode} | update_fields
await app.state.services.database.execute(query, values)
params: dict[str, Any] = {
"id": player_id,
"mode": mode,
} | update_fields
await app.state.services.database.execute(query, params)

query = f"""\
SELECT {READ_PARAMS}
Expand Down
9 changes: 7 additions & 2 deletions app/repositories/user_achievements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ async def create(user_id: int, achievement_id: int) -> UserAchievement:
INSERT INTO user_achievements (userid, achid)
VALUES (:user_id, :achievement_id)
"""
params: dict[str, Any] = {"user_id": user_id, "achievement_id": achievement_id}
params: dict[str, Any] = {
"user_id": user_id,
"achievement_id": achievement_id,
}
await app.state.services.database.execute(query, params)

query = f"""\
Expand All @@ -60,7 +63,9 @@ async def fetch_many(
FROM user_achievements
WHERE userid = :user_id
"""
params: dict[str, Any] = {"user_id": user_id}
params: dict[str, Any] = {
"user_id": user_id,
}

if not isinstance(page, _UnsetSentinel) and not isinstance(
page_size,
Expand Down

0 comments on commit 09c2499

Please sign in to comment.