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


Python inspection.inspect方法代码示例

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


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

示例1: _get_model_pks

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def _get_model_pks(model) -> 'Tuple[str, ...]':
        """
        Get primary key field name.

        Args:
            model: SQLAlchemy model.

        Returns:
            Field name.

        """
        model_pk_fields: 'Tuple[str]' = tuple(
            (
                cast(str, name)
                for name, c in inspection.inspect(model).columns.items()
                if c.primary_key
            )
        )
        return model_pk_fields 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:21,代码来源:connection_field.py

示例2: _db_row_to_dict

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def _db_row_to_dict(row, remove_columns=False):
    """Converts a DB object to a dictionary."""

    from sqlalchemy.inspection import inspect as sa_inspect
    from sqlalchemy.ext.hybrid import hybrid_property

    row_dict = collections.OrderedDict()

    columns = row.__table__.columns.keys()

    mapper = sa_inspect(row.__class__)
    for key, item in mapper.all_orm_descriptors.items():

        if isinstance(item, hybrid_property):
            columns.append(key)

    for col in columns:
        if remove_columns and col in remove_columns:
            continue
        row_dict[col] = getattr(row, col)

    return row_dict 
开发者ID:sdss,项目名称:marvin,代码行数:24,代码来源:general.py

示例3: _loadParams

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

示例4: sqlalchemy_to_pydantic

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def sqlalchemy_to_pydantic(
    db_model: Type, *, exclude: Container[str] = []
) -> Type[BaseModel]:
    """
    Mostly copied from https://github.com/tiangolo/pydantic-sqlalchemy
    """
    mapper = inspect(db_model)
    fields = {}
    for attr in mapper.attrs:
        if isinstance(attr, ColumnProperty):
            if attr.columns:
                column = attr.columns[0]
                python_type = column.type.python_type
                name = attr.key
                if name in exclude:
                    continue
                default = None
                if column.default is None and not column.nullable:
                    default = ...
                fields[name] = (python_type, default)
    pydantic_model = create_model(
        db_model.__name__, **fields  # type: ignore
    )
    return pydantic_model 
开发者ID:CTFd,项目名称:CTFd,代码行数:26,代码来源:schemas.py

示例5: test_pep435_custom_sort_key

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def test_pep435_custom_sort_key(self):
        s = Session()

        a = self.classes.T3(id=self.three, value=1)
        b = self.classes.T3(id=self.four, value=2)
        s.add_all([a, b])
        s.commit()

        c = self.classes.T3(id=self.five, value=0)
        s.add(c)

        states = [o._sa_instance_state for o in [b, a, c]]
        eq_(
            _sort_states(inspect(self.classes.T3), states),
            # pending come first, then "four" < "three"
            [o._sa_instance_state for o in [c, b, a]],
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_unitofwork.py

示例6: _serialize

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def _serialize(self, value, attr, obj, **kwargs):
        return inspect(value).identity 
开发者ID:ewels,项目名称:MegaQC,代码行数:4,代码来源:fields.py

示例7: serialize

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def serialize(self, obj_type=None, relations=False):
        attrs = inspect(self).attrs.keys()
        obj_dict = {
            attr: serialize_value(getattr(self, attr)) for attr in attrs
        }
        obj_dict["notification_type"] = obj_dict["type"]
        obj_dict["type"] = obj_type or type(self).__name__
        return obj_dict 
开发者ID:cgwire,项目名称:zou,代码行数:10,代码来源:notification.py

示例8: serialize

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def serialize(self, obj_type=None, relations=False):
        attrs = inspect(self).attrs.keys()
        if relations:
            obj_dict = {
                attr: serialize_value(getattr(self, attr)) for attr in attrs
            }
        else:
            obj_dict = {
                attr: serialize_value(getattr(self, attr))
                for attr in attrs
                if not self.is_join(attr)
            }
        obj_dict["type"] = obj_type or type(self).__name__
        return obj_dict 
开发者ID:cgwire,项目名称:zou,代码行数:16,代码来源:serializer.py

示例9: create

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def create(cls, **kwargs):
        instance = cls(**kwargs)
        # Populate all the unspecified columns with their defaults
        for key, column in inspect(cls).columns.items():
            if key not in kwargs and column.default is not None:
                arg = column.default.arg
                column_default = arg if callable(arg) else lambda: arg
                setattr(instance, key, column_default(instance))
        return instance 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:11,代码来源:model_base.py

示例10: delete

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def delete(self, db_session=None):
        db = db_session or inspect(self).session
        db.delete(self) 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:5,代码来源:model_base.py

示例11: fields

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def fields(self):
        model = self.index.model
        schema_fields = self._fields()
        primary_keys = [key.name for key in inspect(model).primary_key]

        schema = getattr(model, "__msearch_schema__", dict())
        for field in self.index.searchable:
            if '.' in field:
                fields = field.split('.')
                field_attr = getattr(
                    getattr(model, fields[0]).property.mapper.class_,
                    fields[1])
            else:
                field_attr = getattr(model, field)

            if field in schema:
                field_type = schema[field]
                if isinstance(field_type, str):
                    schema_fields[field] = self.fields_map(field_type)
                else:
                    schema_fields[field] = field_type
                continue

            if hasattr(field_attr, 'descriptor') and isinstance(
                    field_attr.descriptor, hybrid_property):
                schema_fields[field] = self.fields_map("text")
                continue

            if field in primary_keys:
                schema_fields[field] = self.fields_map("primary")
                continue

            field_type = field_attr.property.columns[0].type
            schema_fields[field] = self.fields_map(field_type)
        return schema_fields 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:37,代码来源:backends.py

示例12: __getattr__

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def __getattr__(cls, item):
        if item == "__table__":
            return inspect(cls).local_table
        raise AttributeError(item) 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:6,代码来源:model.py

示例13: has_sqlalchemy_fields

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def has_sqlalchemy_fields(base):
    for p in base.__dict__.keys():
        attr = base.__dict__[p]
        if inspection.inspect(attr, raiseerr=False) is not None:
            return True

    return False 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:9,代码来源:__init__.py

示例14: get_parent_value

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def get_parent_value(instance):
        return inspection.inspect(instance).attrs.parent.loaded_value 
开发者ID:uralbash,项目名称:sqlalchemy_mptt,代码行数:4,代码来源:events.py

示例15: to_dict

# 需要导入模块: from sqlalchemy import inspection [as 别名]
# 或者: from sqlalchemy.inspection import inspect [as 别名]
def to_dict(self):
        return {c.key: getattr(self, c.key)
                for c in inspect(self).mapper.column_attrs} 
开发者ID:sodafoundation,项目名称:orchestration,代码行数:5,代码来源:models.py


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