Example #1
0
 def _get_columns(self, connection, table_name, schema: str = None, **kw):  # type: ignore
     schema = schema or self._get_default_schema_name(connection)
     query = dedent(
         """
         SELECT
             "column_name",
             "data_type",
             "column_default",
             UPPER("is_nullable") AS "is_nullable",
             "comment"
         FROM "information_schema"."columns"
         WHERE "table_schema" = :schema
           AND "table_name" = :table
         ORDER BY "ordinal_position" ASC
     """
     ).strip()
     res = connection.execute(sql.text(query), schema=schema, table=table_name)
     columns = []
     for record in res:
         column = dict(
             name=record.column_name,
             type=datatype.parse_sqltype(record.data_type),
             nullable=record.is_nullable == "YES",
             default=record.column_default,
             comment=record.comment,
         )
         columns.append(column)
     return columns
def test_parse_row(type_str: str, sql_type: ARRAY):
    actual_type = datatype.parse_sqltype(type_str)
    assert_that(actual_type).is_sqltype(sql_type)
def test_parse_type_options(type_str: str, sql_type: TypeEngine):
    actual_type = datatype.parse_sqltype(type_str)
    assert_that(actual_type).is_sqltype(sql_type)
def test_parse_simple_type(type_str: str, sql_type: TypeEngine):
    actual_type = datatype.parse_sqltype(type_str)
    if not isinstance(actual_type, type):
        actual_type = type(actual_type)
    assert_that(actual_type).is_equal_to(sql_type)