89 lines
1.8 KiB
Python
89 lines
1.8 KiB
Python
from asyncpg import Connection
|
|
|
|
# swipe create and delete
|
|
|
|
async def create_swipe(
|
|
conn: Connection,
|
|
username: str,
|
|
feed_id: int,
|
|
picture_id: int,
|
|
value: int
|
|
):
|
|
result = await conn.fetchrow(
|
|
"""
|
|
insert into picrinth.swipes
|
|
(username, feed_id, picture_id, value, created_at)
|
|
values ($1, $2, $3, $4, now())
|
|
returning id
|
|
""",
|
|
username, feed_id, picture_id, value,
|
|
)
|
|
if result is None:
|
|
return None
|
|
return result["id"]
|
|
|
|
|
|
async def delete_swipe(
|
|
conn: Connection,
|
|
username: str,
|
|
feed_id: int,
|
|
picture_id: int
|
|
):
|
|
result = await conn.execute(
|
|
"""
|
|
delete from picrinth.swipes
|
|
where username = $1 and picture_id = $2 and feed_id = $3
|
|
""",
|
|
username, picture_id, feed_id,
|
|
)
|
|
return result != "DELETE 0"
|
|
|
|
|
|
# swipe receiving
|
|
|
|
async def get_swipe(
|
|
conn: Connection,
|
|
username: str,
|
|
feed_id: int,
|
|
picture_id: int
|
|
):
|
|
return await conn.fetchrow(
|
|
"""
|
|
select username,
|
|
feed_id, picture_id,
|
|
value, created_at
|
|
from picrinth.swipes
|
|
where username = $1 and feed_id = $2 and picture_id = $3
|
|
""",
|
|
username, feed_id, picture_id,
|
|
)
|
|
|
|
|
|
async def get_swipes_by_picture_id(
|
|
conn: Connection,
|
|
feed_id: int,
|
|
picture_id: int
|
|
):
|
|
return await conn.fetchrow(
|
|
"""
|
|
select *
|
|
from picrinth.swipes
|
|
where feed_id = $1 and picture_id = $2
|
|
""",
|
|
feed_id, picture_id,
|
|
)
|
|
|
|
async def get_swipes_by_user(
|
|
conn: Connection,
|
|
username: str,
|
|
feed_id: int
|
|
):
|
|
return await conn.fetchrow(
|
|
"""
|
|
select *
|
|
from picrinth.swipes
|
|
where username = $1 and feed_id = $2
|
|
""",
|
|
username, feed_id,
|
|
)
|