Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 484-feat-support-integer-types-other-than-bi…
Browse files Browse the repository at this point in the history
…gint
edgarrmondragon committed Jan 27, 2025
2 parents f7ebe6b + f77971c commit 809ca8e
Showing 3 changed files with 325 additions and 305 deletions.
610 changes: 309 additions & 301 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ sqlalchemy = "~=2.0"
sshtunnel = "0.4.0"

[tool.poetry.dependencies.singer-sdk]
version = "~=0.43.0"
version = "~=0.44.0"

[tool.poetry.extras]
faker = ["faker"]
18 changes: 15 additions & 3 deletions target_postgres/connector.py
Original file line number Diff line number Diff line change
@@ -49,9 +49,14 @@
class JSONSchemaToPostgres(JSONSchemaToSQL):
"""Convert JSON Schema types to Postgres types."""

def __init__(self, *, content_encoding: bool = True) -> None:
def __init__(
self,
*args: t.Any,
content_encoding: bool = True,
**kwargs: t.Any,
) -> None:
"""Initialize the JSONSchemaToPostgres instance."""
super().__init__()
super().__init__(*args, **kwargs)
self.content_encoding = content_encoding

def handle_raw_string(self, schema):
@@ -71,6 +76,10 @@ class PostgresConnector(SQLConnector):
allow_merge_upsert: bool = True # Whether MERGE UPSERT is supported.
allow_temp_tables: bool = True # Whether temp tables are supported.

#: Maximum length of a VARCHAR column.
#: https://www.postgresql.org/docs/current/datatype-character.html
max_varchar_length: int | None = 10_485_760

def __init__(self, config: dict) -> None:
"""Initialize a connector to a Postgres database.
@@ -286,7 +295,10 @@ def _handle_integer_type(self, jsonschema: dict) -> SMALLINT | INTEGER | BIGINT:
@cached_property
def jsonschema_to_sql(self) -> JSONSchemaToSQL:
"""Return a JSONSchemaToSQL instance with custom type handling."""
to_sql = JSONSchemaToPostgres(content_encoding=self.interpret_content_encoding)
to_sql = JSONSchemaToPostgres(
content_encoding=self.interpret_content_encoding,
max_varchar_length=self.max_varchar_length,
)
to_sql.fallback_type = TEXT
to_sql.register_type_handler("integer", self._handle_integer_type)
to_sql.register_type_handler("object", JSONB)

0 comments on commit 809ca8e

Please sign in to comment.