• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python types.to_instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_varchar_raise

    def test_varchar_raise(self):
        for type_ in (
            String,
            VARCHAR,
            String(),
            VARCHAR(),
            NVARCHAR(),
            Unicode,
            Unicode(),
        ):
            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:23andMe,项目名称:sqlalchemy,代码行数:28,代码来源:test_compiler.py


示例2: alter_column

    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_)
            existing.type = type_
            existing_transfer["expr"] = cast(existing_transfer["expr"], type_)
        if nullable is not None:
            existing.nullable = nullable
        if server_default is not False:
            existing.server_default = server_default
        if autoincrement is not None:
            existing.autoincrement = bool(autoincrement)
开发者ID:I-am-Gabi,项目名称:AppAdmin,代码行数:26,代码来源:batch.py


示例3: __init__

    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:zzzeek,项目名称:alembic,代码行数:26,代码来源:mysql.py


示例4: __init__

 def __init__(self, type_=None, args=(), **kwargs):
     self.packagenames = []
     self.name = self.__class__.__name__
     self._bind = kwargs.get('bind', None)
     self.clause_expr = ClauseList(
             operator=operators.comma_op,
             group_contents=True, *args).self_group()
     self.type = sqltypes.to_instance(
         type_ or getattr(self, '__return_type__', None))
开发者ID:Am3s,项目名称:CouchPotatoServer,代码行数:9,代码来源:functions.py


示例5: __init__

 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:marcosptf,项目名称:fedora,代码行数:10,代码来源:base.py


示例6: alter_column

    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

            if existing.type._type_affinity is not type_._type_affinity:
                existing_transfer["expr"] = cast(
                    existing_transfer["expr"], 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:zzzeek,项目名称:alembic,代码行数:52,代码来源:batch.py


示例7: _visit_create_composite_type

def _visit_create_composite_type(create, compiler, **kw):
    type_ = create.element
    fields = ', '.join(
        '{name} {type}'.format(
            name=column.name,
            type=compiler.dialect.type_compiler.process(
                to_instance(column.type)
            )
        )
        for column in type_.columns
    )

    return 'CREATE TYPE {name} AS ({fields})'.format(
        name=compiler.preparer.format_type(type_),
        fields=fields
    )
开发者ID:dappiu,项目名称:sqlalchemy-utils,代码行数:16,代码来源:pg_composite.py


示例8: as_mutable

    def as_mutable(cls, sqltype):
        """Associate a SQL type with this mutable Python type.

        This establishes listeners that will detect ORM mappings against
        the given type, adding mutation event trackers to those mappings.

        The type is returned, unconditionally as an instance, so that
        :meth:`.as_mutable` can be used inline::

            Table('mytable', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', MyMutableType.as_mutable(PickleType))
            )

        Note that the returned type is always an instance, even if a class
        is given, and that only columns which are declared specifically with that
        type instance receive additional instrumentation.

        To associate a particular mutable type with all occurrences of a
        particular type, use the :meth:`.Mutable.associate_with` classmethod
        of the particular :meth:`.Mutable` subclass to establish a global
        association.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.as_mutable` for types that are permanent to an application,
           not with ad-hoc types else this will cause unbounded growth
           in memory usage.

        """
        sqltype = types.to_instance(sqltype)

        def listen_for_type(mapper, class_):
            for prop in mapper.iterate_properties:
                if hasattr(prop, 'columns'):
                    if prop.columns[0].type is sqltype:
                        cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type)

        return sqltype
开发者ID:ArcTanSusan,项目名称:ratings,代码行数:43,代码来源:mutable.py


示例9: as_mutable

    def as_mutable(cls, orig_sqltype):
        """Mark the value as nested mutable value.

        What happens here

        * We coerce the return value - the type value set on sqlalchemy.Column() to the underlying SQL typ

        * We mark this type value with a marker attribute

        * Then we set a global SQAlchemy mapper event handler

        * When mapper is done setting up our model classes, it will call the event handler for all models

        * We check if any of the models columns have our marked type value as the value

        * If so we call ``associate_with_attribute`` for this model and column that sets up ``MutableBase._listen_on_attribute`` event handlers. These event handlers take care of taking the raw dict coming out from database and wrapping it to NestedMutableDict.

        :param orig_sqltype: Usually websauna.system.model.column.JSONB instance
        :return: Marked and coerced type value
        """

        # Create an instance of this type and add a marker attribute,
        # so we later find it.
        # We cannot directly compare the result type values, as looks like
        # the type value might be mangled by dialect specific implementations
        # or lost somewhere. Never figured this out 100%.
        sqltype = types.to_instance(orig_sqltype)
        sqltype._column_value_id = id(sqltype)

        def listen_for_type(mapper, class_):
            for prop in mapper.column_attrs:
                # The original implementation has SQLAlchemy type comparator.
                # Here we need to be little more complex, because we define a type alias
                # for generic JSONB implementation
                if getattr(prop.columns[0].type, "_column_value_id", None) == sqltype._column_value_id:
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type)

        return sqltype
开发者ID:frispete,项目名称:websauna,代码行数:40,代码来源:json.py


示例10: _compile_ndb_string

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 = compat_utils.adapt_type_object(
            element, _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,代码行数:24,代码来源:ndb.py


示例11: __init__

    def __init__(self, base, field, type_):
        self.name = field
        self.type = to_instance(type_)

        super(CompositeElement, self).__init__(base)
开发者ID:dappiu,项目名称:sqlalchemy-utils,代码行数:5,代码来源:pg_composite.py


示例12: __init__

 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:spermspace,项目名称:microblog_flask0.12.2,代码行数:5,代码来源:postgresql.py


示例13: __init__

 def __init__(self, base, field, type_):
     ColumnElement.__init__(self)
     self.base = base
     self.field = field
     self.type = to_instance(type_)
开发者ID:extramental,项目名称:cerebro,代码行数:5,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python types.Enum类代码示例发布时间:2022-05-27
下一篇:
Python types.adapt_type函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap