Skip to content

Commit

Permalink
Add method get_schemas to retrieve postgres schemas (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 authored Nov 17, 2023
1 parent dc192f5 commit e1de484
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************/
"""
import logging
import re

import psycopg2
Expand Down Expand Up @@ -1073,3 +1074,20 @@ def get_ili2db_settings(self):
)
result = cur.fetchall()
return result

def get_schemas(self):
cursor = self.conn.cursor()
try:
cursor.execute(
"""SELECT schema_name
FROM information_schema.schemata"""
)
except psycopg2.errors.Error as e:
error_message = " ".join(e.args)
logging.error(f"Could not get the list of schemas: {error_message}")
return []

schemas = cursor.fetchall()

# Transform list of tuples into list
return list(sum(schemas, ()))

0 comments on commit e1de484

Please sign in to comment.