-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate table comment extraction for models
Generated-by: aiautocommit
- Loading branch information
1 parent
6fcd768
commit b7b9722
Showing
5 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Test database comments integration | ||
""" | ||
|
||
from activemodel import BaseModel | ||
from activemodel.mixins.timestamps import TimestampsMixin | ||
from activemodel.mixins.typeid import TypeIDMixin | ||
from activemodel.session_manager import get_session | ||
from sqlmodel import text | ||
|
||
|
||
class ExampleWithoutComments( | ||
BaseModel, TimestampsMixin, TypeIDMixin("ex2"), table=True | ||
): | ||
pass | ||
|
||
|
||
TABLE_COMMENT = "Expected table comment" | ||
|
||
|
||
class ExampleWithComments(BaseModel, TimestampsMixin, TypeIDMixin("ex"), table=True): | ||
"""Expected table comment""" | ||
|
||
|
||
def test_comment(create_and_wipe_database): | ||
assert ExampleWithComments.__doc__ | ||
assert not ExampleWithoutComments.__doc__ | ||
|
||
connection = create_and_wipe_database | ||
with get_session() as session: | ||
result = session.execute( | ||
text(""" | ||
SELECT obj_description('example_with_comments'::regclass, 'pg_class') AS table_comment; | ||
""") | ||
) | ||
table_comment = result.fetchone()[0] | ||
assert table_comment == "Expected table comment" | ||
|
||
# session.exec( | ||
# text(""" | ||
# SELECT col_description('example_with_comments'::regclass, ordinal_position) AS column_comment | ||
# FROM information_schema.columns | ||
# WHERE table_name = 'example_with_comments' AND column_name = 'your_column'; | ||
# """) | ||
# ) | ||
# column_comment = cursor.fetchone()[0] | ||
# assert column_comment == "Expected column comment" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import pytest | ||
|
||
import activemodel | ||
from activemodel.session_manager import get_engine | ||
from sqlmodel import SQLModel | ||
|
||
from .utils import database_url | ||
from .utils import database_url, temporary_tables | ||
|
||
activemodel.init(database_url()) | ||
|
||
SQLModel.metadata.drop_all( | ||
bind=get_engine(), | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def create_and_wipe_database(): | ||
with temporary_tables(): | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters