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

Python declarative.DeclarativeMeta类代码示例

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

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



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

示例1: __init__

 def __init__(cls, classname, bases, dict_):
     DeclarativeMeta.__init__(cls, classname, bases, dict_)
     try:
         mapper = class_mapper(cls)
         _history_mapper(mapper)
     except UnmappedClassError:
         pass
开发者ID:loechel,项目名称:collective.saversioning,代码行数:7,代码来源:history_meta.py


示例2: __init__

    def __init__(self, name, bases, namespace):
        assert isinstance(namespace, dict), 'Invalid namespace %s' % namespace

        mappings, models = [], []
        for cls in bases:
            model = typeFor(cls)
            if isinstance(model, TypeModel):
                if isinstance(cls, MappedSupport):
                    if models:
                        raise MappingError('The mapped class %s needs to be placed before %s' % (cls, ','.join(mappings)))
                    mappings.append(model)
                else: models.append(model)

        if not models:
            assert log.debug('Cannot find any API model class for \'%s\', no merging required', name) or True
            DeclarativeMeta.__init__(self, name, bases, namespace)
            return

        if len(mappings) > 1:
            raise MappingError('Cannot inherit more then one mapped class, got %s' % ','.join(str(typ) for typ in mappings))
        if len(models) > 1:
            raise MappingError('Cannot merge with more then one API model class, got %s' % ','.join(str(typ) for typ in models))

        model = models[0]
        assert isinstance(model, TypeModel)
        self._ally_type = model  # Provides the TypeSupport
        self._ally_reference = {name: Reference(prop) for name, prop in model.properties.items()}
        self._ally_listeners = {}  # Provides the BindableSupport

        DeclarativeMeta.__init__(self, name, bases, namespace)

        try: mappings = self.metadata._ally_mappers
        except AttributeError: mappings = self.metadata._ally_mappers = []
        mappings.append(self)
开发者ID:cristidomsa,项目名称:Ally-Py,代码行数:34,代码来源:mapper.py


示例3: __init__

    def __init__(self, name, bases, d):
        DeclarativeMeta.__init__(self, name, bases, d)

        try:
            bind_key = d.pop('__bind_key__', DEFAULT_BIND_KEY)
            self.__table__.info['bind_key'] = bind_key
        except AttributeError:
            pass
开发者ID:FI-Mihej,项目名称:seismograph,代码行数:8,代码来源:orm.py


示例4: __init__

    def __init__(cls, name, bases, dct):
        DeclarativeMeta.__init__(cls, name, bases, dct)

        if hasattr(cls, '__table__'):
            if '__bind_key__' in dct:
                cls.__table__.info['bind_key'] = dct['__bind_key__']

            events.register(cls, dct)
开发者ID:LeoKudrik,项目名称:alchy,代码行数:8,代码来源:model.py


示例5: __init__

    def __init__(cls, name, bases, attrs):
        """Handle Flask-SQLAlchemy's bind_key without setting tablename."""

        bind_key = attrs.pop('__bind_key__', None)
        BaseDeclarativeMeta.__init__(cls, name, bases, attrs)

        if bind_key is not None:
            cls.__table__.info['bind_key'] = bind_key
开发者ID:NotTheEconomist,项目名称:sopython-site,代码行数:8,代码来源:sqlalchemy.py


示例6: __init__

 def __init__(self, name, bases, d):
     bind_key = d.pop('__bind_key__', None)
     if bind_key not in self._metadata:
         self._metadata[bind_key] = MetaData()
     self.metadata = self._metadata[bind_key]
     DeclarativeMeta.__init__(self, name, bases, d)
     if bind_key is not None:
         self.__table__.info['bind_key'] = bind_key
开发者ID:Kazanz,项目名称:flask-sqlalchemy,代码行数:8,代码来源:__init__.py


示例7: __init__

 def __init__(cls, names, bases, dict_):
     DeclarativeMeta.__init__(cls, names, bases, dict_)
     if not hasattr(cls, "_obj_classes"):
         # This will be set in the 'DomainObject' class.
         cls._obj_classes = collections.defaultdict(list)
     else:
         # Add the subclass to DomainObject._obj_classes
         base.make_class_properties(cls)
         cls._obj_classes[cls.obj_name()].append(cls)
开发者ID:smarterclayton,项目名称:solum,代码行数:9,代码来源:models.py


示例8: __init__

    def __init__(cls, name, bases, dct):
        bind_key = dct.pop('__bind_key__', None)

        DeclarativeMeta.__init__(cls, name, bases, dct)

        if bind_key is not None:
            cls.__table__.info['bind_key'] = bind_key

        events.register(cls, dct)
开发者ID:genba,项目名称:alchy,代码行数:9,代码来源:model.py


示例9: __init__

 def __init__(mcs, classname, bases, dict_):
     """
     Permet l'ajout automatique du préfixe aux tables
     du modèle, lorsque celles-ci sont définies
     en utilisant le mode "Declarative" de SQLAlchemy.
     """
     if '__tablename__' in dict_:
         mcs.__tablename__ = dict_['__tablename__'] = \
             configure.DB_BASENAME + dict_['__tablename__']
     DeclarativeMeta.__init__(mcs, classname, bases, dict_)
开发者ID:vigilo,项目名称:models,代码行数:10,代码来源:session.py


示例10: sql_model

 def sql_model(self, model):
     sql_model = getattr(model, '_sql_model', None)
     if not sql_model:
         meta = model._meta
         fields = {'__tablename__': meta.table_name}
         for field in model._meta.dfields.values():
             fields[field.store_name] = field.sql_alchemy_column()
         sql_model = DeclarativeMeta(meta.name, (Base,), fields)
         model._sql_model = sql_model
         sql_model._meta = meta
     return sql_model
开发者ID:JinsongBian,项目名称:pulsar,代码行数:11,代码来源:base.py


示例11: __init__

 def __init__(self, name, bases, d):
     route_key = d.pop('__route_key__', None)
     shard_key = d.pop('__shard_key__', None)
     shard_lookup = d.pop('__shard_lookup__', None)
     DeclarativeMeta.__init__(self, name, bases, d)
     if route_key is not None:
         self.__table__.info['route_key'] = route_key
     if shard_key is not None:
         self.__table__.info['shard_key'] = shard_key
     if shard_lookup is not None:
         self.__table__.info['shard_lookup'] = shard_lookup
开发者ID:smiledaddy,项目名称:Crystal,代码行数:11,代码来源:mysql.py


示例12: __init__

    def __init__(self, name, bases, namespace):
        assert isinstance(namespace, dict), "Invalid namespace %s" % namespace

        mapped, models = [], []
        for cls in bases:
            typ = typeFor(cls)
            if isinstance(typ, TypeModelMapped):
                mapped.append(cls)
            elif isinstance(typ, TypeModel):
                models.append(cls)

        if not mapped and not models:
            assert log.debug("Cannot find any API model class for '%s', no merging required", name) or True
            DeclarativeMeta.__init__(self, name, bases, namespace)
            return

        if len(mapped) > 1:
            raise MappingError("Cannot inherit more then one mapped class, got %s" % models)

        if len(models) > 1:
            raise MappingError("Cannot merge with more then one API model class, got %s" % models)

        if models:
            typeModel = typeFor(models[0])
        else:
            typeModel = None
        if mapped:
            if typeModel is None:
                typeModel = typeFor(mapped[0]).base
        assert isinstance(typeModel, TypeModel)
        typeModel = TypeModelMapped(self, typeModel)

        self._ally_reference = {
            prop: Reference(TypeModelProperty(typeModel, prop, propType))
            for prop, propType in typeModel.container.properties.items()
        }
        self._ally_listeners = {}  # Provides the BindableSupport
        self._ally_type = typeModel  # Provides the TypeSupport

        DeclarativeMeta.__init__(self, name, bases, namespace)

        # TODO: see if required: self.__clause_element__ = lambda: self.__table__

        for prop in typeModel.container.properties:
            if typeFor(getattr(self, prop)) != typeFor(self._ally_reference[prop]):
                value, _class = getAttrAndClass(self, prop)
                setattr(self, prop, value)

        try:
            mappings = self.metadata._ally_mappers
        except AttributeError:
            mappings = self.metadata._ally_mappers = deque()
        mappings.append(self)
开发者ID:adityaathalye,项目名称:Ally-Py,代码行数:53,代码来源:mapper.py


示例13: __init__

 def __init__(self, name, bases, d):
     DeclarativeMeta.__init__(self, name, bases, d)
     if not hasattr(self, '__table__'):
         return
     distribution_method = d.pop('__distribution_method__', None)
     distribution_column = (
         d.pop('__distribute_by__', None) or
         getattr(self, '__bind_key__', None)
     )
     colocated_table = d.pop('__colocate_with__', None)
     if distribution_method is not None:
         self.__table__.info['is_distributed'] = True
         self.__table__.info['distribution_method'] = distribution_method
         if distribution_method in {'range', 'hash'}:
             if distribution_column is None:
                 raise ValueError(
                     'Table "%s" is distributed by "%s" and must therefore '
                     'provide a distribution column via "__distribute_by__".'
                     % (self.__table__.name, distribution_method)
                 )
             column_type = self.__table__.c[distribution_column].type
             if not isinstance(column_type, sqlalchemy.types.Integer):
                 raise TypeError(
                     'Distribution column "%s" of table "%s" must have type '
                     '"%s" for distribtion method "%s"' % (
                         distribution_column, self.__table__.name,
                         sqlalchemy.types.Integer.__name__,
                         table.info['distribution_method']
                     )
                 )
             columns = self.__table__.c
             if distribution_column not in columns:
                 raise ValueError(
                     'Specified distribution column "%s" '
                     'is not a column of table "%s".'
                     % (distribution_column, self.__table__.name)
                 )
             self.__table__.info['distribute_by'] = distribution_column
             self.__table__.info['colocate_with'] = colocated_table
         elif distribution_method == 'replication':
             self.__table__.info['distribute_by'] = None
             self.__table__.info['colocate_with'] = None
         else:
             raise ValueError(
                 'Table "%s" specified an unsupported distribution method. '
                 'Supported are: "range", "hash" and "replication".'
                 % self.__table__.name
             )
     else:
         self.__table__.info['is_distributed'] = False
开发者ID:dvischi,项目名称:TissueMAPS,代码行数:50,代码来源:base.py


示例14: __new__

 def __new__(cls, classname, bases, dict_):
     tablename = dict_.get('__tablename__')
     if not tablename and not dict_.get('__table__') \
        and _DeclarativeMeta.has_primary_key(dict_):
         dict_['__tablename__'] = strings.pluralize(
             strings.snakecase(classname))
     return DeclarativeMeta.__new__(cls, classname, bases, dict_)
开发者ID:watsonpy,项目名称:watson-db,代码行数:7,代码来源:meta.py


示例15: save_instances

async def save_instances(
        instances: Iterable[DeclarativeMeta], *,
        cls: DeclarativeMeta,
        connection: ConnectionType,
        is_mysql: bool) -> List[int]:
    columns_names = list(cls.columns_fields_names())
    primary_key = await get_primary_key(table=cls.__table__)
    primary_key_column_index = columns_names.index(primary_key)
    columns_names.pop(primary_key_column_index)
    unique_columns_names = await get_unique_columns_names(cls.__table__)
    returning_columns_names = [primary_key]

    def record_without_id(instance: DeclarativeMeta
                          ) -> RecordType:
        res = list(instance.record)
        res.pop(primary_key_column_index)
        return tuple(res)

    records = map(record_without_id, instances)
    resp = await insert_returning(
        table_name=cls.__tablename__,
        columns_names=columns_names,
        unique_columns_names=unique_columns_names,
        returning_columns_names=returning_columns_names,
        records=records,
        merge=True,
        connection=connection,
        is_mysql=is_mysql)
    return [row[0] for row in resp]
开发者ID:lycantropos,项目名称:RecommendSystem,代码行数:29,代码来源:films.py


示例16: __new__

    def __new__(cls, name, bases, d):
        # if tablename is set explicitly, move it to the cache attribute so
        # that future subclasses still have auto behavior
        if '__tablename__' in d:
            d['_cached_tablename'] = d.pop('__tablename__')

        return DeclarativeMeta.__new__(cls, name, bases, d)
开发者ID:tanny2015,项目名称:Blog_Flask,代码行数:7,代码来源:__init__.py


示例17: __new__

    def __new__(cls, cls_name, cls_bases, cls_dict):
        if cls_dict.get("__type_name__", None) is None:
            cls_dict["__type_name__"] = cls_name

        if cls_dict.get("_type_info", None) is None:
            cls_dict["_type_info"] = _type_info = TypeInfo()

            for k, v in cls_dict.items():
                if (not k.startswith('__')) and isinstance(v, Column):
                    _type_info[k] = _process_item(v)

            table = cls_dict.get('__table__', None)
            if not (table is None):
                for c in table.c:
                    _type_info[c.name] = _process_item(c)

            # mixin inheritance
            for b in cls_bases:
                for k,v in vars(b).items():
                    if isinstance(v, Column):
                        _type_info[k] = _process_item(v)

            # same table inheritance
            for b in cls_bases:
                table = getattr(b, '__table__', None)

                if not (table is None):
                    for c in table.c:
                        _type_info[c.name] = _process_item(c)

        return DeclarativeMeta.__new__(cls, cls_name, cls_bases, cls_dict)
开发者ID:antoinehumbert,项目名称:rpclib,代码行数:31,代码来源:table.py


示例18: __new__

    def __new__(mcs, name, bases, dct):
        # Set __events__ to expected default so that it's updatable when
        # initializing. E.g. if class definition sets __events__=None but
        # defines decorated events, then we want the final __events__ attribute
        # to reflect the registered events. If set to anything that's
        # non-empty/non-dict will lead to an error if decorated events defined.
        if not dct.get('__events__'):
            dct['__events__'] = {}

        if '__bind_key__' not in dct:
            base_dcts = [dct] + [base.__dict__ for base in bases]
            for base in base_dcts:
                if '__bind_key__' in base:
                    dct['__bind_key__'] = base['__bind_key__']
                    break

        cls = DeclarativeMeta.__new__(mcs, name, bases, dct)

        # Determine if should set __tablename__.
        # This is being done after DeclarativeMeta.__new__()
        # as the class is needed to accommodate @declared_attr columns.
        if should_set_tablename(cls):
            # Set to underscore version of class name.
            cls.__tablename__ = camelcase_to_underscore(name)

        return cls
开发者ID:LeoKudrik,项目名称:alchy,代码行数:26,代码来源:model.py


示例19: __new__

    def __new__(cls, cls_name, cls_bases, cls_dict):
        if cls_dict.get("__type_name__", None) is None:
            cls_dict["__type_name__"] = cls_name

        if cls_dict.get("_type_info", None) is None:
            cls_dict["_type_info"] = _type_info = TypeInfo()

            # mixin inheritance
            for b in cls_bases:
                for k,v in vars(b).items():
                    if _is_interesting(k,v):
                        _type_info[k] = _process_item(v)

            # same table inheritance
            for b in cls_bases:
                table = getattr(b, '__table__', None)

                if not (table is None):
                    for c in table.c:
                        _type_info[c.name] = _process_item(c)

            # include from table
            table = cls_dict.get('__table__', None)
            if not (table is None):
                for c in table.c:
                    _type_info[c.name] = _process_item(c)

            # own attributes
            for k, v in cls_dict.items():
                if _is_interesting(k,v):
                    _type_info[k] = _process_item(v)

        return DeclarativeMeta.__new__(cls, cls_name, cls_bases, cls_dict)
开发者ID:cloudappsetup,项目名称:rpclib,代码行数:33,代码来源:table.py


示例20: __new__

    def __new__(cls, cls_name, cls_bases, cls_dict):
        if cls_dict.get("__type_name__", None) is None:
            cls_dict["__type_name__"] = cls_name

        if cls_dict.get("_type_info", None) is None:
            parse_cls_dict(cls_dict)

        return DeclarativeMeta.__new__(cls, cls_name, cls_bases, cls_dict)
开发者ID:PArun,项目名称:soaplib,代码行数:8,代码来源:table.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python api.declarative_base函数代码示例发布时间:2022-05-27
下一篇:
Python declarative.declarative_base函数代码示例发布时间: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