Merge remote-tracking branch 'upstream/master'
This commit is contained in:
+3
-1
@@ -18,12 +18,14 @@ def connect(url=None, schema=None, reflectMetadata=True, engine_kwargs=None):
|
||||
If *url* is not defined it will try to use *DATABASE_URL* from environment variable.
|
||||
Returns an instance of :py:class:`Database <dataset.Database>`. Set *reflectMetadata* to False if you
|
||||
don't want the entire database schema to be pre-loaded. This significantly speeds up
|
||||
connecting to large databases with lots of tables.
|
||||
connecting to large databases with lots of tables. Additionally, *engine_kwargs* will be directly passed to
|
||||
SQLAlchemy, e.g. set *engine_kwargs={'pool_recycle': 3600}* will avoid `DB connection timeout`_.
|
||||
::
|
||||
|
||||
db = dataset.connect('sqlite:///factbook.db')
|
||||
|
||||
.. _SQLAlchemy Engine URL: http://docs.sqlalchemy.org/en/latest/core/engines.html#sqlalchemy.create_engine
|
||||
.. _DB connection timeout: http://docs.sqlalchemy.org/en/latest/core/pooling.html#setting-pool-recycle
|
||||
"""
|
||||
if url is None:
|
||||
url = os.environ.get('DATABASE_URL', url)
|
||||
|
||||
@@ -80,7 +80,7 @@ class Database(object):
|
||||
self.local.must_release = True
|
||||
|
||||
def _release_internal(self):
|
||||
if not hasattr(self.local, 'must_release') and self.local.must_release:
|
||||
if getattr(self.local, 'must_release', None):
|
||||
self.lock.release()
|
||||
self.local.must_release = False
|
||||
|
||||
@@ -141,6 +141,9 @@ class Database(object):
|
||||
set(self.metadata.tables.keys()) | set(self._tables.keys())
|
||||
)
|
||||
|
||||
def __contains__(self, member):
|
||||
return member in self.tables
|
||||
|
||||
def create_table(self, table_name, primary_id='id', primary_type='Integer'):
|
||||
"""
|
||||
Creates a new table. The new table will automatically have an `id` column
|
||||
@@ -253,7 +256,7 @@ class Database(object):
|
||||
"""
|
||||
Run a statement on the database directly, allowing for the
|
||||
execution of arbitrary read/write queries. A query can either be
|
||||
a plain text string, or a `SQLAlchemy expression <http://docs.sqlalchemy.org/ru/latest/core/tutorial.html#selecting>`_. The returned
|
||||
a plain text string, or a `SQLAlchemy expression <http://docs.sqlalchemy.org/en/latest/core/tutorial.html#selecting>`_. The returned
|
||||
iterator will yield each result sequentially.
|
||||
|
||||
Any keyword arguments will be passed into the query to perform
|
||||
|
||||
Reference in New Issue
Block a user