Skip to content

Commit

Permalink
fix: Add metadata reflection fix to sqlite as well
Browse files Browse the repository at this point in the history
Added fix when reflecting metadata to sqlite as well

Fix
  • Loading branch information
dexters1 committed Dec 16, 2024
1 parent d9e558e commit 394a0b2
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ async def get_table(self, table_name: str, schema_name: Optional[str] = "public"
"""
async with self.engine.begin() as connection:
if self.engine.dialect.name == "sqlite":
# Load the schema information into the MetaData object
await connection.run_sync(Base.metadata.reflect)
if table_name in Base.metadata.tables:
return Base.metadata.tables[table_name]
# Create a MetaData instance to load table information
metadata = MetaData()
# Load table information from schema into MetaData
await connection.run_sync(metadata.reflect)
if table_name in metadata.tables:
return metadata.tables[table_name]
else:
raise EntityNotFoundError(message=f"Table '{table_name}' not found.")
else:
Expand All @@ -138,8 +140,11 @@ async def get_table_names(self) -> List[str]:
table_names = []
async with self.engine.begin() as connection:
if self.engine.dialect.name == "sqlite":
await connection.run_sync(Base.metadata.reflect)
for table in Base.metadata.tables:
# Create a MetaData instance to load table information
metadata = MetaData()
# Load table information from schema into MetaData
await connection.run_sync(metadata.reflect)
for table in metadata.tables:
table_names.append(str(table))
else:
schema_list = await self.get_schema_list()
Expand Down

0 comments on commit 394a0b2

Please sign in to comment.