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 custom- x-sql-datatypeannotations into SQLAlchemy types.- classmethod from_config(config, *, max_varchar_length)[source]¶
- Create a new instance from a configuration dictionary. - Override this to instantiate this converter with values from the target’s configuration dictionary. - class CustomJSONSchemaToSQL(JSONSchemaToSQL): @classmethod def from_config(cls, config, **kwargs): return cls(max_varchar_length=config.get("max_varchar_length")) - Parameters:
- Returns:
- A new instance of the class. 
- Return type:
 
 - __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-datatypehandler.- Parameters:
- Return type:
- None 
 - Example - >>> from sqlalchemy.types import SMALLINT >>> to_sql = JSONSchemaToSQL() >>> to_sql.register_sql_datatype_handler("smallint", SMALLINT)