question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use paginate with sqlalchemy new query syntax

See original GitHub issue

Hi

I’m trying to migrate to Sqlalchemy 1.4.23 and activate the new query syntax. But can’t figure out how to use paginate function with it.

fastapi-pagination==0.8.3

from sqlalchemy.future import select
from models import UserModel


class User:
    def _init__(self, db_session):
        self.db_session = session

    def get_users():
        return select(UserModel)

The endpoint looks like this:

from fastapi_pagination.ext.sqlalchemy import paginate
from fastapi_pagination import Page, Params

@router.get('/get-users')
def get_users(self, 
                       page_schema: PaginationParams = Depends(),
                       db_session: Session = Depends(get_request_db)) -> Page[UserSchema]:
    users = User(db_session).get_users()

    return paginate(users, page_schema)

I’m getting this error:

image

Also tried:

from sqlalchemy.future import select
from models import UserModel


class User:
    def _init__(self, db_session):
        self.db_session = session

    def get_users():
        return self.db_session.execute(select(UserModel))

but got this:

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rafa761commented, Sep 6, 2021

ok, thank you for your effort on the project @uriyyo

1reaction
uriyyocommented, Sep 6, 2021

Hi @rafa761,

Currently fastapi-pagination does not support sqlalchemy 1.14 version. I am planing to include support at version 0.9.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Query Tables and Paginate Data in Flask-SQLAlchemy
You'll use the Flask shell to query a table, and get table records based on a column value (for example, an email). You'll...
Read more >
pagination - SQLAlchemy and going through a large result set
Returns a Pagination object for the previous page. prev_num. Number of the previous page. query = None. the unlimited query object that was...
Read more >
Paging Query Results - Flask-SQLAlchemy
Call SQLAlchemy.paginate() on a select statement to get a Pagination object. During a request, this will take page and per_page arguments from the...
Read more >
wizeline/sqlalchemy-pagination: Small utility to ... - GitHub
Small utility to paginate SqlAlchemy queries. . Contribute to wizeline/sqlalchemy-pagination development by creating an account on GitHub.
Read more >
Several pagination methods of SQLAlchemy and Flask ...
1.sets the index offset with offset (), limit () limits the amount taken. Db.session. · 2. Use Slice (offset, amount of removal )...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found