コード例 #1
0
ファイル: SQLSupport.py プロジェクト: Afridocs/GlobaLeaks-0.1
#################### Session Usage ###############
# What is all this l_session madness? See:                                                                
# http://www.sqlalchemy.org/docs/orm/session.html#lifespan-of-a-contextual-session                        
#   "This has the effect such that each web request starts fresh with                                     
#   a brand new session, and is the most definitive approach to closing                                   
#   out a request." 

#################### Model #######################

# In elixir, the session (DB connection) is a property of the model..
# There can only be one for all of the listeners below that use it
# See http://elixir.ematia.de/trac/wiki/Recipes/MultipleDatabases
OP=None
tc_metadata = MetaData()
tc_metadata.echo=True
tc_session = scoped_session(sessionmaker(autoflush=True))

def setup_db(db_uri, echo=False, drop=False):
  tc_engine = create_engine(db_uri, echo=echo)
  tc_metadata.bind = tc_engine
  tc_metadata.echo = echo

  setup_all()
  if drop: drop_all()
  create_all()

  if sqlalchemy.__version__ < "0.5.0":
    # DIAF SQLAlchemy. A token gesture at backwards compatibility
    # wouldn't kill you, you know.
    tc_session.add = tc_session.save_or_update
コード例 #2
0
from elixir import *

# Nodes with a ratio below this value will be removed from consideration
# for higher-valued nodes
MIN_RATIO=0.5

NO_FPE=2**-50

#################### Model #######################

# In elixir, the session (DB connection) is a property of the model..
# There can only be one for all of the listeners below that use it
# See http://elixir.ematia.de/trac/wiki/Recipes/MultipleDatabases
OP=None
tc_metadata = MetaData()
tc_metadata.echo=True
tc_session = scoped_session(sessionmaker(autoflush=True))

def setup_db(db_uri, echo=False, drop=False):
  tc_engine = create_engine(db_uri, echo=echo)
  tc_metadata.bind = tc_engine
  tc_metadata.echo = echo

  setup_all()
  if drop: drop_all()
  create_all()

  if sqlalchemy.__version__ < "0.5.0":
    # DIAF SQLAlchemy. A token gesture at backwards compatibility
    # wouldn't kill you, you know.
    tc_session.add = tc_session.save_or_update