當前位置: 首頁>>代碼示例>>Python>>正文


Python session.sessionmaker方法代碼示例

本文整理匯總了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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_sql.py

示例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") 
開發者ID:afimb,項目名稱:gtfslib-python,代碼行數:20,代碼來源:dao.py

示例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 
開發者ID:EI-CoreBioinformatics,項目名稱:mikado,代碼行數:22,代碼來源:superlocus.py

示例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)) 
開發者ID:fridiculous,項目名稱:estimators,代碼行數:11,代碼來源:database.py

示例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
    ) 
開發者ID:ActiDoo,項目名稱:gamification-engine,代碼行數:8,代碼來源:metadata.py

示例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 
開發者ID:Nukesor,項目名稱:pornhub-dl,代碼行數:6,代碼來源:db.py

示例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 
開發者ID:Nukesor,項目名稱:sticker-finder,代碼行數:6,代碼來源:db.py

示例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) 
開發者ID:aws,項目名稱:aws-xray-sdk-python,代碼行數:4,代碼來源:query.py

示例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) 
開發者ID:Nukesor,項目名稱:ultimate-poll-bot,代碼行數:6,代碼來源:db.py

示例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)() 
開發者ID:PyQt5,項目名稱:PyQt,代碼行數:9,代碼來源:SqlQuery.py

示例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() 
開發者ID:EI-CoreBioinformatics,項目名稱:mikado,代碼行數:17,代碼來源:retrieval.py

示例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)) 
開發者ID:tethysplatform,項目名稱:tethys,代碼行數:13,代碼來源:test_PersistentStoreConnectionSetting.py


注:本文中的sqlalchemy.orm.session.sessionmaker方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。