Skip to content

Commit ed4e617

Browse files
committed
Update docs and postgresql connection
1 parent 500c130 commit ed4e617

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

text_2_sql/__init__.py

Whitespace-only changes.

text_2_sql/data_dictionary/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ If there is no pre-built script for your database engine, take one of the above
224224

225225
## Running
226226

227-
1. Create your `.env` file based on the provided sample `.env.example`. Place this file in the same place as the `.env.example`.
227+
**Execute all these commands in the `text_2_sql` directory.**
228+
1. Create your `.env` file based on the provided sample `text_2_sql/.env.example`. Place this file in the same place in `text_2_sql/.env`.
228229
2. Package and install the `text_2_sql_core` library. See [build](https://docs.astral.sh/uv/concepts/projects/build/) if you want to build as a wheel and install on an agent. Or you can run from within a `uv` environment and skip packaging.
229230
- Install the optional dependencies if you need a database connector other than TSQL. `uv sync --extra <DATABASE ENGINE>`
230231
3. Run `data_dictionary <DATABASE ENGINE>`

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/postgresql_sql.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def __init__(self):
1616

1717
self.database_engine = DatabaseEngine.POSTGRESQL
1818

19+
@property
20+
def engine_specific_rules(self) -> str:
21+
"""Get the engine specific rules."""
22+
return ""
23+
1924
@property
2025
def engine_specific_fields(self) -> list[str]:
2126
"""Get the engine specific fields."""
@@ -64,7 +69,7 @@ async def query_execution(
6469
connection_string = os.environ["Text2Sql__DatabaseConnectionString"]
6570

6671
# Establish an asynchronous connection to the PostgreSQL database
67-
async with psycopg.AsyncConnection.connect(connection_string) as conn:
72+
async with await psycopg.AsyncConnection.connect(connection_string) as conn:
6873
# Create an asynchronous cursor
6974
async with conn.cursor() as cursor:
7075
await cursor.execute(sql_query)

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import typer
77
from rich import print as rich_print
8+
from tenacity import RetryError
89

910
logging.basicConfig(level=logging.INFO)
1011

@@ -112,8 +113,18 @@ def create(
112113

113114
try:
114115
asyncio.run(data_dictionary_creator.create_data_dictionary())
116+
except RetryError as e:
117+
# Fetch the actual exception
118+
e = e.last_attempt.exception()
119+
logging.error(e)
120+
rich_print("Text2SQL Data Dictionary Creator Failed ❌")
121+
122+
rich_print(f"Error Messages: {e}")
123+
124+
raise typer.Exit(code=1)
115125
except Exception as e:
116126
logging.error(e)
127+
117128
rich_print("Text2SQL Data Dictionary Creator Failed ❌")
118129

119130
rich_print(f"Error Messages: {e}")

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/data_dictionary_creator.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ForeignKeyRelationship(BaseModel):
2121
column: str = Field(..., alias="Column")
2222
foreign_column: str = Field(..., alias="ForeignColumn")
2323

24-
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
24+
model_config = ConfigDict(populate_by_name=True)
2525

2626

2727
class EntityRelationship(BaseModel):
@@ -39,7 +39,7 @@ class EntityRelationship(BaseModel):
3939
foreign_database: Optional[str] = Field(default=None, alias="ForeignDatabase")
4040
foreign_catalog: Optional[str] = Field(default=None, alias="ForeignCatalog")
4141

42-
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
42+
model_config = ConfigDict(populate_by_name=True)
4343

4444
def pivot(self):
4545
"""A method to pivot the entity relationship."""
@@ -128,12 +128,10 @@ class ColumnItem(BaseModel):
128128
name: str = Field(..., alias="Name")
129129
data_type: str = Field(..., alias="DataType")
130130
definition: Optional[str] = Field(..., alias="Definition")
131-
distinct_values: Optional[list[any]] = Field(
132-
None, alias="DistinctValues", exclude=True
133-
)
134-
sample_values: Optional[list[any]] = Field(None, alias="SampleValues")
131+
distinct_values: Optional[list] = Field(None, alias="DistinctValues", exclude=True)
132+
sample_values: Optional[list] = Field(None, alias="SampleValues")
135133

136-
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
134+
model_config = ConfigDict(populate_by_name=True)
137135

138136
def value_store_entry(
139137
self, entity, distinct_value, excluded_fields_for_database_engine

0 commit comments

Comments
 (0)