本文整理匯總了Python中sqlalchemy.orm.session.sessionmaker方法的典型用法代碼示例。如果您正苦於以下問題:Python session.sessionmaker方法的具體用法?Python session.sessionmaker怎麽用?Python session.sessionmaker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.orm.session
的用法示例。
在下文中一共展示了session.sessionmaker方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_temporary_table
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def test_temporary_table(self):
test_data = u'Hello, World!'
expected = DataFrame({'spam': [test_data]})
Base = declarative.declarative_base()
class Temporary(Base):
__tablename__ = 'temp_test'
__table_args__ = {'prefixes': ['TEMPORARY']}
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
spam = sqlalchemy.Column(sqlalchemy.Unicode(30), nullable=False)
Session = sa_session.sessionmaker(bind=self.conn)
session = Session()
with session.transaction:
conn = session.connection()
Temporary.__table__.create(conn)
session.add(Temporary(spam=test_data))
session.flush()
df = sql.read_sql_query(
sql=sqlalchemy.select([Temporary.spam]),
con=conn,
)
tm.assert_frame_equal(df, expected)
示例2: __init__
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def __init__(self, db="", sql_logging=False, schema=None):
if db == "" or db is None:
# In-memory SQLite
connect_url = "sqlite:///"
if "://" in db:
# User has provided a full path
connect_url = db
else:
# Assume a SQLite file
connect_url = "sqlite:///%s" % db
engine = sqlalchemy.create_engine(connect_url, echo=sql_logging)
self._orm = _Orm(engine, schema=schema)
Session = sessionmaker(bind=engine)
self._session = Session()
self._stoptime1 = aliased(StopTime, name="first_stop_time")
self._stoptime2 = aliased(StopTime, name="second_stop_time")
self._transfer_fromstop = aliased(Stop, name="tr_from_stop")
self._transfer_tostop = aliased(Stop, name="tr_to_stop")
示例3: connect_to_db
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def connect_to_db(self, engine):
"""
:param engine: the connection pool
:type engine: Engine
This method will connect to the database using the information
contained in the JSON configuration.
"""
if engine is None:
self.engine = dbutils.connect(self.json_conf)
else:
self.engine = engine
self.sessionmaker = sessionmaker()
self.sessionmaker.configure(bind=self.engine)
self.session = self.sessionmaker()
# @asyncio.coroutine
示例4: __init__
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def __init__(self, url='sqlite:///default.db'):
self.engine = create_engine(
os.environ.get('DATABASE_URL', url),
echo=False
)
self.Session = scoped_session(sessionmaker(
bind=self.engine,
expire_on_commit=False))
示例5: get_sessionmaker
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def get_sessionmaker(bind=None):
return sessionmaker(
extension=ZopeTransactionExtension(),
class_=MySession,
bind=bind
)
示例6: get_session
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def get_session():
"""Get a new scoped session."""
session = scoped_session(sessionmaker(bind=engine))
return session
示例7: get_session
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def get_session(connection=None):
"""Get a new db session."""
session = scoped_session(sessionmaker(bind=engine))
return session
示例8: create_session
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def create_session(self, options):
return sessionmaker(class_=XRaySignallingSession, db=self, **options)
示例9: get_session
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def get_session(connection=None) -> Session:
"""Get a new db session."""
session = scoped_session(sessionmaker(bind=engine))
return cast(Session, session)
示例10: __init__
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setupUi(self)
# sql的拚接字段
self.sql = {}
# 數據庫連接
self.session = sessionmaker(bind=engine)()
示例11: _connect_to_db
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def _connect_to_db(transcript):
"""This method will connect to the database using the information
contained in the JSON configuration.
:param transcript: the Transcript instance
:type transcript: Mikado.loci_objects.transcript.Transcript
"""
transcript.engine = dbutils.connect(
transcript.json_conf, transcript.logger)
transcript.sessionmaker = sessionmaker()
transcript.sessionmaker.configure(bind=transcript.engine)
transcript.session = transcript.sessionmaker()
示例12: test_get_value_as_sessionmaker
# 需要導入模塊: from sqlalchemy.orm import session [as 別名]
# 或者: from sqlalchemy.orm.session import sessionmaker [as 別名]
def test_get_value_as_sessionmaker(self):
ps_cs_setting = self.test_app.settings_set.select_subclasses().get(name='primary')
ps_cs_setting.persistent_store_service = self.pss
ps_cs_setting.save()
# Execute
ret = PersistentStoreConnectionSetting.objects.get(name='primary').get_value(as_sessionmaker=True)
# Check if ret is an instance of sqlalchemy sessionmaker
self.assertIsInstance(ret, sessionmaker)
self.assertEqual('postgresql://foo:password@localhost:5432', str(ret.kw['bind'].url))