Python sqlalchemy.orm.session.sessionmaker() Examples
The following are 17
code examples of sqlalchemy.orm.session.sessionmaker().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.orm.session
, or try the search function
.
Example #1
Source File: test_sql.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #2
Source File: test_sql.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: test_sql.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #4
Source File: test_sql.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: superlocus.py From mikado with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #6
Source File: test_sql.py From elasticintel with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: dao.py From gtfslib-python with GNU General Public License v3.0 | 6 votes |
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")
Example #8
Source File: test_PersistentStoreConnectionSetting.py From tethys with BSD 2-Clause "Simplified" License | 5 votes |
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))
Example #9
Source File: retrieval.py From mikado with GNU Lesser General Public License v3.0 | 5 votes |
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()
Example #10
Source File: db.py From archivebot with MIT License | 5 votes |
def get_session(connection=None): """Get a new db session.""" session = scoped_session(sessionmaker(bind=engine)) return session
Example #11
Source File: SqlQuery.py From PyQt with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.setupUi(self) # sql的拼接字段 self.sql = {} # 数据库连接 self.session = sessionmaker(bind=engine)()
Example #12
Source File: db.py From ultimate-poll-bot with MIT License | 5 votes |
def get_session(connection=None) -> Session: """Get a new db session.""" session = scoped_session(sessionmaker(bind=engine)) return cast(Session, session)
Example #13
Source File: query.py From aws-xray-sdk-python with Apache License 2.0 | 5 votes |
def create_session(self, options): return sessionmaker(class_=XRaySignallingSession, db=self, **options)
Example #14
Source File: db.py From sticker-finder with MIT License | 5 votes |
def get_session(connection=None): """Get a new db session.""" session = scoped_session(sessionmaker(bind=engine)) return session
Example #15
Source File: db.py From pornhub-dl with MIT License | 5 votes |
def get_session(): """Get a new scoped session.""" session = scoped_session(sessionmaker(bind=engine)) return session
Example #16
Source File: metadata.py From gamification-engine with MIT License | 5 votes |
def get_sessionmaker(bind=None): return sessionmaker( extension=ZopeTransactionExtension(), class_=MySession, bind=bind )
Example #17
Source File: database.py From estimators with MIT License | 5 votes |
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))