當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。