singer_sdk.connectors.sql.JSONSchemaToSQL¶
- class singer_sdk.connectors.sql.JSONSchemaToSQL[source]¶
A configurable mapper for converting JSON Schema types to SQLAlchemy types.
This class provides a mapping from JSON Schema types to SQLAlchemy types.
Added in version 0.42.0.
Changed in version 0.44.0: Added the
singer_sdk.connectors.sql.JSONSchemaToSQL.register_sql_datatype_handler()
method to map customx-sql-datatype
annotations into SQLAlchemy types.- __init__(*, max_varchar_length=None)[source]¶
Initialize the mapper with default type mappings.
- Parameters:
max_varchar_length (int | None) – The absolute maximum length for VARCHAR columns that the database supports.
- Return type:
None
- handle_raw_string(schema)[source]¶
Handle a string type generically.
- Parameters:
schema (dict) – The JSON Schema object.
- Returns:
Appropriate SQLAlchemy type.
- Return type:
TypeEngine
- register_sql_datatype_handler(sql_datatype, handler)[source]¶
Register a custom
x-sql-datatype
handler.- Parameters:
- Return type:
None
Example
>>> from sqlalchemy.types import SMALLINT >>> to_sql = JSONSchemaToSQL() >>> to_sql.register_sql_datatype_handler("smallint", SMALLINT)