Skip to content

Commit 0e56a36

Browse files
committed
Connection options
1 parent a897add commit 0e56a36

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It allows you to make queries using the powerful [SQLAlchemy Core][sqlalchemy-co
1818
expression language, and provides support for PostgreSQL, MySQL, and SQLite.
1919

2020
Databases is suitable for integrating against any async Web framework, such as [Starlette][starlette],
21-
[Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp], [Tornado][tornado], [FastAPI][fastapi],
21+
[Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp], [Tornado][tornado], [FastAPI][fastapi],
2222
or [Bocadillo][bocadillo].
2323

2424
**Requirements**: Python 3.6+
@@ -220,6 +220,13 @@ database = Database('postgresql://localhost/example?ssl=true')
220220
database = Database('mysql://localhost/example?min_size=5&max_size=20')
221221
```
222222

223+
You can also use keyword arguments to pass in any connection options.
224+
Available keyword arguments may differ between database backends.
225+
226+
```python
227+
database = Database('postgresql://localhost/example', ssl=True, min_size=5, max_size=20)
228+
```
229+
223230
## Test isolation
224231

225232
For strict test isolation you will always want to rollback the test database

databases/backends/mysql.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ def _get_connection_kwargs(self) -> dict:
4040
if ssl is not None:
4141
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
4242

43-
kwargs.update(self._options)
43+
for key, value in self._options.items():
44+
# Coerce 'min_size' and 'max_size' for consistency.
45+
if key == 'min_size':
46+
key = 'minsize'
47+
elif key == 'max_size'
48+
key = 'maxsize'
49+
kwargs[key] = value
4450

4551
return kwargs
4652

0 commit comments

Comments
 (0)