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


Python DBSession.execute方法代码示例

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


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

示例1: inject_in_db

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import execute [as 别名]
 def inject_in_db(cls, enable_player=False):
     from mediacore.model import DBSession
     from mediacore.model.players import players as players_table, PlayerPrefs
     
     prefs = PlayerPrefs()
     prefs.name = cls.name
     prefs.enabled = enable_player
     # didn't get direct SQL expression to work with SQLAlchemy
     # player_table = sql.func.max(player_table.c.priority)
     query = sql.select([sql.func.max(players_table.c.priority)])
     max_priority = DBSession.execute(query).first()[0]
     if max_priority is None:
         max_priority = -1
     prefs.priority = max_priority + 1
     prefs.created_on = datetime.now()
     prefs.modified_on = datetime.now()
     prefs.data = cls.default_data
     DBSession.add(prefs)
     DBSession.commit()
开发者ID:axxis7,项目名称:mediacore-community,代码行数:21,代码来源:players.py

示例2: map_migrate_version

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import execute [as 别名]
 def map_migrate_version(self):
     migrate_version_query = migrate_table.select(
         migrate_table.c.repository_id == u'MediaCore Migrations'
     )
     result = DBSession.execute(migrate_version_query).fetchone()
     db_migrate_version = result.version
     if db_migrate_version in migrate_to_alembic_mapping:
         return migrate_to_alembic_mapping[db_migrate_version]
     
     earliest_upgradable_version = sorted(migrate_to_alembic_mapping)[0]
     if db_migrate_version < earliest_upgradable_version:
         error_msg = ('Upgrading from such an old version of MediaCore is not '
             'supported. Your database is at version %d but upgrades are only '
             'supported from MediaCore CE 0.9.0 (DB version %d). Please upgrade '
             '0.9.0 first.')
         self.log.error(error_msg % (db_migrate_version, earliest_upgradable_version))
     else:
         self.log.error('Unknown DB version %s. Can not upgrade to alembic' % db_migrate_version)
     raise AssertionError('unsupported DB migration version.')
开发者ID:TAMUArch,项目名称:mediacore-community,代码行数:21,代码来源:util.py

示例3: reposition_file

# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import execute [as 别名]
    def reposition_file(self, file, budge_infront=None):
        """Position the first file after the second or last file.

        If only one file is specified, we move it to the last position (the end).

        If two files are specified, the first takes the seconds position, and the
        positions of the second file and those that follow it are incremented.

        This increments MediaFile.position such that gaps in the sequence occur.

        When the primary_file is changed by this operation, we ensure that the
        Media.type matches the type of the new primary_file.

        Depending on the situation, we manipulate the DBSession, rather than our
        usual practice of simply modifying the object and leaving DBSession work
        to the controller. This is necessary because we run a query on the DB
        without using the ORM in some cases.

        :param file: The file to move
        :type file: :class:`MediaFile` or int
        :param budge_infront: The file to position after.
        :type budge_infront: :class:`MediaFile` or int or None
        """
        if not isinstance(file, MediaFile):
            file = [f for f in self.files if f.id == file][0]

        if budge_infront:
            # The first file is going to move in front of the second
            if not isinstance(budge_infront, MediaFile):
                budge_infront = [f for f in self.files if f.id == budge_infront][0]

            pos = budge_infront.position
            is_first = budge_infront is self.primary_file

            # Update the moved row, the budge_infront file, and those after it.
            # When we reach the moved row, the new position is simply set,
            # otherwise the position is incremented 1.
            update = media_files.update()\
                .where(sql.and_(
                    media_files.c.media_id == self.id,
                    sql.or_(
                        media_files.c.position >= pos,
                        media_files.c.id == file.id
                    )
                ))\
                .values({
                    media_files.c.position: sql.case(
                        [(media_files.c.id == file.id, pos)],
                        else_=media_files.c.position + 1
                    )
                })

            DBSession.execute(update)
            datamanager.mark_changed(DBSession())

        else:
            # No budging, so if there any other files we'll have to go after them...
            pos = 0
            is_first = True

            if self.files:
                pos += self.files[-1].position
                is_first = False

            file.position = pos
            DBSession.add(file)

        # Making an audio file primary over a video file changes the media type
        if is_first and file.medium is not None:
            self.type = file.medium

        return pos
开发者ID:SergeyLashin,项目名称:mediacore,代码行数:74,代码来源:media.py


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