Last active
June 28, 2016 20:11
-
-
Save inklesspen/4205802bfffcdabfa737 to your computer and use it in GitHub Desktop.
Revisions
-
inklesspen revised this gist
Jan 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,4 +43,4 @@ def includeme(config): # Every request will have a db_session property. The first time # you use it, it creates a session, and then replaces the property # with that session. config.add_request_method(lambda request: maker(), 'db_session', reify=True) -
inklesspen renamed this gist
Jan 4, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
inklesspen created this gist
Jan 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ from sqlalchemy import ( Column, Index, Integer, Text, ) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import engine_from_config from sqlalchemy.orm import sessionmaker from zope.sqlalchemy import register Base = declarative_base() class MyModel(Base): __tablename__ = 'models' id = Column(Integer, primary_key=True) name = Column(Text) value = Column(Integer) Index('my_index', MyModel.name, unique=True, mysql_length=255) def includeme(config): # We'll configure the DB connection from this. settings = config.get_settings() # by including pyramid_tm here, it doesn't need to be in the ini file. config.include('pyramid_tm') # connect to the DB and make a sessionmaker engine = engine_from_config(settings, 'sqlalchemy.') maker = sessionmaker() # register the sessionmaker with the zope transaction manager # all sessions created from this will be hooked up register(maker) # and finally connect the session to the engine maker.configure(bind=engine) # Every request will have a db_session property. The first time # you use it, it creates a session, and then replaces the property # with that session. config.add_request_method(lambda request: sessionmaker(), 'db_session', reify=True)