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


Python sqlalchemy.between方法代码示例

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


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

示例1: _find_columns

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def _find_columns(clause):
    """locate Column objects within the given expression."""

    cols = util.column_set()
    traverse(clause, {}, {'column': cols.add})
    return cols


# there is some inconsistency here between the usage of
# inspect() vs. checking for Visitable and __clause_element__.
# Ideally all functions here would derive from inspect(),
# however the inspect() versions add significant callcount
# overhead for critical functions like _interpret_as_column_or_from().
# Generally, the column-based functions are more performance critical
# and are fine just checking for __clause_element__().  It is only
# _interpret_as_from() where we'd like to be able to receive ORM entities
# that have no defined namespace, hence inspect() is needed there. 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:elements.py

示例2: _find_columns

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def _find_columns(clause):
    """locate Column objects within the given expression."""

    cols = util.column_set()
    traverse(clause, {}, {'column': cols.add})
    return cols


# there is some inconsistency here between the usage of
# inspect() vs. checking for Visitable and __clause_element__.
# Ideally all functions here would derive from inspect(),
# however the inspect() versions add significant callcount
# overhead for critical functions like _interpret_as_column_or_from().
# Generally, the column-based functions are more performance critical
# and are fine just checking for __clause_element__().  it's only
# _interpret_as_from() where we'd like to be able to receive ORM entities
# that have no defined namespace, hence inspect() is needed there. 
开发者ID:binhex,项目名称:moviegrabber,代码行数:19,代码来源:elements.py

示例3: _cloned_intersection

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def _cloned_intersection(a, b):
    """return the intersection of sets a and b, counting
    any overlap between 'cloned' predecessors.

    The returned set is in terms of the entities present within 'a'.

    """
    all_overlap = set(_expand_cloned(a)).intersection(_expand_cloned(b))
    return set(elem for elem in a
               if all_overlap.intersection(elem._cloned_set)) 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:elements.py

示例4: test_operator_precedence_9

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_operator_precedence_9(self):
        self.assert_compile(
            self.table2.select(not_(self.table2.c.field.between(5, 6))),
            "SELECT op.field FROM op WHERE "
            "op.field NOT BETWEEN :field_1 AND :field_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_operators.py

示例5: test_operator_precedence_11

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_operator_precedence_11(self):
        self.assert_compile(
            self.table2.select(
                (self.table2.c.field == self.table2.c.field).between(
                    False, True
                )
            ),
            "SELECT op.field FROM op WHERE (op.field = op.field) "
            "BETWEEN :param_1 AND :param_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:test_operators.py

示例6: test_operator_precedence_12

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_operator_precedence_12(self):
        self.assert_compile(
            self.table2.select(
                between(
                    (self.table2.c.field == self.table2.c.field), False, True
                )
            ),
            "SELECT op.field FROM op WHERE (op.field = op.field) "
            "BETWEEN :param_1 AND :param_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:test_operators.py

示例7: test_pickle_operators_one

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_pickle_operators_one(self):
        clause = (
            (self.table1.c.myid == 12)
            & self.table1.c.myid.between(15, 20)
            & self.table1.c.myid.like("hoho")
        )
        eq_(str(clause), str(util.pickle.loads(util.pickle.dumps(clause)))) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,代码来源:test_operators.py

示例8: test_between_1

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_between_1(self):
        self.assert_compile(
            self.table1.c.myid.between(1, 2),
            "mytable.myid BETWEEN :myid_1 AND :myid_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_operators.py

示例9: test_between_2

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_between_2(self):
        self.assert_compile(
            ~self.table1.c.myid.between(1, 2),
            "mytable.myid NOT BETWEEN :myid_1 AND :myid_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_operators.py

示例10: test_between_3

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_between_3(self):
        self.assert_compile(
            self.table1.c.myid.between(1, 2, symmetric=True),
            "mytable.myid BETWEEN SYMMETRIC :myid_1 AND :myid_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_operators.py

示例11: test_between_4

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_between_4(self):
        self.assert_compile(
            ~self.table1.c.myid.between(1, 2, symmetric=True),
            "mytable.myid NOT BETWEEN SYMMETRIC :myid_1 AND :myid_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_operators.py

示例12: test_between_5

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def test_between_5(self):
        self.assert_compile(
            between(self.table1.c.myid, 1, 2, symmetric=True),
            "mytable.myid BETWEEN SYMMETRIC :myid_1 AND :myid_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:7,代码来源:test_operators.py

示例13: between

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def between(expr, lower_bound, upper_bound, symmetric=False):
    """Produce a ``BETWEEN`` predicate clause.

    E.g.::

        from sqlalchemy import between
        stmt = select([users_table]).where(between(users_table.c.id, 5, 7))

    Would produce SQL resembling::

        SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2

    The :func:`.between` function is a standalone version of the
    :meth:`.ColumnElement.between` method available on all
    SQL expressions, as in::

        stmt = select([users_table]).where(users_table.c.id.between(5, 7))

    All arguments passed to :func:`.between`, including the left side
    column expression, are coerced from Python scalar values if a
    the value is not a :class:`.ColumnElement` subclass.   For example,
    three fixed values can be compared as in::

        print(between(5, 3, 7))

    Which would produce::

        :param_1 BETWEEN :param_2 AND :param_3

    :param expr: a column expression, typically a :class:`.ColumnElement`
     instance or alternatively a Python scalar expression to be coerced
     into a column expression, serving as the left side of the ``BETWEEN``
     expression.

    :param lower_bound: a column or Python scalar expression serving as the
     lower bound of the right side of the ``BETWEEN`` expression.

    :param upper_bound: a column or Python scalar expression serving as the
     upper bound of the right side of the ``BETWEEN`` expression.

    :param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note
     that not all databases support this syntax.

     .. versionadded:: 0.9.5

    .. seealso::

        :meth:`.ColumnElement.between`

    """
    expr = _literal_as_binds(expr)
    return expr.between(lower_bound, upper_bound, symmetric=symmetric) 
开发者ID:jpush,项目名称:jbox,代码行数:54,代码来源:elements.py

示例14: _apply_criterion

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def _apply_criterion(table, query, criterion):
        if criterion is not None:
            for name, value in criterion.items():
                column = getattr(table.c, name)

                # Wildcard value: '%'
                if isinstance(value, six.string_types) and '%' in value:
                    query = query.where(column.like(value))

                elif (isinstance(value, six.string_types) and
                        value.startswith('!')):
                    queryval = value[1:]
                    query = query.where(column != queryval)

                elif (isinstance(value, six.string_types) and
                        value.startswith('<=')):
                    queryval = value[2:]
                    query = query.where(column <= queryval)

                elif (isinstance(value, six.string_types) and
                        value.startswith('<')):
                    queryval = value[1:]
                    query = query.where(column < queryval)

                elif (isinstance(value, six.string_types) and
                        value.startswith('>=')):
                    queryval = value[2:]
                    query = query.where(column >= queryval)

                elif (isinstance(value, six.string_types) and
                        value.startswith('>')):
                    queryval = value[1:]
                    query = query.where(column > queryval)

                elif (isinstance(value, six.string_types) and
                        value.startswith('BETWEEN')):
                    elements = [i.strip(" ") for i in
                                value.split(" ", 1)[1].strip(" ").split(",")]
                    query = query.where(between(
                        column, elements[0], elements[1]))

                elif isinstance(value, list):
                    query = query.where(column.in_(value))

                else:
                    query = query.where(column == value)

        return query 
开发者ID:openstack,项目名称:designate,代码行数:50,代码来源:base.py

示例15: all_children

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import between [as 别名]
def all_children(self):
        """
        Get immediate children of the organization
        Reference:
        http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
        http://www.sitepoint.com/hierarchical-data-database/
        Generated SQL Sample:
        SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
        FROM nested_category AS node,
             nested_category AS parent,
             nested_category AS sub_parent,
             (
              SELECT node.name, (COUNT(parent.name) - 1) AS depth
              FROM nested_category AS node,
              nested_category AS parent
              WHERE node.lft BETWEEN parent.lft AND parent.rgt
              AND node.name = 'PORTABLE ELECTRONICS'
              GROUP BY node.name
              ORDER BY node.lft
             )AS sub_tree
             WHERE node.lft BETWEEN parent.lft AND parent.rgt
             AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
             AND sub_parent.name = sub_tree.name
             GROUP BY node.name
             ORDER BY node.lft;
        """
        s_node = aliased(Organization, name='s_node')
        s_parent = aliased(Organization, name='s_parent')
        sub_tree = db.session.query(s_node.id, (func.count(s_parent.name) - 1).label('depth')). \
            filter(and_(between(s_node.lft, s_parent.lft, s_parent.rgt), s_node.id == self.id)) \
            .group_by(s_node.id, s_node.lft).order_by(s_node.lft).subquery()

        t_node = aliased(Organization, name='t_node')
        t_parent = aliased(Organization, name='t_parent')
        t_sub_parent = aliased(Organization, name='t_sub_parent')
        # Postgres does not support label as (func.count(t_parent.name) - (sub_tree.c.depth + 1)).label('xxx')
        # And have the field in having clause will cause issue.
        query = (db.session.query(t_node.id, t_node.name, (func.count(t_parent.name) - (sub_tree.c.depth + 1))).
                 filter(and_(between(t_node.lft, t_parent.lft, t_parent.rgt),
                             between(t_node.lft, t_sub_parent.lft, t_sub_parent.rgt),
                             t_node.id != self.id,  # Exclude current node --> itself
                             t_sub_parent.id == sub_tree.c.id))
                 .group_by(t_node.id, t_node.name, t_node.lft, 'depth')
                 .order_by(t_node.lft))
        obj_result = id_query_to_obj(Organization, query)
        return obj_result 
开发者ID:betterlife,项目名称:betterlifepsi,代码行数:48,代码来源:organization.py


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