2

This is a simple exercice, following instructions below, i need to paginate with sqlalchemy using sessionmaker...

This is the main.py:

from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker 
from database_config import Post

engine = create_engine('sqlite:///posts.db') Base.metadata.bind = engine 
DBSession = sessionmaker(bind=engine) session = DBSession()

posts = session.query(Post).all() #this will give all posts i need

And this is the database_config module:

from sqlalchemy import Column, String, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine

Base = declarative_base()

class Post(Base):
    __tablename__ = 'posts'
    id = Column(Integer, primary_key=True)
    title = Column(String(250), nullable=False)

engine=create_engine('sqlite:///posts.db')
Base.metadata.create_all(engine)

Medinho
  • 193
  • 1
  • 3
  • 10

0 Answers0