Exemplo n.º 1
0
    def test_subquery(self):
        self.create_data(10)

        query = User.where(User.id._in(Post.select(Post.user_id))).select()
        result = query.execute()
        assert result.count == 10

        query = User.where(id=(Post.select(fn.max(Post.user_id)))).select()
        result = query.execute()
        assert result.count == 1
        assert result.one().id == 10

        query = User.where(
            User.id < Post.select(fn.min(Post.user_id))).select()
        result = query.execute()
        assert result.count == 0
Exemplo n.º 2
0
    def test_subquery(self):
        self.create_data(10)

        query = User.where(User.id._in(Post.select(Post.user_id))).select()
        result = query.execute()
        assert result.count == 10

        query = User.where(id=(Post.select(fn.max(Post.user_id)))).select()
        result = query.execute()
        assert result.count == 1
        assert result.one().id == 10

        query = User.where(
            User.id < Post.select(fn.min(Post.user_id))).select()
        result = query.execute()
        assert result.count == 0
Exemplo n.º 3
0
Arquivo: post.py Projeto: hit9/zhiz
def post(id):
    post = Post.at(id).getone()

    if post is None:
        abort(404)

    setattr(post, "html", markdown.render(post.body))

    query = Post.where(
        Post.id._in(Post.where(Post.id > id).select(fn.min(Post.id)), Post.where(Post.id < id).select(fn.max(Post.id)))
    ).select(Post.id, Post.title)

    setattr(post, "next", None)
    setattr(post, "prev", None)

    for pst in query:  # execute query
        if pst.id > id:
            post.next = pst
        elif pst.id < id:
            post.prev = pst

    return render_public("post.html", post=post)
Exemplo n.º 4
0
 def test_min(self):
     self.create_data(4)
     query = User.where(User.id > 2).select(fn.min(User.id))
     result = query.execute()
     assert result.count == 1
     assert result.tuples()[0][0] == 3
Exemplo n.º 5
0
 def test_min(self):
     self.create_data(4)
     query = User.where(User.id > 2).select(fn.min(User.id))
     result = query.execute()
     assert result.count == 1
     assert result.tuples()[0][0] == 3