From 085ca5ece895eb8c7680a14df4f46de88021d4f8 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Mon, 5 Aug 2024 10:05:00 +0200 Subject: [PATCH] Fixes to the users --- .../relational/sqlalchemy/SqlAlchemyAdapter.py | 8 ++++---- cognee/modules/users/methods/get_default_user.py | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py b/cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py index ae79805cf..7de1ca785 100644 --- a/cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +++ b/cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py @@ -57,11 +57,11 @@ class SQLAlchemyAdapter(): result = connection.execute(text(f"SELECT id, name, file_path, extension, mime_type FROM {dataset_name}.file_metadata;")) return [dict(row) for row in result] - def create_table(self, schema_name: str, table_name: str, table_config: list[dict]): + async def create_table(self, schema_name: str, table_name: str, table_config: list[dict]): fields_query_parts = [f"{item['name']} {item['type']}" for item in table_config] - with self.engine.connect() as connection: - connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {schema_name};")) - connection.execute(text(f"CREATE TABLE IF NOT EXISTS {schema_name}.{table_name} ({', '.join(fields_query_parts)});")) + async with self.engine.connect() as connection: + await connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {schema_name};")) + await connection.execute(text(f"CREATE TABLE IF NOT EXISTS {schema_name}.{table_name} ({', '.join(fields_query_parts)});")) def delete_table(self, table_name: str): with self.engine.connect() as connection: diff --git a/cognee/modules/users/methods/get_default_user.py b/cognee/modules/users/methods/get_default_user.py index 011c06ec4..5e0d3bcfe 100644 --- a/cognee/modules/users/methods/get_default_user.py +++ b/cognee/modules/users/methods/get_default_user.py @@ -1,8 +1,12 @@ from cognee.modules.users.models import User from cognee.infrastructure.databases.relational import get_relational_engine -async def get_default_user() -> User: - db_engine = get_relational_engine() +from sqlalchemy.future import select +async def get_default_user(): + db_engine = get_relational_engine() async with db_engine.get_async_session() as session: - return session.query(User).filter(User.email == "default_user@example.com").first() + stmt = select(User).where(User.email == "default_user@example.com") + result = await session.execute(stmt) + user = result.scalars().first() + return user \ No newline at end of file