def get_column_spec( cls, native_type: Optional[str], source: utils.ColumnTypeSource = utils.ColumnTypeSource.GET_TABLE, column_type_mappings: Tuple[ Tuple[ Pattern[str], Union[TypeEngine, Callable[[Match[str]], TypeEngine]], GenericDataType, ], ..., ] = column_type_mappings, ) -> Union[ColumnSpec, None]: """ Converts native database type to sqlalchemy column type. :param native_type: Native database typee :param source: Type coming from the database table or cursor description :return: ColumnSpec object """ col_types = cls.get_sqla_column_type( native_type, column_type_mappings=column_type_mappings ) if col_types: column_type, generic_type = col_types # wrap temporal types in custom type that supports literal binding # using datetimes if generic_type == GenericDataType.TEMPORAL: column_type = literal_dttm_type_factory( type(column_type), cls, native_type or "" ) is_dttm = generic_type == GenericDataType.TEMPORAL return ColumnSpec( sqla_type=column_type, generic_type=generic_type, is_dttm=is_dttm ) return None
def test_literal_dttm_type_factory(): orig_type = DateTime() new_type = literal_dttm_type_factory( orig_type, PostgresEngineSpec, "TIMESTAMP", db_extra={} ) assert type(new_type).__name__ == "TemporalWrapperType" assert str(new_type) == str(orig_type)