Skip to content

Commit

Permalink
Merge pull request #28 from geoCML/boolean-ignore-rasters
Browse files Browse the repository at this point in the history
Support boolean data types + ignore raster layers
  • Loading branch information
TristanDamron authored Oct 14, 2024
2 parents 8dbf3a7 + 2184f2b commit d0910d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ def get_tables(self) -> list[str]:
self.cursor.execute("""SELECT schema_name FROM information_schema.schemata WHERE schema_name != 'pg_catalog' AND schema_name != 'information_schema';""")
schemata = self.cursor.fetchall()

try:
self.cursor.execute("""SELECT * FROM raster_columns;""")
has_rasters = True
except:
has_rasters = False

for schema in schemata:
self.cursor.execute(f"""SELECT table_name FROM information_schema.tables WHERE table_schema = '{schema[0]}'""")
for table in self.cursor.fetchall():
if has_rasters:
self.cursor.execute(f"""SELECT * FROM raster_columns WHERE r_table_name = '{table[0]}' AND r_table_schema = '{schema[0]}';""")
if self.cursor.fetchone():
continue
tables.append(f"{schema[0]}.{table[0]}")

return tables
Expand Down
16 changes: 14 additions & 2 deletions src/tabor_field_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ class TaborFieldType(object):
postgres_integer_types = ("smallint", "integer", "bigint", "int2", "int4", "int8")
postgres_numerical_types = ("double precision", "float", "numeric")
postgres_text_types = ("character varying", "name", "text")
postgres_binary_types = ("boolean")
postgres_collection_types = ("TEXT ARRAY", "text array") # TODO: https://github.com/geoCML/tabor/issues/27
postgres_generic_types = ("USER-DEFINED", "user-defined") # TODO: https://github.com/geoCML/tabor/issues/26

def __init__(self, type: str):
self.valid_types = ("text", "int", "numeric")
self.valid_types = ("text", "int", "numeric", "boolean", "text array", "user-defined")
if type != "":
self.set_type(type)


def convert_postgres_type_to_tabor_field_type(self, type):
def convert_postgres_type_to_tabor_field_type(self, type: str) -> str:
if type in self.postgres_integer_types:
return "int"

Expand All @@ -19,6 +22,15 @@ def convert_postgres_type_to_tabor_field_type(self, type):
if type in self.postgres_numerical_types:
return "numeric"

if type in self.postgres_binary_types:
return "boolean"

if type in self.postgres_collection_types:
return type.lower()

if type in self.postgres_generic_types:
return "user-defined"

return type


Expand Down

0 comments on commit d0910d9

Please sign in to comment.