New files
storeapi/security.py
import logging
from storeapi.database import database, user_table
logger = logging.getLogger(__name__)
async def get_user(email: str):
logger.debug("Fetching user from the database", extra={"email": email})
query = user_table.select().where(user_table.c.email == email)
result = await database.fetch_one(query)
if result:
return result
Modified files
storeapi/database.py
---
+++
@@ -10,6 +10,14 @@
metadata,
sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column("body", sqlalchemy.String)
+)
+
+user_table = sqlalchemy.Table(
+ "users",
+ metadata,
+ sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
+ sqlalchemy.Column("email", sqlalchemy.String, unique=True),
+ sqlalchemy.Column("password", sqlalchemy.String),
)
comment_table = sqlalchemy.Table(