In [1]:
from agora import Forum
from agora.models import Base
In [2]:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
In [3]:
# set up in-memory sqlite database for persistence
engine = create_engine('sqlite:///:memory:')
# create the database tables defined in agora.models
Base.metadata.create_all(engine)
In [4]:
# create an sqlalchemy scoped session
# and bind it to the engine
# (scoped sessions manage transactions internally)
DBSession = scoped_session(sessionmaker())
DBSession.configure(bind=engine)
In [ ]:
In [5]:
# instantiate the forum
forum = Forum(DBSession)
In [6]:
forum.get_ideas()
Out[6]:
In [ ]:
In [7]:
forum.add_author(username='schmoe', fullname='Joe Schmoe', email='schmoe@example.com')
Out[7]:
In [8]:
forum.add_author(username='misinformation', fullname='Miss Information', email='misinformation@example.com')
Out[8]:
In [9]:
forum.get_authors()
Out[9]:
In [10]:
forum.get_author(1)
Out[10]:
In [ ]:
In [11]:
forum.add_idea(title='First Idea!', idea='This is my idea.', author_id=1)
Out[11]:
In [12]:
forum.add_idea(title='My First Idea!', idea='This is my idea.', author_id=2)
Out[12]:
In [13]:
forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=1)
Out[13]:
In [14]:
forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=2)
Out[14]:
In [15]:
forum.get_ideas()
Out[15]:
In [16]:
forum.get_idea(1)
Out[16]:
In [ ]:
In [ ]:
forum.get_ideas(filters={'author': forum.get_author(1)})
In [ ]:
forum.get_ideas(filters={'title': 'First Idea!'})
In [ ]:
forum.get_ideas(filters={'title': 'Another Idea!'})
In [ ]:
forum.get_ideas(filters={'author': forum.get_author(2), 'title': 'Another Idea!'})
In [ ]:
In [ ]:
forum.get_ideas()
In [ ]:
forum.delete_idea(1)
In [ ]:
forum.get_ideas()
In [ ]: