added elixir simplicity - hope the sessions gets cleared automagically somehow

git-svn-id: http://yolanda.mister-muffin.de/svn@374 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-08-18 22:56:39 +00:00
parent 6a851c384b
commit 3662a1f4b4
4 changed files with 11 additions and 23 deletions

View file

@ -8,7 +8,7 @@ import yolanda.lib.helpers
from yolanda.config.routing import make_map from yolanda.config.routing import make_map
from sqlalchemy import engine_from_config from sqlalchemy import engine_from_config
from yolanda.model import init_model from yolanda import model
def load_environment(global_conf, app_conf): def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config`` """Configure the Pylons environment via the ``pylons.config``
@ -36,4 +36,6 @@ def load_environment(global_conf, app_conf):
# any Pylons config options) # any Pylons config options)
engine = engine_from_config(config, 'sqlalchemy.') engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine) model.metadata.bind = engine
model.metadata.bind.echo = True
model.Session.bind = engine

View file

@ -23,10 +23,7 @@ class BaseController(WSGIController):
# the request is routed to. This routing information is # the request is routed to. This routing information is
# available in environ['pylons.routes_dict'] # available in environ['pylons.routes_dict']
response.headers['Content-type'] = "application/xml" response.headers['Content-type'] = "application/xml"
try: return WSGIController.__call__(self, environ, start_response)
return WSGIController.__call__(self, environ, start_response)
finally:
Session.remove()
# Include the '_' function in the public names # Include the '_' function in the public names
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ __all__ = [__name for __name in locals().keys() if not __name.startswith('_') \

View file

@ -1,20 +1,11 @@
from sqlalchemy.orm import scoped_session, sessionmaker
import elixir import elixir
# replace the elixir session with our own # replace the elixir session with our own
Session = scoped_session(sessionmaker(autoflush=True, transactional=True)) Session = elixir.session(autoflush=True, transactional=True)
elixir.session = Session
elixir.options_defaults.update({
'shortnames': True
})
# use the elixir metadata # use the elixir metadata
metadata = elixir.metadata metadata = elixir.metadata
# this will be called in config/environment.py
def init_model(engine):
metadata.bind = engine
# import your entities, and set them up # import your entities, and set them up
from entities import * from entities import *
elixir.setup_all() elixir.setup_all()

View file

@ -1,8 +1,6 @@
from elixir.entity import * from elixir import *
from elixir.fields import *
from sqlalchemy.types import *
from datetime import datetime
class Person(Entity): class Video(Entity):
name = Field(Unicode(128)) using_options(tablename='videos')
birthdate = Field(DateTime, default=datetime.now)
title = Field(Unicode(255))