From 989e81d1d8c66e036efd46cbb9ab39562030e864 Mon Sep 17 00:00:00 2001 From: Ilia Kaziamov Date: Thu, 9 Jan 2025 00:21:48 +0400 Subject: [PATCH] Add asyncpg logic --- Makefile | 2 +- .../{sync_crud.py => asyncpg_commands/__init__.py} | 0 simplecrud/asyncpg_commands/cruds.py | 10 ++++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename simplecrud/{sync_crud.py => asyncpg_commands/__init__.py} (100%) create mode 100644 simplecrud/asyncpg_commands/cruds.py diff --git a/Makefile b/Makefile index 95a3533..c30f6c6 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,4 @@ package-install: lint: poetry run flake8 simplecrud coverage: - poetry run coverage run --source=simplecrud -m pytest + poetry run pytest --cov=simplecrud --cov-report=xml diff --git a/simplecrud/sync_crud.py b/simplecrud/asyncpg_commands/__init__.py similarity index 100% rename from simplecrud/sync_crud.py rename to simplecrud/asyncpg_commands/__init__.py diff --git a/simplecrud/asyncpg_commands/cruds.py b/simplecrud/asyncpg_commands/cruds.py new file mode 100644 index 0000000..20aea64 --- /dev/null +++ b/simplecrud/asyncpg_commands/cruds.py @@ -0,0 +1,10 @@ +from asyncpg import connect + + +async def insert_to_table(conn: connect, table: str, data: dict): + keys = ", ".join(data.keys()) + nums = ", ".join([f"${num}" for num in range(1, len(data.items()) + 1)]) + values = list(data.values()) + query = f"INSERT INTO {table} ({keys}) VALUES ({nums}) ON CONFLICT DO NOTHING;" + await conn.execute(query, *values) +