Skip to content

Commit

Permalink
docs: Added more versions when stuff changed or was added
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 10, 2024
1 parent 595392f commit 7deac7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/guides/sql-tap.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Building SQL taps

## Default type mapping
## Mapping SQL types to JSON Schema

Starting with the `v0.41.0`, the Meltano Singer SDK provides a clean way to map SQL types to JSON Schema. This is useful when the SQL dialect you are using has custom types that need to be mapped accordingly to JSON Schema.

### Default type mapping

The Singer SDK automatically handles the most common SQLAlchemy column types, using [`functools.singledispatchmethod`](inv:python:py:class:#functools.singledispatchmethod) to process each type. See the [`SQLToJSONSchema`](connectors.sql.SQLToJSONSchema) reference documentation for details.

## Custom type mapping
### Custom type mapping

If the class above doesn't cover all the types supported by the SQLAlchemy dialect in your tap, you can subclass it and override or extend with a new method for the type you need to support:

Expand Down
15 changes: 15 additions & 0 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class SQLToJSONSchema:
"""SQLAlchemy to JSON Schema type mapping helper.
This class provides a mapping from SQLAlchemy types to JSON Schema types.
.. versionadded:: 0.41.0
"""

@functools.singledispatchmethod
Expand Down Expand Up @@ -171,6 +173,10 @@ def string_to_jsonschema(self, column_type: sa.types.String) -> dict: # noqa: P
Args:
column_type (:column_type:`String`): The column type.
.. versionchanged:: 0.41.0
The ``length`` attribute is now used to determine the maximum length of the
string type.
"""
if column_type.length:
return th.StringType(max_length=column_type.length).type_dict # type: ignore[no-any-return]
Expand Down Expand Up @@ -247,6 +253,8 @@ def sql_to_jsonschema(self) -> SQLToJSONSchema:
Returns:
The type mapper object.
.. versionadded:: 0.41.0
"""
return SQLToJSONSchema()

Expand Down Expand Up @@ -380,6 +388,10 @@ def to_jsonschema_type(
Returns:
The JSON Schema representation of the provided type.
.. versionchanged:: 0.40.0
Support for SQLAlchemy type classes and strings in the ``sql_type`` argument
was deprecated. Please pass a SQLAlchemy type object instead.
"""
if isinstance(sql_type, sa.types.TypeEngine):
return self.sql_to_jsonschema.to_jsonschema(sql_type)
Expand Down Expand Up @@ -445,6 +457,9 @@ def get_fully_qualified_name(
Returns:
The fully qualified name as a string.
.. versionchanged:: 0.40.0
A ``FullyQualifiedName`` object is now returned.
"""
return FullyQualifiedName(
table=table_name, # type: ignore[arg-type]
Expand Down
2 changes: 2 additions & 0 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def user_agent(self) -> str:
Returns:
The user agent string.
.. versionadded:: 0.40.0
"""
return self.config.get(
"user_agent",
Expand Down

0 comments on commit 7deac7c

Please sign in to comment.