Fixes to the users
This commit is contained in:
parent
07e2bc1b39
commit
085ca5ece8
2 changed files with 11 additions and 7 deletions
|
|
@ -57,11 +57,11 @@ class SQLAlchemyAdapter():
|
||||||
result = connection.execute(text(f"SELECT id, name, file_path, extension, mime_type FROM {dataset_name}.file_metadata;"))
|
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]
|
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]
|
fields_query_parts = [f"{item['name']} {item['type']}" for item in table_config]
|
||||||
with self.engine.connect() as connection:
|
async with self.engine.connect() as connection:
|
||||||
connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {schema_name};"))
|
await 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)});"))
|
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):
|
def delete_table(self, table_name: str):
|
||||||
with self.engine.connect() as connection:
|
with self.engine.connect() as connection:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
from cognee.modules.users.models import User
|
from cognee.modules.users.models import User
|
||||||
from cognee.infrastructure.databases.relational import get_relational_engine
|
from cognee.infrastructure.databases.relational import get_relational_engine
|
||||||
|
|
||||||
async def get_default_user() -> User:
|
from sqlalchemy.future import select
|
||||||
db_engine = get_relational_engine()
|
|
||||||
|
|
||||||
|
async def get_default_user():
|
||||||
|
db_engine = get_relational_engine()
|
||||||
async with db_engine.get_async_session() as session:
|
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
|
||||||
Loading…
Add table
Reference in a new issue