Пример #1
0
def delete_by_facet(etype, filter_expression=None):
    """Delete entity instance by id.

    :param class etype: A supported entity type.
    :param expression filter_expression: Facet filter expression.

    """
    qry = session.query(etype)
    if filter_expression:
        qry = qry.filter(filter_expression)
    qry.delete()
Пример #2
0
def get_issue(uid):
    """Returns an issue.

    :param str uid: Issue unique identifier.

    :returns: First matching issue.
    :rtype: db.models.Issue

    """
    qry = query(Issue)
    qry = text_filter(qry, Issue.uid, uid)

    return qry.first()
Пример #3
0
def get_issues(status=None):
    """Returns an issue.

    :param str status: Issue status filter field.

    :returns: First matching issue.
    :rtype: db.models.Issue

    """
    qry = query(Issue)
    if status:
        qry = text_filter(qry, Issue.status, status)

    return qry.all()
Пример #4
0
def get_count(etype, qfilter=None):
    """Gets count of entity instances.

    :param class etype: A supported entity type.
    :param expression qfilter: Query filter expression.

    :returns: Entity collection count.
    :rtype: int

    """
    qry = session.query(etype)
    if qfilter is not None:
        qry = qry.filter(qfilter)

    return qry.count()
Пример #5
0
def get_by_facet(etype, qfilter=None, order_by=None, get_iterable=False):
    """Gets entity instance by facet.

    :param class etype: A supported entity type.
    :param expression qfilter: Query filter expression.
    :param expression order_by: Sort expression.
    :param bool get_iterable: Flag indicating whether to return an iterable or not.

    :returns: Entity or entity collection.
    :rtype: Sub-class of db.Entity

    """
    qry = session.query(etype)
    if qfilter is not None:
        qry = qry.filter(qfilter)
    if order_by is not None:
        qry = qry.order_by(order_by)

    return exec_query(etype, qry, get_iterable)