Skip to content

Commit dcd7ec4

Browse files
test: Test with singer-sdk @ main
1 parent 4f4b9c7 commit dcd7ec4

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

poetry.lock

Lines changed: 17 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ sqlalchemy = "~=2.0"
4040
sshtunnel = "0.4.0"
4141

4242
[tool.poetry.dependencies.singer-sdk]
43-
version = "~=0.42.0b1"
43+
git = "https://github.com/meltano/sdk.git"
44+
branch = "edgarrmondragon/refactor/jsonschematosql-fromconfig"
4445

4546
[tool.poetry.extras]
4647
faker = ["faker"]

target_postgres/connector.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def __init__(self, *, content_encoding: bool = True) -> None:
4646
super().__init__()
4747
self.content_encoding = content_encoding
4848

49+
@classmethod
50+
def from_config(
51+
cls: type[JSONSchemaToPostgres],
52+
config: dict,
53+
) -> JSONSchemaToPostgres:
54+
"""Create a JSONSchemaToPostgres instance from a configuration."""
55+
return cls(content_encoding=config.get("interpret_content_encoding", False))
56+
4957
def handle_raw_string(self, schema):
5058
"""Handle a raw string type."""
5159
if self.content_encoding and schema.get("contentEncoding") == "base16":
@@ -63,6 +71,8 @@ class PostgresConnector(SQLConnector):
6371
allow_merge_upsert: bool = True # Whether MERGE UPSERT is supported.
6472
allow_temp_tables: bool = True # Whether temp tables are supported.
6573

74+
jsonschema_to_sql_converter = JSONSchemaToPostgres
75+
6676
def __init__(self, config: dict) -> None:
6777
"""Initialize a connector to a Postgres database.
6878
@@ -100,18 +110,6 @@ def __init__(self, config: dict) -> None:
100110
sqlalchemy_url=url.render_as_string(hide_password=False),
101111
)
102112

103-
@cached_property
104-
def interpret_content_encoding(self) -> bool:
105-
"""Whether to interpret schema contentEncoding to set the column type.
106-
107-
It is an opt-in feature because it might result in data loss if the
108-
actual data does not match the schema's advertised encoding.
109-
110-
Returns:
111-
True if the feature is enabled, False otherwise.
112-
"""
113-
return self.config.get("interpret_content_encoding", False)
114-
115113
def prepare_table( # type: ignore[override] # noqa: PLR0913
116114
self,
117115
full_table_name: str | FullyQualifiedName,
@@ -258,7 +256,7 @@ def _handle_array_type(self, jsonschema: dict) -> ARRAY | JSONB:
258256
@cached_property
259257
def jsonschema_to_sql(self) -> JSONSchemaToSQL:
260258
"""Return a JSONSchemaToSQL instance with custom type handling."""
261-
to_sql = JSONSchemaToPostgres(content_encoding=self.interpret_content_encoding)
259+
to_sql = JSONSchemaToPostgres.from_config(self.config)
262260
to_sql.fallback_type = TEXT
263261
to_sql.register_type_handler("integer", BIGINT)
264262
to_sql.register_type_handler("object", JSONB)

0 commit comments

Comments
 (0)