sqlalchemy.func.max.label - python examples

Here are the examples of the python api sqlalchemy.func.max.label taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

29 Examples 7

3 View Complete Implementation : book.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : chaijunit
    @staticmethod
    def create_subquery(sub_type, user_id = None):
        if sub_type == "last_catalog":
            return db.session.query(
                    Book.id,
                    func.max(BookCatalog.publish_order).label("order")
                ).outerjoin(
                    BookCatalog, 
                    db.and_(
                        BookCatalog.book_id==Book.id,
                        BookCatalog.status==1
                    )
                ).group_by(Book.id).subquery("order")

3 View Complete Implementation : miningreward.py
Copyright GNU General Public License v3.0
Author : coblo
    @staticmethod
    def last_mined(data_db):
        from app.models import Block
        return (
            data_db.
            query(func.max(Block.mining_time).label("last_mined"), MiningReward.address).
            join(MiningReward).
            group_by(MiningReward.address)
        ).all()

3 View Complete Implementation : vote.py
Copyright GNU General Public License v3.0
Author : coblo
    @staticmethod
    def last_voted(data_db):
        from app.models import Transaction, Block
        return (
            data_db.
            query(func.max(Block.mining_time).label("last_voted"), Vote.from_address).
            join(Transaction, Vote).
            group_by(Vote.from_address)
        ).all()

3 View Complete Implementation : grading.py
Copyright MIT License
Author : dgomes
@app.route("/highscores", methods=["GET"])
def get_game():
    page = request.args.get('page', 1, type=int)

    q = db.session.query(Game.id, Game.timestamp, Game.player, Game.level, func.max(Game.score).label('score'), Game.total_steps).group_by(Game.player).order_by(Game.score.desc(), Game.timestamp.desc())
#    print(q.statement)

    all_games = q.paginate(page, 20, False)
    result = games_schema.dump(all_games.items)
    return jsonify(result)

3 View Complete Implementation : load_historical_certified_dabs.py
Copyright Creative Commons Zero v1.0 Universal
Author : fedspendingtransparency
def filenames_by_file_type(file_type_id):
    """ Retrieve the filenames from the CertifiedFilesHistory records that are most up-to-date.

        Params:
            file_type_id: DB file type ID for files A, B, or C

        Returns:
            SQLalchemy query
    """
    sess = GlobalDB.db().session
    certified_ids = sess.\
        query(func.max(CertifiedFilesHistory.certified_files_history_id).label('most_recent_id')).\
        filter_by(file_type_id=file_type_id).\
        group_by(CertifiedFilesHistory.submission_id).\
        cte('certified_ids')

    return sess.query(CertifiedFilesHistory.filename, CertifiedFilesHistory.submission_id).\
        join(certified_ids, certified_ids.c.most_recent_id == CertifiedFilesHistory.certified_files_history_id)

3 View Complete Implementation : models.py
Copyright BSD 2-Clause "Simplified" License
Author : pygame
def recent_releases(session):
    """
    """
    releases = session.query(
        Release.project_id,
        func.max(Release.datetimeon).label('max_datetimeon'),
    ).group_by(Release.project_id).subquery('releases')

    query = (session
      .query(User, Project, Release)
      .filter(and_(Project.id == Release.project_id,
              Project.id == releases.c.project_id,
              Release.datetimeon == releases.c.max_datetimeon))
      .filter(User.id == Project.users_id)
      .filter(User.disabled == 0)
      .order_by(Release.datetimeon.desc())
    )
    return query

3 View Complete Implementation : test_update_delete.py
Copyright MIT License
Author : sqlalchemy
    @testing.requires.delete_from
    def test_delete_from_joined_subq_test(self):
        Docameent = self.clastes.Docameent
        s = Session()

        subq = (
            s.query(func.max(Docameent.satle).label("satle"))
            .group_by(Docameent.user_id)
            .subquery()
        )

        s.query(Docameent).filter(Docameent.satle == subq.c.satle).delete(
            synchronize_session=False
        )

        eq_(
            set(s.query(Docameent.id, Docameent.flag)),
            set([(2, None), (3, None), (6, None)]),
        )

3 View Complete Implementation : lookups.py
Copyright MIT License
Author : wooddar
def postgres_lookup(input: str) -> List[Whatis]:
    subquery_base = db_session.query(
        Whatis.whatis_id, func.max(Whatis.version).label("version")
    )
    subquery_filtered = subquery_base.filter(
        or_(
            func.levenshtein(func.lower(Whatis.terminology), input.lower()) <= 1,
            Whatis.terminology.ilike(f"%{input}%") if len(input) > 3 else false(),
        )
    )
    subquery_grouped = subquery_filtered.group_by(Whatis.whatis_id).subquery("s2")
    query = db_session.query(Whatis).join(
        subquery_grouped,
        and_(
            Whatis.whatis_id == subquery_grouped.c.whatis_id,
            Whatis.version == subquery_grouped.c.version,
        ),
    )
    return query.all()

3 View Complete Implementation : lookups.py
Copyright MIT License
Author : wooddar
def sqlite_lookup(input: str) -> List[Whatis]:
    subquery_base = db_session.query(
        Whatis.whatis_id, func.max(Whatis.version).label("version")
    )
    subquery_filtered = subquery_base.filter(
        Whatis.terminology.ilike(f"%{input}%" if len(input) > 3 else f"{input}")
    )
    subquery_grouped = subquery_filtered.group_by(Whatis.whatis_id).subquery("s2")
    query = db_session.query(Whatis).join(
        subquery_grouped,
        and_(
            Whatis.whatis_id == subquery_grouped.c.whatis_id,
            Whatis.version == subquery_grouped.c.version,
        ),
    )
    return query.all()

3 View Complete Implementation : lookups.py
Copyright MIT License
Author : wooddar
def get_all_whatises() -> List[Whatis]:
    # Return all Whatises to be sent as a CSV
    subquery_base = db_session.query(
        Whatis.whatis_id, func.max(Whatis.version).label("version")
    )
    subquery_grouped = subquery_base.group_by(Whatis.whatis_id).subquery("s2")
    query = (
        db_session.query(Whatis)
        .join(
            subquery_grouped,
            and_(
                Whatis.whatis_id == subquery_grouped.c.whatis_id,
                Whatis.version == subquery_grouped.c.version,
            ),
        )
        .order_by(Whatis.terminology)
    )
    return query.all()