Skip to content

Commit

Permalink
Merge pull request #37 from DalgoT4D/fetching-schemas-database
Browse files Browse the repository at this point in the history
fetching schemas/datasets in postgres and bigquery
  • Loading branch information
fatchat authored Oct 25, 2023
2 parents 33bf2d8 + b8b48c2 commit be4f774
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dbt_automation/utils/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def get_tables(self, schema: str) -> list:
tables = self.bqclient.list_tables(schema)
return [x.table_id for x in tables]

def get_schemas(self) -> list:
"""returns the list of schema names in the given connection"""
datasets = self.bqclient.list_datasets()
return [x.dataset_id for x in datasets]

def get_table_columns(self, schema: str, table: str) -> list:
"""fetch the list of columns from a BigQuery table."""
table_ref = f"{schema}.{table}"
Expand Down
11 changes: 11 additions & 0 deletions dbt_automation/utils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def get_tables(self, schema: str) -> list:
)
return [x[0] for x in resultset]

def get_schemas(self) -> list:
"""returns the list of schema names in the given database connection"""
resultset = self.execute(
f"""
SELECT nspname
FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema';
"""
)
return [x[0] for x in resultset]

def get_columnspec(self, schema: str, table: str):
"""get the column schema for this table"""
return [
Expand Down

0 comments on commit be4f774

Please sign in to comment.