當前位置: 首頁>>代碼示例>>Python>>正文


Python types.to_instance方法代碼示例

本文整理匯總了Python中sqlalchemy.types.to_instance方法的典型用法代碼示例。如果您正苦於以下問題:Python types.to_instance方法的具體用法?Python types.to_instance怎麽用?Python types.to_instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.types的用法示例。


在下文中一共展示了types.to_instance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(self, name, column_name, schema=None,
                 newname=None,
                 type_=None,
                 nullable=None,
                 default=False,
                 autoincrement=None):
        super(AlterColumn, self).__init__(name, schema=schema)
        self.column_name = column_name
        self.nullable = nullable
        self.newname = newname
        self.default = default
        self.autoincrement = autoincrement
        if type_ is None:
            raise util.CommandError(
                "All MySQL CHANGE/MODIFY COLUMN operations "
                "require the existing type."
            )

        self.type_ = sqltypes.to_instance(type_) 
開發者ID:jpush,項目名稱:jbox,代碼行數:21,代碼來源:mysql.py

示例2: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(
        self,
        name,
        column_name,
        schema=None,
        existing_type=None,
        existing_nullable=None,
        existing_server_default=None,
        existing_comment=None,
    ):
        super(AlterColumn, self).__init__(name, schema=schema)
        self.column_name = column_name
        self.existing_type = (
            sqltypes.to_instance(existing_type)
            if existing_type is not None
            else None
        )
        self.existing_nullable = existing_nullable
        self.existing_server_default = existing_server_default
        self.existing_comment = existing_comment 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:22,代碼來源:base.py

示例3: to_sql_pkey

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def to_sql_pkey(self, frame, name, if_exists='fail', index=True,
             index_label=None, schema=None,
             dtype=None, **kwargs):
    '''Function to load a table with the reqirement for a primary key.'''
    if dtype is not None:
        from sqlalchemy.types import to_instance, TypeEngine
        for col, my_type in dtype.items():
            if not isinstance(to_instance(my_type), TypeEngine):
                raise ValueError('The type of %s is not a SQLAlchemy '
                                 'type ' % col)

    table = pandas.io.sql.SQLTable(name, self,
                               frame=frame,
                               index=index,
                               if_exists=if_exists,
                               index_label=index_label,
                               schema=schema,
                               dtype=dtype, **kwargs)
    table.create()
    table.insert() 
開發者ID:cgat-developers,項目名稱:cgat-core,代碼行數:22,代碼來源:csv2db.py

示例4: _compile_ndb_string

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def _compile_ndb_string(element, compiler, **kw):
    """Process ndb specific overrides for String.

    Function will intercept mysql_ndb_length and mysql_ndb_type
    arguments to adjust columns automatically.

    mysql_ndb_length argument will adjust the String length
    to the requested value.

    mysql_ndb_type will change the column type to the requested
    data type.
    """
    if not ndb_status(compiler):
        return compiler.visit_string(element, **kw)

    if element.mysql_ndb_length:
        effective_type = element.adapt(
            _String, length=element.mysql_ndb_length)
        return compiler.visit_string(effective_type, **kw)
    elif element.mysql_ndb_type:
        effective_type = to_instance(element.mysql_ndb_type)
        return compiler.process(effective_type, **kw)
    else:
        return compiler.visit_string(element, **kw) 
開發者ID:openstack,項目名稱:oslo.db,代碼行數:26,代碼來源:ndb.py

示例5: test_varchar_raise

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def test_varchar_raise(self):
        for type_ in (
            String,
            VARCHAR,
            String(),
            VARCHAR(),
            Unicode,
            Unicode(),
        ):
            type_ = sqltypes.to_instance(type_)
            assert_raises_message(
                exc.CompileError,
                "VARCHAR requires a length on dialect firebird",
                type_.compile,
                dialect=firebird.dialect(),
            )

            t1 = Table("sometable", MetaData(), Column("somecolumn", type_))
            assert_raises_message(
                exc.CompileError,
                r"\(in table 'sometable', column 'somecolumn'\)\: "
                r"(?:N)?VARCHAR requires a length on dialect firebird",
                schema.CreateTable(t1).compile,
                dialect=firebird.dialect(),
            ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:27,代碼來源:test_firebird.py

示例6: test_varchar_raise

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def test_varchar_raise(self, type_):
        type_ = sqltypes.to_instance(type_)
        assert_raises_message(
            exc.CompileError,
            "VARCHAR requires a length on dialect mysql",
            type_.compile,
            dialect=mysql.dialect(),
        )

        t1 = Table("sometable", MetaData(), Column("somecolumn", type_))
        assert_raises_message(
            exc.CompileError,
            r"\(in table 'sometable', column 'somecolumn'\)\: "
            r"(?:N)?VARCHAR requires a length on dialect mysql",
            schema.CreateTable(t1).compile,
            dialect=mysql.dialect(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:19,代碼來源:test_compiler.py

示例7: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(self, name, column_name, schema=None,
                 existing_type=None,
                 existing_nullable=None,
                 existing_server_default=None):
        super(AlterColumn, self).__init__(name, schema=schema)
        self.column_name = column_name
        self.existing_type = sqltypes.to_instance(existing_type) \
            if existing_type is not None else None
        self.existing_nullable = existing_nullable
        self.existing_server_default = existing_server_default 
開發者ID:jpush,項目名稱:jbox,代碼行數:12,代碼來源:base.py

示例8: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(
        self,
        name,
        column_name,
        schema=None,
        newname=None,
        type_=None,
        nullable=None,
        default=False,
        autoincrement=None,
        comment=False,
    ):
        super(AlterColumn, self).__init__(name, schema=schema)
        self.column_name = column_name
        self.nullable = nullable
        self.newname = newname
        self.default = default
        self.autoincrement = autoincrement
        self.comment = comment
        if type_ is None:
            raise util.CommandError(
                "All MySQL CHANGE/MODIFY COLUMN operations "
                "require the existing type."
            )

        self.type_ = sqltypes.to_instance(type_) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:28,代碼來源:mysql.py

示例9: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(self, name, column_name, type_, **kw):
        using = kw.pop("using", None)
        super(PostgresqlColumnType, self).__init__(name, column_name, **kw)
        self.type_ = sqltypes.to_instance(type_)
        self.using = using 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:7,代碼來源:postgresql.py

示例10: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(self, base, field, type_):
        self.name = field
        self.type = to_instance(type_)

        super(CompositeElement, self).__init__(base) 
開發者ID:gltn,項目名稱:stdm,代碼行數:7,代碼來源:elements.py

示例11: test_uppercase_rendering

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def test_uppercase_rendering(self, dialect, type_, expected):
        """Test that uppercase types from types.py always render as their
        type.

        As of SQLA 0.6, using an uppercase type means you want specifically
        that type. If the database in use doesn't support that DDL, it (the DB
        backend) should raise an error - it means you should be using a
        lowercased (genericized) type.

        """

        if isinstance(expected, str):
            expected = (expected,)

        try:
            compiled = type_.compile(dialect=dialect)
        except NotImplementedError:
            return

        assert compiled in expected, "%r matches none of %r for dialect %s" % (
            compiled,
            expected,
            dialect.name,
        )

        assert (
            str(types.to_instance(type_)) in expected
        ), "default str() of type %r not expected, %r" % (type_, expected) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:30,代碼來源:test_types.py

示例12: test_typedecorator_impl

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def test_typedecorator_impl(self):
        for impl_, exp, kw in [
            (Float, "FLOAT", {}),
            (Float, "FLOAT(2)", {"precision": 2}),
            (Float(2), "FLOAT(2)", {"precision": 4}),
            (Numeric(19, 2), "NUMERIC(19, 2)", {}),
        ]:
            for dialect_ in (
                dialects.postgresql,
                dialects.mssql,
                dialects.mysql,
            ):
                dialect_ = dialect_.dialect()

                raw_impl = types.to_instance(impl_, **kw)

                class MyType(types.TypeDecorator):
                    impl = impl_

                dec_type = MyType(**kw)

                eq_(dec_type.impl.__class__, raw_impl.__class__)

                raw_dialect_impl = raw_impl.dialect_impl(dialect_)
                dec_dialect_impl = dec_type.dialect_impl(dialect_)
                eq_(dec_dialect_impl.__class__, MyType)
                eq_(
                    raw_dialect_impl.__class__, dec_dialect_impl.impl.__class__
                )

                self.assert_compile(MyType(**kw), exp, dialect=dialect_) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:33,代碼來源:test_types.py

示例13: __init__

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def __init__(self, name, column_name, type_, **kw):
        using = kw.pop('using', None)
        super(PostgresqlColumnType, self).__init__(name, column_name, **kw)
        self.type_ = sqltypes.to_instance(type_)
        self.using = using 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:7,代碼來源:postgresql.py

示例14: alter_column

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def alter_column(self, table_name, column_name,
                     nullable=None,
                     server_default=False,
                     name=None,
                     type_=None,
                     autoincrement=None,
                     **kw
                     ):
        existing = self.columns[column_name]
        existing_transfer = self.column_transfers[column_name]
        if name is not None and name != column_name:
            # note that we don't change '.key' - we keep referring
            # to the renamed column by its old key in _create().  neat!
            existing.name = name
            existing_transfer["name"] = name

        if type_ is not None:
            type_ = sqltypes.to_instance(type_)
            # old type is being discarded so turn off eventing
            # rules. Alternatively we can
            # erase the events set up by this type, but this is simpler.
            # we also ignore the drop_constraint that will come here from
            # Operations.implementation_for(alter_column)
            if isinstance(existing.type, SchemaEventTarget):
                existing.type._create_events = \
                    existing.type.create_constraint = False

            existing.type = type_

            # we *dont* however set events for the new type, because
            # alter_column is invoked from
            # Operations.implementation_for(alter_column) which already
            # will emit an add_constraint()

            existing_transfer["expr"] = cast(existing_transfer["expr"], type_)
        if nullable is not None:
            existing.nullable = nullable
        if server_default is not False:
            if server_default is None:
                existing.server_default = None
            else:
                sql_schema.DefaultClause(server_default)._set_parent(existing)
        if autoincrement is not None:
            existing.autoincrement = bool(autoincrement) 
開發者ID:jpush,項目名稱:jbox,代碼行數:46,代碼來源:batch.py

示例15: alter_column

# 需要導入模塊: from sqlalchemy import types [as 別名]
# 或者: from sqlalchemy.types import to_instance [as 別名]
def alter_column(
        self,
        table_name,
        column_name,
        nullable=None,
        server_default=False,
        name=None,
        type_=None,
        autoincrement=None,
        **kw
    ):
        existing = self.columns[column_name]
        existing_transfer = self.column_transfers[column_name]
        if name is not None and name != column_name:
            # note that we don't change '.key' - we keep referring
            # to the renamed column by its old key in _create().  neat!
            existing.name = name
            existing_transfer["name"] = name

        if type_ is not None:
            type_ = sqltypes.to_instance(type_)
            # old type is being discarded so turn off eventing
            # rules. Alternatively we can
            # erase the events set up by this type, but this is simpler.
            # we also ignore the drop_constraint that will come here from
            # Operations.implementation_for(alter_column)
            if isinstance(existing.type, SchemaEventTarget):
                existing.type._create_events = (
                    existing.type.create_constraint
                ) = False

            self.impl.cast_for_batch_migrate(
                existing, existing_transfer, type_
            )

            existing.type = type_

            # we *dont* however set events for the new type, because
            # alter_column is invoked from
            # Operations.implementation_for(alter_column) which already
            # will emit an add_constraint()

        if nullable is not None:
            existing.nullable = nullable
        if server_default is not False:
            if server_default is None:
                existing.server_default = None
            else:
                sql_schema.DefaultClause(server_default)._set_parent(existing)
        if autoincrement is not None:
            existing.autoincrement = bool(autoincrement) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:53,代碼來源:batch.py


注:本文中的sqlalchemy.types.to_instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。