Name | django-database-connection-pool JSON |
Version |
0.0.1
JSON |
| download |
home_page | None |
Summary | Database connection pool component library for Django |
upload_time | 2024-07-18 13:45:55 |
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-database-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": null,
"platform": null,
"description": "# django-db-connection-pool\n\n:star: If this project is helpful to you, please light up the star, Thank you:smile:\n\nMySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django,\nBe based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\nWorks fine in multiprocessing and multithreading django project.\n\n* [\u4e2d\u6587\u7248](README_CN.md)\n\n## Quickstart\n\n### Installation\n\nInstall with `pip` with all engines:\n\n```bash\n$ pip install django-db-connection-pool[all]\n```\n\nor select specific engines:\n\n```bash\n$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]\n```\n\nor one of mysql,oracle,postgresql,jdbc\n\n```bash\n$ pip install django-db-connection-pool[oracle]\n```\n\n### Update settings.DATABASES\n\n#### MySQL\n\nchange `django.db.backends.mysql` to `dj_db_conn_pool.backends.mysql`:\n\n```python\nDATABASES = {\n 'default': {\n 'ENGINE': 'dj_db_conn_pool.backends.mysql'\n }\n}\n```\n\n#### Oracle\n\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.oracle`:\n\n```python\nDATABASES = {\n 'default': {\n 'ENGINE': 'dj_db_conn_pool.backends.oracle'\n }\n}\n```\n\n#### PostgreSQL\n\nchange `django.db.backends.postgresql` to `dj_db_conn_pool.backends.postgresql`:\n\n```python\nDATABASES = {\n 'default': {\n 'ENGINE': 'dj_db_conn_pool.backends.postgresql'\n }\n}\n```\n\n#### Pool options(optional)\n\nyou can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`:\n\n```python\nDATABASES = {\n 'default': {\n 'POOL_OPTIONS': {\n 'POOL_SIZE': 10,\n 'MAX_OVERFLOW': 10,\n 'RECYCLE': 24 * 60 * 60\n }\n }\n}\n```\n\n`django-db-connection-pool` has more configuration options\nhere: [PoolContainer.pool_default_params](https://github.com/altairbow/django-db-connection-pool/blob/master/dj_db_conn_pool/core/__init__.py#L13-L20)\n\nHere's the explanation of these options(from SQLAlchemy's Doc):\n\n* **pool_size**: The size of the pool to be maintained,\n defaults to 5. This is the largest number of connections that\n will be kept persistently in the pool. Note that the pool\n begins with no connections; once this number of connections\n is requested, that number of connections will remain.\n `pool_size` can be set to 0 to indicate no size limit; to\n disable pooling, use a :class:`~sqlalchemy.pool.NullPool`\n instead.\n\n* **max_overflow**: The maximum overflow size of the\n pool. When the number of checked-out connections reaches the\n size set in pool_size, additional connections will be\n returned up to this limit. When those additional connections\n are returned to the pool, they are disconnected and\n discarded. It follows then that the total number of\n simultaneous connections the pool will allow is pool_size +\n `max_overflow`, and the total number of \"sleeping\"\n connections the pool will allow is pool_size. `max_overflow`\n can be set to -1 to indicate no overflow limit; no limit\n will be placed on the total number of concurrent\n connections. Defaults to 10.\n\n* **recycle**: If set to a value other than -1, number of seconds\n between connection recycling, which means upon checkout,\n if this timeout is surpassed the connection will be closed\n and replaced with a newly opened connection.\n Defaults to -1.\n\nOr, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:\n\n```python\nimport dj_db_conn_pool\n\ndj_db_conn_pool.setup(pool_size=100, max_overflow=50)\n```\n\n#### multiprocessing environment\n\nIn a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container`\nobject,\nIt means that each process has an independent connection pool, for example:\nThe `POOL_OPTIONS` configuration of database `db1` is`{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }`,\nIf uWSGI starts 8 worker processes, then the total connection pool size of `db1` is `8 * 10`,\nThe maximum number of connections will not exceed `8 * 10 + 8 * 20`\n\n## JDBC\n\nThanks to [JPype](https://github.com/jpype-project/jpype),\ndjango-db-connection-pool can connect to database by jdbc\n\n### Usage\n\n#### Set Java runtime environment\n\n```bash\nexport JAVA_HOME=$PATH_TO_JRE;\nexport CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR\n```\n\n#### Update settings.DATABASES\n\n##### Oracle\n\nchange `django.db.backends.oracle` to `dj_db_conn_pool.backends.jdbc.oracle`:\n\n```python\nDATABASES = {\n 'default': {\n 'ENGINE': 'dj_db_conn_pool.backends.jdbc.oracle'\n }\n}\n```\n\n##### OceanBase\n\nuse `dj_db_conn_pool.backends.jdbc.oceanbase`:\n\n```python\nDATABASES = {\n 'default': {\n 'ENGINE': 'dj_db_conn_pool.backends.jdbc.oceanbase'\n }\n}\n```\n\n### Performing raw SQL queries\n\nJust like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,\nyou can execute raw sql queries like this:\n\n```python\nfrom django.db import connections\n\nwith connections[\"default\"].cursor() as cursor:\n cursor.execute('select name, phone from users where name = %(name)s', params={\"name\": \"Altair\"})\n result = cursor.fetchall()\n```\n\n### Acknowledgments\n- Thanks to all friends who provided PR and suggestions !\n- Thanks to [JetBrains](https://www.jetbrains.com/?from=django-db-connection-pool) for providing development tools for django-db-connection-pool !\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": "0.0.1",
"project_urls": {
"homepage": "https://github.com/daviddelucca/django-db-connection-pool",
"repository": "https://github.com/daviddelucca/django-db-connection-pool"
},
"split_keywords": [
"django",
" db",
" database",
" persistent",
" connection",
" pool",
" pooling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b6e077700c0b0ca6c185118606728ae8ef1e0492f26bc4993653255bd136ec11",
"md5": "8fd8cfb1be97099b6a81e3193870be9c",
"sha256": "49361b526176ad7c97bbd124d10c838d5a225b39f9b001745b7afbcc5e3e9cfe"
},
"downloads": -1,
"filename": "django_database_connection_pool-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8fd8cfb1be97099b6a81e3193870be9c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 19089,
"upload_time": "2024-07-18T13:45:55",
"upload_time_iso_8601": "2024-07-18T13:45:55.966807Z",
"url": "https://files.pythonhosted.org/packages/b6/e0/77700c0b0ca6c185118606728ae8ef1e0492f26bc4993653255bd136ec11/django_database_connection_pool-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-18 13:45:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "daviddelucca",
"github_project": "django-db-connection-pool",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-database-connection-pool"
}