Skip to content

Commit

Permalink
Update postgresql generator with relationships path (#96)
Browse files Browse the repository at this point in the history
* Add relationships path to PostgresqlPathsModel

* Update README with example of relationships path. Fix previous mistakes.

* Update tests

---------

Co-authored-by: Valerii Mironchenko <vmironchenko@provectus.com>
  • Loading branch information
ValeriyWorld and Valerii Mironchenko committed Jan 24, 2024
1 parent b92a6e0 commit 9b71405
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
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

0 comments on commit 9b71405

Please sign in to comment.