Did I find the right examples for you? yes no

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Find the current version of all items.

        def get_current_itemversions_join(model, max_timestamp=None):
    """Find the current version of all items."""

    from sqlalchemy.sql import select, and_, or_, not_, func

    max_timestamps_per_item = select(
            [model.itemversions.c.item_id,
                func.max(model.itemversions.c.timestamp).label("max_timestamp")])

    if max_timestamp is not None:
        max_timestamps_per_item = max_timestamps_per_item.where(
                model.itemversions.c.timestamp <= max_timestamp+1)

    max_timestamps_per_item = max_timestamps_per_item.group_by(
            model.itemversions.c.item_id)
    max_timestamps_per_item = max_timestamps_per_item.alias("max_ts")

    return model.itemversions.join(max_timestamps_per_item,
                and_(
                    max_timestamps_per_item.c.item_id
                      ==model.itemversions.c.item_id,
                    max_timestamps_per_item.c.max_timestamp
                      ==model.itemversions.c.timestamp,
                    ))
        


src/s/y/synoptic-2013.1/synoptic/__init__.py   synoptic(Download)
from synoptic.datamodel import \
        Item, ItemVersion, Tag, ViewOrdering, ViewOrderingEntry, \
        store_itemversion,  \
        get_current_itemversions_join, \
        query_itemversions
            itemversions_q = select([model.itemversions],
                    from_obj=[get_current_itemversions_join(
                        model, max_timestamp)
                        ])
 
 
        from_obj = get_current_itemversions_join(
                request.datamodel, max_timestamp)
 
        from sqlalchemy.sql import select, or_, and_