當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。