Skip to content

Commit e24c2f5

Browse files
pudoclaude
andcommitted
Document close() and add missing public members to API docs
- Expanded close() docstring - Added "Closing connections" section to quickstart - Added has_table, views, exists to API docs - Removed stale "no way to close connections" note Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4a6bf5f commit e24c2f5

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

dataset/database.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ def __exit__(
212212
self.rollback()
213213

214214
def close(self) -> None:
215-
"""Close database connections. Makes this object unusable."""
215+
"""Close all database connections and dispose of the engine.
216+
217+
Releases all pooled connections and makes this object unusable.
218+
This should be called when the database is no longer needed,
219+
especially in multi-threaded or connection-pooled setups.
220+
"""
216221
with self.lock:
217222
for conn in self.connections.values():
218223
conn.close()

docs/api.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,19 @@ Connecting
77

88
.. autofunction:: dataset.connect
99

10-
Notes
11-
-----
12-
13-
* **dataset** uses SQLAlchemy connection pooling when connecting to the
14-
database. There is no way of explicitly clearing or shutting down the
15-
connections, other than having the dataset instance garbage collected.
16-
1710
Database
1811
--------
1912

2013
.. autoclass:: dataset.Database
21-
:members: tables, get_table, create_table, load_table, query, begin, commit, rollback
14+
:members: tables, views, has_table, get_table, create_table, load_table, query, begin, commit, rollback, close
2215
:special-members:
2316

2417

2518
Table
2619
-----
2720

2821
.. autoclass:: dataset.Table
29-
:members: columns, find, find_one, all, count, distinct, insert, insert_ignore, insert_many, update, update_many, upsert, upsert_many, delete, create_column, create_column_by_example, drop_column, create_index, drop, has_column, has_index
22+
:members: exists, columns, find, find_one, all, count, distinct, insert, insert_ignore, insert_many, update, update_many, upsert, upsert_many, delete, create_column, create_column_by_example, drop_column, create_index, drop, has_column, has_index
3023
:special-members: __len__, __iter__
3124

3225

docs/quickstart.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ Nested transactions are supported too::
9595
with db as tx2:
9696
tx2['user'].insert(dict(name='Jane Doe', age=37, country='France', gender='female'))
9797

98+
Closing connections
99+
-------------------
100+
101+
When you're done with a database, call :py:meth:`close() <dataset.Database.close>`
102+
to release all connections back to the pool and dispose of the engine::
103+
104+
db = dataset.connect('sqlite:///mydb.db')
105+
# ... do work ...
106+
db.close()
107+
108+
This is especially important in multi-threaded applications or when using
109+
connection-pooled databases (PostgreSQL, MySQL), where open connections
110+
can accumulate and exhaust the pool.
98111

99112

100113
Inspecting databases and tables

0 commit comments

Comments
 (0)