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


Python attributes.QueryableAttribute方法代码示例

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


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

示例1: get_descriptor_columns

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import QueryableAttribute [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

示例2: to_json

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import QueryableAttribute [as 别名]
def to_json(self):
        """Exports the object to a JSON friendly dict

        Returns:
             Dict representation of object type
        """
        output = {
            '__type': self.__class__.__name__
        }

        cls_attribs = self.__class__.__dict__
        for attrName in cls_attribs:
            attr = getattr(self.__class__, attrName)
            value = getattr(self, attrName)
            value_class = type(value)

            if issubclass(type(attr), QueryableAttribute):
                # List of Model, BaseModelMixin objects (one-to-many relationship)
                if issubclass(value_class, InstrumentedList):
                    output[to_camelcase(attrName)] = [x.to_json() for x in value]

                # Model, BaseModelMixin object (one-to-one relationship)
                elif issubclass(value_class, Model):
                    output[to_camelcase(attrName)] = value.to_json()

                # Datetime object
                elif isinstance(value, datetime):
                    output[to_camelcase(attrName)] = isoformat(value)

                elif isinstance(value, enum.Enum):
                    output[to_camelcase(attrName)] = value.name

                # Any primitive type
                else:
                    output[to_camelcase(attrName)] = value

        return output 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:39,代码来源:base.py

示例3: primary_key_names

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import QueryableAttribute [as 别名]
def primary_key_names(model):
    """Returns all the primary keys for a model."""
    return [key for key, field in inspect.getmembers(model)
            if isinstance(field, QueryableAttribute)
            and isinstance(field.property, ColumnProperty)
            and field.property.columns[0].primary_key] 
开发者ID:yfauser,项目名称:planespotter,代码行数:8,代码来源:helpers.py

示例4: apply_nested_fields

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import QueryableAttribute [as 别名]
def apply_nested_fields(self, data, obj):
        nested_fields_to_apply = []
        nested_fields = get_nested_fields(self.resource.schema, model_field=True)
        for key, value in data.items():
            if key in nested_fields:
                nested_field_inspection = inspect(getattr(obj.__class__, key))

                if not isinstance(nested_field_inspection, QueryableAttribute):
                    raise InvalidType("Unrecognized nested field type: not a queryable attribute.")

                if isinstance(nested_field_inspection.property, RelationshipProperty):
                    nested_model = getattr(obj.__class__, key).property.mapper.class_

                    if isinstance(value, list):
                        nested_objects = []

                        for identifier in value:
                            nested_object = nested_model(**identifier)
                            nested_objects.append(nested_object)

                        nested_fields_to_apply.append({'field': key, 'value': nested_objects})
                    else:
                        nested_fields_to_apply.append({'field': key, 'value': nested_model(**value)})
                elif isinstance(nested_field_inspection.property, ColumnProperty):
                    nested_fields_to_apply.append({'field': key, 'value': value})
                else:
                    raise InvalidType("Unrecognized nested field type: not a RelationshipProperty or ColumnProperty.")

        for nested_field in nested_fields_to_apply:
            setattr(obj, nested_field['field'], nested_field['value']) 
开发者ID:miLibris,项目名称:flask-rest-jsonapi,代码行数:32,代码来源:alchemy.py

示例5: derive_order_key

# 需要导入模块: from sqlalchemy.orm import attributes [as 别名]
# 或者: from sqlalchemy.orm.attributes import QueryableAttribute [as 别名]
def derive_order_key(ocol, desc, index):
    """Attempt to derive the value of `ocol` from a query column.

    :param ocol: The :class:`OC` to look up.
    :param desc: Either a column description as in
        :attr:`sqlalchemy.orm.query.Query.column_descriptions`, or a
        :class:`sqlalchemy.sql.expression.ColumnElement`.

    :returns: Either a :class:`MappedOrderColumn` or `None`."""
    if isinstance(desc, ColumnElement):
        if desc.compare(ocol.comparable_value):
            return DirectColumn(ocol, index)
        else:
            return None

    entity = desc['entity']
    expr = desc['expr']

    if isinstance(expr, Bundle):
        for key, col in expr.columns.items():
            if strip_labels(col).compare(ocol.comparable_value):
                return AttributeColumn(ocol, index, key)

    try:
        is_a_table = bool(entity == expr)
    except (sqlalchemy.exc.ArgumentError, TypeError):
        is_a_table = False

    if isinstance(expr, Mapper) and expr.class_ == entity:
        is_a_table = True

    if is_a_table:  # is a table
        mapper = class_mapper(desc['type'])
        try:
            prop = mapper.get_property_by_column(ocol.element)
            return AttributeColumn(ocol, index, prop.key)
        except sqlalchemy.orm.exc.UnmappedColumnError:
            pass

    # is an attribute
    if isinstance(expr, QueryableAttribute):
        mapper = expr.parent
        tname = mapper.local_table.description
        if ocol.table_name == tname and ocol.name == expr.name:
            return DirectColumn(ocol, index)

    # is an attribute with label
    try:
        if ocol.quoted_full_name == OC(expr).full_name:
            return DirectColumn(ocol, index)
    except sqlalchemy.exc.ArgumentError:
        pass 
开发者ID:djrobstep,项目名称:sqlakeyset,代码行数:54,代码来源:columns.py


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