#NEWLINE# def new_session_factory( url = 'sqlite:///:memory:' , reset = False , **kwargs ) : #NEWLINE# #INDENT# 'Create a new session at url' #NEWLINE# if url . startswith ( 'sqlite' ) : #NEWLINE# #INDENT# kwargs . setdefault ( 'connect_args' , { #NEWLINE# #INDENT# 'check_same_thread' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if url . startswith ( 'mysql' ) : #NEWLINE# #INDENT# kwargs . setdefault ( 'pool_recycle' , 60 ) #NEWLINE# #UNINDENT# #UNINDENT# if url . endswith ( ':memory:' ) : #NEWLINE# #INDENT# kwargs . setdefault ( 'poolclass' , StaticPool ) #NEWLINE# #UNINDENT# engine = create_engine ( url , ** kwargs ) #NEWLINE# if engine : #NEWLINE# #INDENT# Base . metadata . drop_all ( engine ) #NEWLINE# #UNINDENT# Base . metadata . create_all ( engine ) #NEWLINE# session_factory = sessionmaker ( bind = engine ) #NEWLINE# return session_factory