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


Python attributes.InstrumentedAttribute方法代码示例

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


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

示例1: with_joined

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def with_joined(cls, *paths):
        """
        Eagerload for simple cases where we need to just
         joined load some relations
        In strings syntax, you can split relations with dot 
         due to this SQLAlchemy feature: https://goo.gl/yM2DLX
         
        :type paths: *List[str] | *List[InstrumentedAttribute]

        Example 1:
            Comment.with_joined('user', 'post', 'post.comments').first()

        Example 2:
            Comment.with_joined(Comment.user, Comment.post).first()
        """
        options = [joinedload(path) for path in paths]
        return cls.query.options(*options) 
开发者ID:absent1706,项目名称:sqlalchemy-mixins,代码行数:19,代码来源:eagerload.py

示例2: with_subquery

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def with_subquery(cls, *paths):
        """
        Eagerload for simple cases where we need to just
         joined load some relations
        In strings syntax, you can split relations with dot 
         (it's SQLAlchemy feature)

        :type paths: *List[str] | *List[InstrumentedAttribute]

        Example 1:
            User.with_subquery('posts', 'posts.comments').all()

        Example 2:
            User.with_subquery(User.posts, User.comments).all()
        """
        options = [subqueryload(path) for path in paths]
        return cls.query.options(*options) 
开发者ID:absent1706,项目名称:sqlalchemy-mixins,代码行数:19,代码来源:eagerload.py

示例3: get_descriptor_columns

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def get_descriptor_columns(model, descriptor):
    if isinstance(descriptor, InstrumentedAttribute):
        return descriptor.property.columns
    elif isinstance(descriptor, sa.orm.ColumnProperty):
        return descriptor.columns
    elif isinstance(descriptor, sa.Column):
        return [descriptor]
    elif isinstance(descriptor, sa.sql.expression.ClauseElement):
        return []
    elif isinstance(descriptor, sa.ext.hybrid.hybrid_property):
        expr = descriptor.expr(model)
        try:
            return get_descriptor_columns(model, expr)
        except TypeError:
            return []
    elif (
        isinstance(descriptor, QueryableAttribute) and
        hasattr(descriptor, 'original_property')
    ):
        return get_descriptor_columns(model, descriptor.property)
    raise TypeError(
        'Given descriptor is not of type InstrumentedAttribute, '
        'ColumnProperty or Column.'
    ) 
开发者ID:kvesteri,项目名称:sqlalchemy-json-api,代码行数:26,代码来源:utils.py

示例4: _loadParams

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def _loadParams(self, newclass):
        ''' Loads all parameters from wtforms into a dictionary with
            key, value = {'parameter_name': 'parent WTForm name'}.
            Ignores hidden attributes and the Meta class
        '''

        model = newclass.Meta.model
        schema = model.__table__.schema
        tablename = model.__table__.name

        mapper = sa_inspect(model)
        for key, item in mapper.all_orm_descriptors.items():
            if isinstance(item, (hybrid_property, hybrid_method)):
                key = key
            elif isinstance(item, InstrumentedAttribute):
                key = item.key
            else:
                continue

            lookupKeyName = schema + '.' + tablename + '.' + key
            self._param_form_lookup[lookupKeyName] = newclass
            self._paramtree[newclass.Meta.model.__name__][key] 
开发者ID:sdss,项目名称:marvin,代码行数:24,代码来源:forms.py

示例5: _flatten_schema

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def _flatten_schema(schema):
    """
    :type schema: dict
    """
    def _flatten(schema, parent_path, result):
        """
        :type schema: dict
        """
        for path, value in schema.items():
            # for supporting schemas like Product.user: {...},
            # we transform, say, Product.user to 'user' string
            if isinstance(path, InstrumentedAttribute):
                path = path.key

            if isinstance(value, tuple):
                join_method, inner_schema = value[0], value[1]
            elif isinstance(value, dict):
                join_method, inner_schema = JOINED, value
            else:
                join_method, inner_schema = value, None

            full_path = parent_path + '.' + path if parent_path else path
            result[full_path] = join_method

            if inner_schema:
                _flatten(inner_schema, full_path, result)

    result = {}
    _flatten(schema, '', result)
    return result 
开发者ID:absent1706,项目名称:sqlalchemy-mixins,代码行数:32,代码来源:eagerload.py

示例6: is_relationship_descriptor

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def is_relationship_descriptor(self, descriptor):
        return (
            isinstance(descriptor, InstrumentedAttribute) and
            isinstance(descriptor.property, sa.orm.RelationshipProperty)
        ) 
开发者ID:kvesteri,项目名称:sqlalchemy-json-api,代码行数:7,代码来源:query_builder.py

示例7: _are_valid_query_entities

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def _are_valid_query_entities(self, func_name, entities):
        from sqlalchemy.orm.attributes import InstrumentedAttribute
        for e in entities:
            if not isinstance(e, InstrumentedAttribute):
                raise RQInvalidArgument(
                    _("function {}: invalid {} argument, should be entity like "
                      "Fundamentals.balance_sheet.total_equity, got {} (type: {})").format(
                        func_name, self.arg_name, e, type(e)
                    )) 
开发者ID:zhengwsh,项目名称:InplusTrader_Linux,代码行数:11,代码来源:arg_checker.py

示例8: _are_valid_query_entities

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def _are_valid_query_entities(self, func_name, entities):
        from sqlalchemy.orm.attributes import InstrumentedAttribute
        for e in entities:
            if not isinstance(e, InstrumentedAttribute):
                raise RQInvalidArgument(
                    _(u"function {}: invalid {} argument, should be entity like "
                      u"Fundamentals.balance_sheet.total_equity, got {} (type: {})").format(
                        func_name, self.arg_name, e, type(e)
                    )) 
开发者ID:zhengwsh,项目名称:InplusTrader_Linux,代码行数:11,代码来源:arg_checker.py

示例9: filter_timestamp_column_by_day_of_week

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def filter_timestamp_column_by_day_of_week(
        self, ts_col: InstrumentedAttribute
    ) -> ColumnElement:
        """
        Returns an expression equivalent to TRUE (because no additional
        filtering is needed to limit the day of the week).

        Parameters
        ----------
        ts_col : sqlalchemy.orm.attributes.InstrumentedAttribute
            The timestamp column to filter. Note that this input argument
            is ignored for the DayPeriod class because it requires no
            additional filtering to limit the day of the week.
        """
        return true() 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:17,代码来源:hour_slice.py

示例10: _sub_operator

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import InstrumentedAttribute [as 别名]
def _sub_operator(model, argument, fieldname):
    """Recursively calls :func:`QueryBuilder._create_operation` when argument
    is a dictionary of the form specified in :ref:`search`.

    This function is for use with the ``has`` and ``any`` search operations.

    """
    if isinstance(model, InstrumentedAttribute):
        submodel = model.property.mapper.class_
    elif isinstance(model, AssociationProxy):
        submodel = get_related_association_proxy_model(model)
    else:  # TODO what to do here?
        pass
    if isinstance(argument, dict):
        fieldname = argument['name']
        operator = argument['op']
        argument = argument.get('val')
        relation = None
        if '__' in fieldname:
            fieldname, relation = fieldname.split('__')
        return QueryBuilder._create_operation(submodel, fieldname, operator,
                                              argument, relation)
    # Support legacy has/any with implicit eq operator
    return getattr(submodel, fieldname) == argument


#: The mapping from operator name (as accepted by the search method) to a
#: function which returns the SQLAlchemy expression corresponding to that
#: operator.
#:
#: Each of these functions accepts either one, two, or three arguments. The
#: first argument is the field object on which to apply the operator. The
#: second argument, where it exists, is either the second argument to the
#: operator or a dictionary as described below. The third argument, where it
#: exists, is the name of the field.
#:
#: For functions that accept three arguments, the second argument may be a
#: dictionary containing ``'name'``, ``'op'``, and ``'val'`` mappings so that
#: :func:`QueryBuilder._create_operation` may be applied recursively. For more
#: information and examples, see :ref:`search`.
#:
#: Some operations have multiple names. For example, the equality operation can
#: be described by the strings ``'=='``, ``'eq'``, ``'equals'``, etc. 
开发者ID:yfauser,项目名称:planespotter,代码行数:45,代码来源:search.py


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