这是一个简单的练习,请按照以下说明操作,我需要使用sessionmaker对sqlalchemy进行分页...
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
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)