当前位置: 首页>>代码示例>>Python>>正文


Python types.NullType方法代码示例

本文整理汇总了Python中sqlalchemy.types.NullType方法的典型用法代码示例。如果您正苦于以下问题:Python types.NullType方法的具体用法?Python types.NullType怎么用?Python types.NullType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.types的用法示例。


在下文中一共展示了types.NullType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _compare_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def _compare_type(
    autogen_context, alter_column_op, schema, tname, cname, conn_col,
        metadata_col):

    conn_type = conn_col.type
    alter_column_op.existing_type = conn_type
    metadata_type = metadata_col.type
    if conn_type._type_affinity is sqltypes.NullType:
        log.info("Couldn't determine database type "
                 "for column '%s.%s'", tname, cname)
        return
    if metadata_type._type_affinity is sqltypes.NullType:
        log.info("Column '%s.%s' has no type within "
                 "the model; can't compare", tname, cname)
        return

    isdiff = autogen_context.migration_context._compare_type(
        conn_col, metadata_col)

    if isdiff:
        alter_column_op.modify_type = metadata_type
        log.info("Detected type change from %r to %r on '%s.%s'",
                 conn_type, metadata_type, tname, cname
                 ) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:compare.py

示例2: test_varchar_as_nulltype

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_varchar_as_nulltype(self):
        """
        Varchar columns with no length should be considered NullType columns
        """
        dialect = RedshiftDialect()
        column_info = dialect._get_column_info(
            'Null Column',
            'character varying', None, False, {}, {}, 'default', 'test column'
        )
        assert isinstance(column_info['type'], NullType)
        column_info_1 = dialect._get_column_info(
            'character column',
            'character varying(30)', None, False, {}, {}, 'default',
            comment='test column'
        )
        assert isinstance(column_info_1['type'], VARCHAR) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:18,代码来源:test_column_loading.py

示例3: _type_affinity_fixture

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def _type_affinity_fixture(self):
        return [
            ("LONGTEXT", sqltypes.TEXT()),
            ("TINYINT", sqltypes.INTEGER()),
            ("MEDIUMINT", sqltypes.INTEGER()),
            ("INT2", sqltypes.INTEGER()),
            ("UNSIGNED BIG INT", sqltypes.INTEGER()),
            ("INT8", sqltypes.INTEGER()),
            ("CHARACTER(20)", sqltypes.TEXT()),
            ("CLOB", sqltypes.TEXT()),
            ("CLOBBER", sqltypes.TEXT()),
            ("VARYING CHARACTER(70)", sqltypes.TEXT()),
            ("NATIVE CHARACTER(70)", sqltypes.TEXT()),
            ("BLOB", sqltypes.BLOB()),
            ("BLOBBER", sqltypes.NullType()),
            ("DOUBLE PRECISION", sqltypes.REAL()),
            ("FLOATY", sqltypes.REAL()),
            ("SOMETHING UNKNOWN", sqltypes.NUMERIC()),
        ] 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_sqlite.py

示例4: test_typing_construction

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_typing_construction(self):
        t = text("select * from table :foo :bar :bat")

        self._assert_type_map(
            t, {"foo": NullType(), "bar": NullType(), "bat": NullType()}
        )

        t = t.bindparams(bindparam("foo", type_=String))

        self._assert_type_map(
            t, {"foo": String(), "bar": NullType(), "bat": NullType()}
        )

        t = t.bindparams(bindparam("bar", type_=Integer))

        self._assert_type_map(
            t, {"foo": String(), "bar": Integer(), "bat": NullType()}
        )

        t = t.bindparams(bat=45.564)

        self._assert_type_map(
            t, {"foo": String(), "bar": Integer(), "bat": Float()}
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_text.py

示例5: get_columns

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def get_columns(self, connection, table_name, schema=None, **kw):
        # Extend types supported by PrestoDialect as defined in PyHive
        type_map = {
            'bigint': sql_types.BigInteger,
            'integer': sql_types.Integer,
            'boolean': sql_types.Boolean,
            'double': sql_types.Float,
            'varchar': sql_types.String,
            'timestamp': sql_types.TIMESTAMP,
            'date': sql_types.DATE,
            'array<bigint>': sql_types.ARRAY(sql_types.Integer),
            'array<varchar>': sql_types.ARRAY(sql_types.String)
        }

        rows = self._get_table_columns(connection, table_name, schema)
        result = []
        for row in rows:
            try:
                coltype = type_map[row.Type]
            except KeyError:
                logger.warn("Did not recognize type '%s' of column '%s'" % (row.Type, row.Column))
                coltype = sql_types.NullType
            result.append({
                'name': row.Column,
                'type': coltype,
                # newer Presto no longer includes this column
                'nullable': getattr(row, 'Null', True),
                'default': None,
            })
        return result 
开发者ID:airbnb,项目名称:omniduct,代码行数:32,代码来源:_schemas.py

示例6: create_index

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def create_index(self, index):
        # this likely defaults to None if not present, so get()
        # should normally not return the default value.  being
        # defensive in any case
        mssql_include = index.kwargs.get("mssql_include", None) or ()
        for col in mssql_include:
            if col not in index.table.c:
                index.table.append_column(Column(col, sqltypes.NullType))
        self._exec(CreateIndex(index)) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:11,代码来源:mssql.py

示例7: _compare_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def _compare_type(
    autogen_context,
    alter_column_op,
    schema,
    tname,
    cname,
    conn_col,
    metadata_col,
):

    conn_type = conn_col.type
    alter_column_op.existing_type = conn_type
    metadata_type = metadata_col.type
    if conn_type._type_affinity is sqltypes.NullType:
        log.info(
            "Couldn't determine database type " "for column '%s.%s'",
            tname,
            cname,
        )
        return
    if metadata_type._type_affinity is sqltypes.NullType:
        log.info(
            "Column '%s.%s' has no type within " "the model; can't compare",
            tname,
            cname,
        )
        return

    isdiff = autogen_context.migration_context._compare_type(
        conn_col, metadata_col
    )

    if isdiff:
        alter_column_op.modify_type = metadata_type
        log.info(
            "Detected type change from %r to %r on '%s.%s'",
            conn_type,
            metadata_type,
            tname,
            cname,
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:43,代码来源:compare.py

示例8: get_columns

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def get_columns(self, connection, table_name, schema=None, **kw):
        rows = self._get_table_columns(connection, table_name, schema)
        result = []
        for r in rows:
            col_name = r.name
            col_type = ""
            if r.type.startswith("AggregateFunction"):
                # Extract type information from a column
                # using AggregateFunction
                # the type from clickhouse will be 
                # AggregateFunction(sum, Int64) for an Int64 type
                # remove first 24 chars and remove the last one to get Int64
                col_type = r.type[23:-1]
            else:    
                # Take out the more detailed type information
                # e.g. 'map<int,int>' -> 'map'
                #      'decimal(10,1)' -> decimal                
                col_type = re.search(r'^\w+', r.type).group(0)
            try:
                coltype = ischema_names[col_type]
            except KeyError:
                coltype = sqltypes.NullType
            result.append({
                'name': col_name,
                'type': coltype,
                'nullable': True,
                'default': None,
            })
        return result 
开发者ID:cloudflare,项目名称:sqlalchemy-clickhouse,代码行数:31,代码来源:base.py

示例9: test_skip_types

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_skip_types(self):
        metadata = self.metadata
        with testing.db.connect() as c:
            c.exec_driver_sql(
                "create table foo (id integer primary key, data xml)"
            )
        with mock.patch.object(
            testing.db.dialect, "ischema_names", {"int": mssql.INTEGER}
        ):
            t1 = Table("foo", metadata, autoload=True)
        assert isinstance(t1.c.id.type, Integer)
        assert isinstance(t1.c.data.type, types.NullType) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_reflection.py

示例10: test_bind_adapt_update

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_bind_adapt_update(self):
        bp = bindparam("somevalue")
        stmt = test_table.update().values(avalue=bp)
        compiled = stmt.compile()
        eq_(bp.type._type_affinity, types.NullType)
        eq_(compiled.binds["somevalue"].type._type_affinity, MyCustomType) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_types.py

示例11: test_bind_adapt_insert

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_bind_adapt_insert(self):
        bp = bindparam("somevalue")
        stmt = test_table.insert().values(avalue=bp)
        compiled = stmt.compile()
        eq_(bp.type._type_affinity, types.NullType)
        eq_(compiled.binds["somevalue"].type._type_affinity, MyCustomType) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_types.py

示例12: test_bind_typing

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_bind_typing(self):
        from sqlalchemy.sql import column

        class MyFoobarType(types.UserDefinedType):
            pass

        class Foo(object):
            pass

        # unknown type + integer, right hand bind
        # coerces to given type
        expr = column("foo", MyFoobarType) + 5
        assert expr.right.type._type_affinity is MyFoobarType

        # untyped bind - it gets assigned MyFoobarType
        bp = bindparam("foo")
        expr = column("foo", MyFoobarType) + bp
        assert bp.type._type_affinity is types.NullType  # noqa
        assert expr.right.type._type_affinity is MyFoobarType

        expr = column("foo", MyFoobarType) + bindparam("foo", type_=Integer)
        assert expr.right.type._type_affinity is types.Integer

        # unknown type + unknown, right hand bind
        # coerces to the left
        expr = column("foo", MyFoobarType) + Foo()
        assert expr.right.type._type_affinity is MyFoobarType

        # including for non-commutative ops
        expr = column("foo", MyFoobarType) - Foo()
        assert expr.right.type._type_affinity is MyFoobarType

        expr = column("foo", MyFoobarType) - datetime.date(2010, 8, 25)
        assert expr.right.type._type_affinity is MyFoobarType 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:36,代码来源:test_types.py

示例13: test_date_coercion

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_date_coercion(self):
        expr = column("bar", types.NULLTYPE) - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.NullType)

        expr = func.sysdate() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval)

        expr = func.current_date() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:11,代码来源:test_types.py

示例14: test_null_comparison

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def test_null_comparison(self):
        eq_(
            str(column("a", types.NullType()) + column("b", types.NullType())),
            "a + b",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_types.py

示例15: _compare_param_dict

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NullType [as 别名]
def _compare_param_dict(self, a, b):
        if list(a) != list(b):
            return False

        from sqlalchemy.types import NullType

        for a_k, a_i in a.items():
            b_i = b[a_k]

            # compare BindParameter on the left to
            # literal value on the right
            assert a_i.compare(literal(b_i, type_=NullType())) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_external_traversal.py


注:本文中的sqlalchemy.types.NullType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。