From e27b57050a3eaa04f638866842dcee02d84235e4 Mon Sep 17 00:00:00 2001 From: ducklet Date: Tue, 28 Mar 2023 22:04:14 +0200 Subject: [PATCH] remove unused functions --- unwind/db.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/unwind/db.py b/unwind/db.py index a610b78..6c21a9d 100644 --- a/unwind/db.py +++ b/unwind/db.py @@ -1,7 +1,6 @@ import asyncio import contextlib import logging -import re import threading from pathlib import Path from typing import Any, Iterable, Literal, Type, TypeVar @@ -16,7 +15,6 @@ from .models import ( Rating, User, asplain, - fields, fromplain, movies, optional_fields, @@ -414,7 +412,7 @@ async def add_or_update_rating(rating: Rating) -> bool: return False -def sql_escape(s: str, char="#"): +def sql_escape(s: str, char: str = "#") -> str: return s.replace(char, 2 * char).replace("%", f"{char}%").replace("_", f"{char}_") @@ -533,10 +531,6 @@ async def ratings_for_movie_ids( return tuple(dict(r._mapping) for r in rows) -def sql_fields(tp: Type): - return (f"{tp._table}.{f.name}" for f in fields(tp)) - - async def ratings_for_movies( movie_ids: Iterable[ULID], user_ids: Iterable[ULID] = [] ) -> Iterable[Rating]: @@ -626,24 +620,3 @@ async def find_movies( aggreg[rating.movie_id][1].append(rating) return aggreg.values() - - -def bindparams(query: str, values: dict): - """Bind values to a query. - - This is similar to what SQLAlchemy and Databases do, but it allows to - easily use the same placeholder in multiple places. - """ - pump_vals = {} - pump_keys = {} - - def pump(match): - key = match[1] - val = values[key] - pump_keys[key] = 1 + pump_keys.setdefault(key, 0) - pump_key = f"{key}_{pump_keys[key]}" - pump_vals[pump_key] = val - return f":{pump_key}" - - pump_query = re.sub(r":(\w+)\b", pump, query) - return sa.text(pump_query).bindparams(**pump_vals)