Skip to content

Commit

Permalink
Add asyncpg logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kaziamov committed Jan 8, 2025
1 parent 75abae3 commit 989e81d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
10 changes: 10 additions & 0 deletions simplecrud/asyncpg_commands/cruds.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 989e81d

Please sign in to comment.