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

Python sqlalchemy_continuum.version_class函数代码示例

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

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



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

示例1: setup_method

    def setup_method(self, method):
        self.Model = declarative_base()
        make_versioned(options=self.options)

        driver = os.environ.get('DB', 'sqlite')
        driver = get_driver_name(driver)
        versioning_manager.plugins = self.plugins
        versioning_manager.transaction_cls = self.transaction_cls
        versioning_manager.user_cls = self.user_cls

        self.engine = create_engine(get_dns_from_driver(driver))
        # self.engine.echo = True
        self.connection = self.engine.connect()

        self.create_models()

        sa.orm.configure_mappers()

        if hasattr(self, 'Article'):
            self.ArticleVersion = version_class(self.Article)
        if hasattr(self, 'Tag'):
            try:
                self.TagVersion = version_class(self.Tag)
            except ClassNotVersioned:
                pass
        self.create_tables()

        Session = sessionmaker(bind=self.connection)
        self.session = Session(autoflush=False)
开发者ID:wkiser,项目名称:sqlalchemy-continuum,代码行数:29,代码来源:__init__.py


示例2: test_sa_inheritance_with_no_distinct_table_has_right_translation_class

 def test_sa_inheritance_with_no_distinct_table_has_right_translation_class(self):
     class_ = version_class(self.BaseModel)
     assert class_.__name__ == 'BaseModelVersion'
     assert class_.__table__.name == 'base_model_version'
     class_ = version_class(self.FirstLevel)
     assert class_.__name__ == 'FirstLevelVersion'
     assert class_.__table__.name == 'first_level_version'
     class_ = version_class(self.SecondLevel)
     assert class_.__name__ == 'SecondLevelVersion'
     assert class_.__table__.name == 'first_level_version'
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:10,代码来源:test_multi_level_inheritance.py


示例3: test_versioned_table_structure

 def test_versioned_table_structure(self):
     table = version_class(self.Article).__table__
     assert 'id' in table.c
     assert 'name' in table.c
     assert 'content' in table.c
     assert 'description'in table.c
     assert 'transaction_id' in table.c
     assert 'operation_type' in table.c
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:8,代码来源:test_table_builder.py


示例4: test_something

    def test_something(self):
        table = version_class(self.Article).__table__
        self._insert(
            {
                'id': 1,
                'transaction_id': 1,
                'name': u'Article 1',
                'operation_type': 1,
            }
        )
        self._insert(
            {
                'id': 1,
                'transaction_id': 2,
                'name': u'Article 1 updated',
                'operation_type': 2,
            }
        )
        self._insert(
            {
                'id': 2,
                'transaction_id': 3,
                'name': u'Article 2',
                'operation_type': 1,
            }
        )
        self._insert(
            {
                'id': 1,
                'transaction_id': 4,
                'name': u'Article 1 updated (again)',
                'operation_type': 2,
            }
        )
        self._insert(
            {
                'id': 2,
                'transaction_id': 5,
                'name': u'Article 2 updated',
                'operation_type': 2,
            }
        )

        update_end_tx_column(table, conn=self.session)
        rows = self.session.execute(
            'SELECT * FROM article_version ORDER BY transaction_id'
        ).fetchall()
        assert rows[0].transaction_id == 1
        assert rows[0].end_transaction_id == 2
        assert rows[1].transaction_id == 2
        assert rows[1].end_transaction_id == 4
        assert rows[2].transaction_id == 3
        assert rows[2].end_transaction_id == 5
        assert rows[3].transaction_id == 4
        assert rows[3].end_transaction_id is None
        assert rows[4].transaction_id == 5
        assert rows[4].end_transaction_id is None
开发者ID:disko,项目名称:sqlalchemy-continuum,代码行数:57,代码来源:test_update_end_transaction_id.py


示例5: test_change_single_entity

    def test_change_single_entity(self):
        self.article = self.Article()
        self.article.name = u'Some article'
        self.article.content = u'Some content'
        self.session.add(self.article)
        self.session.commit()
        tx = self.article.versions[0].transaction

        assert tx.changed_entities == {
            version_class(self.article.__class__):
            [self.article.versions[0]]
        }
开发者ID:adamchainz,项目名称:sqlalchemy-continuum,代码行数:12,代码来源:test_transaction_changes.py


示例6: get_revision

def get_revision(endpoint, pid_value, transaction_id, rec_uuid):
    """Get the revision of given record (uuid)"""
    RecordMetadataVersion = version_class(RecordMetadata)

    revision = RecordMetadataVersion.query.with_entities(
        RecordMetadataVersion.json
    ).filter(
        RecordMetadataVersion.transaction_id == transaction_id,
        RecordMetadataVersion.id == rec_uuid
    ).one()

    return jsonify(revision.json)
开发者ID:david-caro,项目名称:inspire-next,代码行数:12,代码来源:api.py


示例7: test_assigns_foreign_keys_for_versions

 def test_assigns_foreign_keys_for_versions(self):
     article = self.Article()
     article.name = u'Some article'
     article.content = u'Some content'
     article.tags.append(self.Tag(name=u'some tag'))
     self.session.add(article)
     self.session.commit()
     cls = version_class(self.Tag)
     version = self.session.query(cls).first()
     assert version.name == u'some tag'
     assert version.id == 1
     assert version.article_id == 1
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:12,代码来源:test_table_builder.py


示例8: test_mod_properties_with_delete

 def test_mod_properties_with_delete(self):
     user = self.User(name=u'John')
     self.session.add(user)
     self.session.commit()
     self.session.delete(user)
     self.session.commit()
     UserVersion = version_class(self.User)
     version = (
         self.session
         .query(UserVersion)
         .order_by(sa.desc(UserVersion.transaction_id))
     ).first()
     assert version.age_mod
     assert version.name_mod
开发者ID:adamchainz,项目名称:sqlalchemy-continuum,代码行数:14,代码来源:test_property_mod_tracker.py


示例9: test_create_file_version

def test_create_file_version(monkeypatch, first_version_node, middle_version_node, current_version_node):
    from sqlalchemy_continuum import version_class
    from core import File
    NodeToFileVersion = version_class(NodeToFile)
    FileVersion = version_class(File)
    
    def _version_class(clz):
        if clz == NodeToFile:
            return NodeToFileVersion
        elif clz == File:
            return FileVersion
    
    monkeypatch.setattr(version_migration, "version_class", _version_class)
    
    Transaction = versioning_manager.transaction_cls
    remove_versioning()
    
    first = first_version_node
    middle = middle_version_node
    current = current_version_node


    first_files = [FileFactory()]
    first.files.extend(first_files)

    middle_files = [FileFactory()]
    middle.files.extend(middle_files)

    current_files = [FileFactory()]
    current.files.extend(current_files)

    transaction = Transaction()
    version_migration.create_file_versions(first, middle, transaction)

    transaction2 = Transaction()
    version_migration.create_file_versions(middle, current, transaction2)
    
开发者ID:mediatum,项目名称:mediatum,代码行数:36,代码来源:test_version_migration.py


示例10: find_by_holding

    def find_by_holding(cls, **kwargs):
        """Find item versions based on their holdings information.

        Every given kwarg will be queried as a key-value pair in the items
        holding.

        :returns: List[(UUID, version_id)] with `version_id` as used by
                  `RecordMetadata.version_id`.
        """
        def _get_filter_clause(obj, key, value):
            val = obj[key].astext
            CASTS = {
                bool: lambda x: cast(x, BOOLEAN),
                int: lambda x: cast(x, INTEGER),
                datetime.date: lambda x: cast(x, DATE),
            }
            if (not isinstance(value, six.string_types) and
                    isinstance(value, collections.Sequence)):
                if len(value) == 2:
                    return CASTS[type(value[0])](val).between(*value)
                raise ValueError('Too few/many values for a range query. '
                                 'Range query requires two values.')
            return CASTS.get(type(value), lambda x: x)(val) == value

        RecordMetadataVersion = version_class(RecordMetadata)

        data = type_coerce(RecordMetadataVersion.json, JSONB)
        path = ('_circulation', 'holdings')

        subquery = db.session.query(
            RecordMetadataVersion.id.label('id'),
            RecordMetadataVersion.version_id.label('version_id'),
            func.json_array_elements(data[path]).label('obj')
        ).subquery()

        obj = type_coerce(subquery.c.obj, JSONB)

        query = db.session.query(
            RecordMetadataVersion.id,
            RecordMetadataVersion.version_id
        ).filter(
            RecordMetadataVersion.id == subquery.c.id,
            RecordMetadataVersion.version_id == subquery.c.version_id,
            *(_get_filter_clause(obj, k, v) for k, v in kwargs.items())
        )

        for result in query:
            yield result
开发者ID:tiborsimko,项目名称:invenio-circulation,代码行数:48,代码来源:api.py


示例11: upgrade

def upgrade():
    op.add_column('volunteer', sa.Column('over_18', sa.Boolean(), nullable=False, server_default=expression.false()))
    op.add_column('volunteer_version', sa.Column('over_18', sa.Boolean(), autoincrement=False, nullable=True))

    bind = op.get_bind()
    session = sa.orm.Session(bind=bind)

    for volunteer in session.query(Volunteer):
        volunteer.over_18 = (volunteer.age >= 18)

    # include deleted records
    for version in session.query(version_class(Volunteer)):
        version.over_18 = (version.age >= 18)

    session.commit()

    op.drop_column('volunteer', 'age')
    op.drop_column('volunteer_version', 'age')
开发者ID:emfcamp,项目名称:Website,代码行数:18,代码来源:7f42f7d8c3f5_change_age_to_over_18.py


示例12: downgrade

def downgrade():
    op.add_column('volunteer_version', sa.Column('age', sa.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('volunteer', sa.Column('age', sa.INTEGER(), autoincrement=False, nullable=False, server_default=text('0')))

    # No clean downgrade, as we want to get rid of the data
    bind = op.get_bind()
    session = sa.orm.Session(bind=bind)

    for volunteer in session.query(Volunteer):
        volunteer.age = 18 if volunteer.over_18 else 17

    # include deleted records
    for version in session.query(version_class(Volunteer)):
        version.age = 18 if version.over_18 else 17

    session.commit()

    op.drop_column('volunteer_version', 'over_18')
    op.drop_column('volunteer', 'over_18')
开发者ID:emfcamp,项目名称:Website,代码行数:19,代码来源:7f42f7d8c3f5_change_age_to_over_18.py


示例13: test_previous_for_deleted_parent

    def test_previous_for_deleted_parent(self):
        item = self.TextItem()
        item.name = u'Some item'
        item.content = u'Some content'
        self.session.add(item)
        self.session.commit()
        self.session.delete(item)
        self.session.commit()
        TextItemVersion = version_class(self.TextItem)

        versions = (
            self.session.query(TextItemVersion)
            .order_by(
                getattr(
                    TextItemVersion,
                    self.options['transaction_column_name']
                )
            )
        ).all()
        assert versions[1].previous.name == u'Some item'
开发者ID:adamchainz,项目名称:sqlalchemy-continuum,代码行数:20,代码来源:test_column_aliases.py


示例14: _insert

 def _insert(self, values):
     table = version_class(self.Article).__table__
     stmt = table.insert().values(values)
     self.session.execute(stmt)
开发者ID:disko,项目名称:sqlalchemy-continuum,代码行数:4,代码来源:test_update_end_transaction_id.py


示例15: test_primary_keys_not_included

 def test_primary_keys_not_included(self):
     UserVersion = version_class(self.User)
     assert 'id_mod' not in UserVersion.__table__.c
开发者ID:disko,项目名称:sqlalchemy-continuum,代码行数:3,代码来源:test_property_mod_tracker.py


示例16: test_each_column_generates_additional_mod_column

 def test_each_column_generates_additional_mod_column(self):
     UserVersion = version_class(self.User)
     assert 'name_mod' in UserVersion.__table__.c
     column = UserVersion.__table__.c['name_mod']
     assert not column.nullable
     assert isinstance(column.type, sa.Boolean)
开发者ID:disko,项目名称:sqlalchemy-continuum,代码行数:6,代码来源:test_property_mod_tracker.py


示例17: test_created_tables_retain_schema

 def test_created_tables_retain_schema(self):
     table = version_class(self.Article).__table__
     assert table.schema is not None
     assert table.schema == self.Article.__table__.schema
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:4,代码来源:test_table_builder.py


示例18: test_does_not_make_composite_primary_keys_not_nullable

    def test_does_not_make_composite_primary_keys_not_nullable(self):
        TeamMemberVersion = version_class(self.TeamMember)

        assert not TeamMemberVersion.__table__.c.user_id.nullable
开发者ID:adamchainz,项目名称:sqlalchemy-continuum,代码行数:4,代码来源:test_composite_primary_key.py


示例19: test_takes_out_onupdate_triggers

 def test_takes_out_onupdate_triggers(self):
     table = version_class(self.Article).__table__
     assert table.c.last_update.onupdate is None
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:3,代码来源:test_table_builder.py


示例20: test_transaction_id_column_not_nullable

 def test_transaction_id_column_not_nullable(self):
     assert self.Article.__table__.c.name.nullable is False
     table = version_class(self.Article).__table__
     assert table.c.transaction_id.nullable is False
开发者ID:karih,项目名称:sqlalchemy-continuum,代码行数:4,代码来源:test_table_builder.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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