Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update postgresql generator with relationships path #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,31 @@ oddrn_gen = PostgresqlGenerator(
oddrn_gen.base_oddrn
# //postgresql/host/my.host.com:5432
oddrn_gen.available_paths
# ('schemas', 'databases', 'tables', 'columns')
# ('databases', 'schemas', 'tables', 'views', 'tables_columns', 'views_columns', 'relationships')

oddrn_gen.get_data_source_oddrn()
# //postgresql/host/my.host.com:5432/schemas/schema_name/databases/database_name
# //postgresql/host/my.host.com:5432/databases/database_name

oddrn_gen.get_oddrn_by_path("schemas")
# //postgresql/host/my.host.com:5432/schemas/schema_name
# //postgresql/host/my.host.com:5432/databases/database_name/schemas/schema_name

oddrn_gen.get_oddrn_by_path("databases")
# //postgresql/host/my.host.com:5432/schemas/schema_name/databases/database_name
# //postgresql/host/my.host.com:5432/databases/database_name

oddrn_gen.get_oddrn_by_path("tables")
# //postgresql/host/my.host.com:5432/schemas/schema_name/databases/database_name/tables/table_name
# //postgresql/host/my.host.com:5432/databases/database_name/schemas/schema_name/tables/table_name

# you can set or change path:
oddrn_gen.set_oddrn_paths(tables='another_table_name', columns='new_column_name')
oddrn_gen.get_oddrn_by_path("columns")
# //postgresql/host/my.host.com:5432/schemas/schema_name/databases/database_name/tables/another_table_name/columns/new_column_name
oddrn_gen.set_oddrn_paths(tables="another_table_name", tables_columns="new_column_name")
oddrn_gen.get_oddrn_by_path("tables_columns")
# //postgresql/host/my.host.com:5432/databases/database_name/schemas/schema_name/tables/another_table_name/columns/new_column_name

oddrn_gen.set_oddrn_paths(relationships="references_table_2_with_constraint_fk")
# //postgresql/host/my.host.com:5432/databases/database_name/schemas/schema_name/tables/another_table_name/relationships/references_table_2_with_constraint_fk

# you can get path wih new values:
oddrn_gen.get_oddrn_by_path("columns", new_value="another_new_column_name")
# //postgresql/host/my.host.com:5432/schemas/schema_name/databases/database_name/tables/another_table_name/columns/another_new_column_name
oddrn_gen.get_oddrn_by_path("tables_columns", new_value="another_new_column_name")
# //postgresql/host/my.host.com:5432/databases/database_name/schemas/schema_name/tables/another_table_name/columns/another_new_column_name


# glue
Expand Down Expand Up @@ -160,9 +163,9 @@ from oddrn_generator import PostgresqlGenerator
oddrn_gen = PostgresqlGenerator(
host_settings='my.host.com:5432',
schemas='schema_name', databases='database_name',
columns='column_without_table'
tables_columns='column_without_table'
)
# WrongPathOrderException: 'columns' can not be without 'tables' attribute
# WrongPathOrderException: 'tables_columns' can not be without 'tables' attribute
```

* EmptyPathValueException - raises when trying to get a path that is not set up
Expand Down Expand Up @@ -201,5 +204,5 @@ poetry install
poetry shell

# Run tests
python run pytest
pytest tests/
```
2 changes: 2 additions & 0 deletions oddrn_generator/path_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class PostgresqlPathsModel(BasePathsModel):
views: Optional[str]
tables_columns: Optional[str] = Field(alias="columns")
views_columns: Optional[str] = Field(alias="columns")
relationships: Optional[str]

class Config:
dependencies_map = {
Expand All @@ -67,6 +68,7 @@ class Config:
"views": ("databases", "schemas", "views"),
"tables_columns": ("databases", "schemas", "tables", "tables_columns"),
"views_columns": ("databases", "schemas", "views", "views_columns"),
"relationships": ("databases", "schemas", "tables", "relationships"),
}
data_source_path = "databases"

Expand Down
1 change: 1 addition & 0 deletions tests/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"views": "some_view",
"tables_columns": "some_table_column",
"views_columns": "some_view_column",
"relationships": "some_relationship",
},
"aliases": {
"tables_columns": "columns",
Expand Down
Loading