Name | django-db-connection-pool JSON |
Version |
1.2.5
JSON |
| download |
home_page | None |
Summary | Database connection pool component library for Django |
upload_time | 2024-04-06 10:00:49 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.4 |
license | MIT License Copyright (c) 2019 Altair Bow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
django
db
database
persistent
connection
pool
pooling
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# django-db-connection-pool
:star: If this project is helpful to you, please light up the star, Thank you:smile:
MySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django,
Be based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).
Works fine in multiprocessing and multithreading django project.
* [中文版](README_CN.md)
## Quickstart
### Installation
Install with `pip` with all engines:
```bash
$ pip install django-db-connection-pool[all]
```
or select specific engines:
```bash
$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]
```
or one of mysql,oracle,postgresql,jdbc
```bash
$ pip install django-db-connection-pool[oracle]
```
### Update settings.DATABASES
#### MySQL
change `django.db.backends.mysql` to `dj_db_conn_pool.backends.mysql`:
```python
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.mysql'
}
}
```
#### Oracle
change `django.db.backends.oracle` to `dj_db_conn_pool.backends.oracle`:
```python
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.oracle'
}
}
```
#### PostgreSQL
change `django.db.backends.postgresql` to `dj_db_conn_pool.backends.postgresql`:
```python
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.postgresql'
}
}
```
#### Pool options(optional)
you can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`:
```python
DATABASES = {
'default': {
'POOL_OPTIONS': {
'POOL_SIZE': 10,
'MAX_OVERFLOW': 10,
'RECYCLE': 24 * 60 * 60
}
}
}
```
`django-db-connection-pool` has more configuration options
here: [PoolContainer.pool_default_params](https://github.com/altairbow/django-db-connection-pool/blob/master/dj_db_conn_pool/core/__init__.py#L13-L20)
Here's the explanation of these options(from SQLAlchemy's Doc):
* **pool_size**: The size of the pool to be maintained,
defaults to 5. This is the largest number of connections that
will be kept persistently in the pool. Note that the pool
begins with no connections; once this number of connections
is requested, that number of connections will remain.
`pool_size` can be set to 0 to indicate no size limit; to
disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
instead.
* **max_overflow**: The maximum overflow size of the
pool. When the number of checked-out connections reaches the
size set in pool_size, additional connections will be
returned up to this limit. When those additional connections
are returned to the pool, they are disconnected and
discarded. It follows then that the total number of
simultaneous connections the pool will allow is pool_size +
`max_overflow`, and the total number of "sleeping"
connections the pool will allow is pool_size. `max_overflow`
can be set to -1 to indicate no overflow limit; no limit
will be placed on the total number of concurrent
connections. Defaults to 10.
* **recycle**: If set to a value other than -1, number of seconds
between connection recycling, which means upon checkout,
if this timeout is surpassed the connection will be closed
and replaced with a newly opened connection.
Defaults to -1.
Or, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:
```python
import dj_db_conn_pool
dj_db_conn_pool.setup(pool_size=100, max_overflow=50)
```
#### multiprocessing environment
In a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container`
object,
It means that each process has an independent connection pool, for example:
The `POOL_OPTIONS` configuration of database `db1` is`{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }`,
If uWSGI starts 8 worker processes, then the total connection pool size of `db1` is `8 * 10`,
The maximum number of connections will not exceed `8 * 10 + 8 * 20`
## JDBC
Thanks to [JPype](https://github.com/jpype-project/jpype),
django-db-connection-pool can connect to database by jdbc
### Usage
#### Set Java runtime environment
```bash
export JAVA_HOME=$PATH_TO_JRE;
export CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR
```
#### Update settings.DATABASES
##### Oracle
change `django.db.backends.oracle` to `dj_db_conn_pool.backends.jdbc.oracle`:
```python
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.jdbc.oracle'
}
}
```
##### OceanBase
use `dj_db_conn_pool.backends.jdbc.oceanbase`:
```python
DATABASES = {
'default': {
'ENGINE': 'dj_db_conn_pool.backends.jdbc.oceanbase'
}
}
```
### Performing raw SQL queries
Just like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,
you can execute raw sql queries like this:
```python
from django.db import connections
with connections["default"].cursor() as cursor:
cursor.execute('select name, phone from users where name = %(name)s', params={"name": "Altair"})
result = cursor.fetchall()
```
### Acknowledgments
- Thanks to all friends who provided PR and suggestions !
- Thanks to [JetBrains](https://www.jetbrains.com/?from=django-db-connection-pool) for providing development tools for django-db-connection-pool !
Raw data
{
"_id": null,
"home_page": null,
"name": "django-db-connection-pool",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": null,
"keywords": "django, db, database, persistent, connection, pool, pooling",
"author": null,
"author_email": "Altair Bow <altair.bow@foxmail.com>",
"download_url": "https://files.pythonhosted.org/packages/38/5c/e66057ac68028f6172f381125585125cea938a1e16a18a4ce25cb90fd35b/django-db-connection-pool-1.2.5.tar.gz",
"platform": null,
"description": "# django-db-connection-pool\r\n\r\n:star: If this project is helpful to you, please light up the star, Thank you:smile:\r\n\r\nMySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django,\r\nBe based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\nWorks fine in multiprocessing and multithreading django project.\r\n\r\n* [\u4e2d\u6587\u7248](README_CN.md)\r\n\r\n## Quickstart\r\n\r\n### Installation\r\n\r\nInstall with `pip` with all engines:\r\n\r\n```bash\r\n$ pip install django-db-connection-pool[all]\r\n```\r\n\r\nor select specific engines:\r\n\r\n```bash\r\n$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]\r\n```\r\n\r\nor one of mysql,oracle,postgresql,jdbc\r\n\r\n```bash\r\n$ pip install django-db-connection-pool[oracle]\r\n```\r\n\r\n### Update settings.DATABASES\r\n\r\n#### MySQL\r\n\r\nchange `django.db.backends.mysql` to `dj_db_conn_pool.backends.mysql`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'dj_db_conn_pool.backends.mysql'\r\n }\r\n}\r\n```\r\n\r\n#### Oracle\r\n\r\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.oracle`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'dj_db_conn_pool.backends.oracle'\r\n }\r\n}\r\n```\r\n\r\n#### PostgreSQL\r\n\r\nchange `django.db.backends.postgresql` to `dj_db_conn_pool.backends.postgresql`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'dj_db_conn_pool.backends.postgresql'\r\n }\r\n}\r\n```\r\n\r\n#### Pool options(optional)\r\n\r\nyou can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'POOL_OPTIONS': {\r\n 'POOL_SIZE': 10,\r\n 'MAX_OVERFLOW': 10,\r\n 'RECYCLE': 24 * 60 * 60\r\n }\r\n }\r\n}\r\n```\r\n\r\n`django-db-connection-pool` has more configuration options\r\nhere: [PoolContainer.pool_default_params](https://github.com/altairbow/django-db-connection-pool/blob/master/dj_db_conn_pool/core/__init__.py#L13-L20)\r\n\r\nHere's the explanation of these options(from SQLAlchemy's Doc):\r\n\r\n* **pool_size**: The size of the pool to be maintained,\r\n defaults to 5. This is the largest number of connections that\r\n will be kept persistently in the pool. Note that the pool\r\n begins with no connections; once this number of connections\r\n is requested, that number of connections will remain.\r\n `pool_size` can be set to 0 to indicate no size limit; to\r\n disable pooling, use a :class:`~sqlalchemy.pool.NullPool`\r\n instead.\r\n\r\n* **max_overflow**: The maximum overflow size of the\r\n pool. When the number of checked-out connections reaches the\r\n size set in pool_size, additional connections will be\r\n returned up to this limit. When those additional connections\r\n are returned to the pool, they are disconnected and\r\n discarded. It follows then that the total number of\r\n simultaneous connections the pool will allow is pool_size +\r\n `max_overflow`, and the total number of \"sleeping\"\r\n connections the pool will allow is pool_size. `max_overflow`\r\n can be set to -1 to indicate no overflow limit; no limit\r\n will be placed on the total number of concurrent\r\n connections. Defaults to 10.\r\n\r\n* **recycle**: If set to a value other than -1, number of seconds\r\n between connection recycling, which means upon checkout,\r\n if this timeout is surpassed the connection will be closed\r\n and replaced with a newly opened connection.\r\n Defaults to -1.\r\n\r\nOr, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:\r\n\r\n```python\r\nimport dj_db_conn_pool\r\n\r\ndj_db_conn_pool.setup(pool_size=100, max_overflow=50)\r\n```\r\n\r\n#### multiprocessing environment\r\n\r\nIn a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container`\r\nobject,\r\nIt means that each process has an independent connection pool, for example:\r\nThe `POOL_OPTIONS` configuration of database `db1` is`{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }`,\r\nIf uWSGI starts 8 worker processes, then the total connection pool size of `db1` is `8 * 10`,\r\nThe maximum number of connections will not exceed `8 * 10 + 8 * 20`\r\n\r\n## JDBC\r\n\r\nThanks to [JPype](https://github.com/jpype-project/jpype),\r\ndjango-db-connection-pool can connect to database by jdbc\r\n\r\n### Usage\r\n\r\n#### Set Java runtime environment\r\n\r\n```bash\r\nexport JAVA_HOME=$PATH_TO_JRE;\r\nexport CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR\r\n```\r\n\r\n#### Update settings.DATABASES\r\n\r\n##### Oracle\r\n\r\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.jdbc.oracle`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'dj_db_conn_pool.backends.jdbc.oracle'\r\n }\r\n}\r\n```\r\n\r\n##### OceanBase\r\n\r\nuse `dj_db_conn_pool.backends.jdbc.oceanbase`:\r\n\r\n```python\r\nDATABASES = {\r\n 'default': {\r\n 'ENGINE': 'dj_db_conn_pool.backends.jdbc.oceanbase'\r\n }\r\n}\r\n```\r\n\r\n### Performing raw SQL queries\r\n\r\nJust like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,\r\nyou can execute raw sql queries like this:\r\n\r\n```python\r\nfrom django.db import connections\r\n\r\nwith connections[\"default\"].cursor() as cursor:\r\n cursor.execute('select name, phone from users where name = %(name)s', params={\"name\": \"Altair\"})\r\n result = cursor.fetchall()\r\n```\r\n\r\n### Acknowledgments\r\n- Thanks to all friends who provided PR and suggestions !\r\n- Thanks to [JetBrains](https://www.jetbrains.com/?from=django-db-connection-pool) for providing development tools for django-db-connection-pool !\r\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2019 Altair Bow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Database connection pool component library for Django",
"version": "1.2.5",
"project_urls": {
"homepage": "https://github.com/altairbow/django-db-connection-pool",
"repository": "https://github.com/altairbow/django-db-connection-pool"
},
"split_keywords": [
"django",
" db",
" database",
" persistent",
" connection",
" pool",
" pooling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "be261feaa26ddc78e5a756522fd96ace91b38269eafc5a740114b44ac75851fb",
"md5": "c1652afd8d9702d0099eb695039d7cc2",
"sha256": "33ec059b8b81801ac23c11903827e89ade5c1383774b0848773ac08b72bc65e6"
},
"downloads": -1,
"filename": "django_db_connection_pool-1.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1652afd8d9702d0099eb695039d7cc2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 19194,
"upload_time": "2024-04-06T10:00:47",
"upload_time_iso_8601": "2024-04-06T10:00:47.306453Z",
"url": "https://files.pythonhosted.org/packages/be/26/1feaa26ddc78e5a756522fd96ace91b38269eafc5a740114b44ac75851fb/django_db_connection_pool-1.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "385ce66057ac68028f6172f381125585125cea938a1e16a18a4ce25cb90fd35b",
"md5": "493e3889de65ff9c9eff3c4ef67c7c13",
"sha256": "693d588c98689415b87a43aa2dc6fc66a2fca36519e889332811867a8579768b"
},
"downloads": -1,
"filename": "django-db-connection-pool-1.2.5.tar.gz",
"has_sig": false,
"md5_digest": "493e3889de65ff9c9eff3c4ef67c7c13",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 14160,
"upload_time": "2024-04-06T10:00:49",
"upload_time_iso_8601": "2024-04-06T10:00:49.153869Z",
"url": "https://files.pythonhosted.org/packages/38/5c/e66057ac68028f6172f381125585125cea938a1e16a18a4ce25cb90fd35b/django-db-connection-pool-1.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-06 10:00:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "altairbow",
"github_project": "django-db-connection-pool",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-db-connection-pool"
}