Skip to content

Commit 5f0f6aa

Browse files
refactor: Use sql_to_jsonschema_converter (#547)
Blocked by a release of the Singer SDK.
1 parent e6761e7 commit 5f0f6aa

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tap_postgres/client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@
3535
class PostgresSQLToJSONSchema(SQLToJSONSchema):
3636
"""Custom SQL to JSON Schema conversion for Postgres."""
3737

38-
def __init__(self, dates_as_string: bool, json_as_object: bool, *args, **kwargs):
38+
def __init__(self, *, dates_as_string: bool, json_as_object: bool, **kwargs):
3939
"""Initialize the SQL to JSON Schema converter."""
40-
super().__init__(*args, **kwargs)
40+
super().__init__(**kwargs)
4141
self.dates_as_string = dates_as_string
4242
self.json_as_object = json_as_object
4343

44+
@classmethod
45+
def from_config(cls, config: dict) -> PostgresSQLToJSONSchema:
46+
"""Instantiate the SQL to JSON Schema converter from a config dictionary."""
47+
return cls(
48+
dates_as_string=config["dates_as_string"],
49+
json_as_object=config["json_as_object"],
50+
)
51+
4452
@functools.singledispatchmethod
4553
def to_jsonschema(self, column_type: t.Any) -> dict:
4654
"""Customize the JSON Schema for Postgres types."""
@@ -132,6 +140,8 @@ def patched_conform(elem: t.Any, property_schema: dict) -> t.Any:
132140
class PostgresConnector(SQLConnector):
133141
"""Connects to the Postgres SQL source."""
134142

143+
sql_to_jsonschema_converter = PostgresSQLToJSONSchema
144+
135145
def __init__(
136146
self,
137147
config: dict | None = None,
@@ -160,14 +170,6 @@ def __init__(
160170

161171
super().__init__(config=config, sqlalchemy_url=sqlalchemy_url)
162172

163-
@functools.cached_property
164-
def sql_to_jsonschema(self):
165-
"""Return a mapping of SQL types to JSON Schema types."""
166-
return PostgresSQLToJSONSchema(
167-
dates_as_string=self.config["dates_as_string"],
168-
json_as_object=self.config["json_as_object"],
169-
)
170-
171173
def get_schema_names(self, engine: Engine, inspected: Inspector) -> list[str]:
172174
"""Return a list of schema names in DB, or overrides with user-provided values.
173175

0 commit comments

Comments
 (0)