feat(api): insert members into database + testing

This commit is contained in:
2024-03-02 15:52:41 -05:00
parent 6bd9657737
commit 0b6c1df6ff
2 changed files with 46 additions and 1 deletions

View File

@@ -55,3 +55,34 @@ async def select_member_by_id(db: AsyncConnectionPool, id: int) -> Member | None
member = await curr.fetchone()
return None if member is None else member
async def insert_member(
db: AsyncConnectionPool, email: str, password_hash: str
) -> Member | None:
"""
Insert a member into the database
Return the inserted member object
"""
async with db.connection() as conn:
async with conn.cursor(row_factory=class_row(Member)) as curr:
query = sql.SQL(
"""
INSERT INTO members (email, password_hash)
VALUES (%s, %s)
RETURNING id, email, password_hash, created, email_verified
"""
)
await curr.execute(
query,
(
email,
password_hash,
),
)
member = await curr.fetchone()
return None if member is None else member