Skip to content

Commit 9ff28af

Browse files
committed
update readme
1 parent 82da39c commit 9ff28af

File tree

3 files changed

+120
-71
lines changed

3 files changed

+120
-71
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ A clear and concise description of what the bug is.
1414
Switch to django's backend (`django.db.backends.xxx`), does the problem reproduce?
1515

1616
**Environment**
17-
- Python Version:
18-
- Django Version:
17+
18+
- Python Version:
19+
- Django Version:
1920

2021
**Traceback**
2122
Post traceback here.

README.md

+63-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# django-db-connection-pool
22

3-
*:star: If this project is helpful to you, please light up the star, Thank you:smile:*
3+
:star: If this project is helpful to you, please light up the star, Thank you:smile:
44

5-
MySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django,
6-
Be based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).
5+
MySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool components for Django,
6+
Be based on [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).
77
Works fine in multiprocessing and multithreading django project.
88

99
* [中文版](README_CN.md)
@@ -13,22 +13,29 @@ Works fine in multiprocessing and multithreading django project.
1313
### Installation
1414

1515
Install with `pip` with all engines:
16+
1617
```bash
1718
$ pip install django-db-connection-pool[all]
1819
```
20+
1921
or select specific engines:
22+
2023
```bash
2124
$ pip install django-db-connection-pool[mysql,oracle,postgresql,jdbc]
2225
```
26+
2327
or one of mysql,oracle,postgresql,jdbc
28+
2429
```bash
2530
$ pip install django-db-connection-pool[oracle]
2631
```
2732

2833
### Update settings.DATABASES
2934

30-
#### MySQL
35+
#### MySQL
36+
3137
change `django.db.backends.mysql` to `dj_db_conn_pool.backends.mysql`:
38+
3239
```python
3340
DATABASES = {
3441
'default': {
@@ -37,8 +44,10 @@ DATABASES = {
3744
}
3845
```
3946

40-
#### Oracle
47+
#### Oracle
48+
4149
change `django.db.backends.oracle` to `dj_db_conn_pool.backends.oracle`:
50+
4251
```python
4352
DATABASES = {
4453
'default': {
@@ -47,8 +56,10 @@ DATABASES = {
4756
}
4857
```
4958

50-
#### PostgreSQL
59+
#### PostgreSQL
60+
5161
change `django.db.backends.postgresql` to `dj_db_conn_pool.backends.postgresql`:
62+
5263
```python
5364
DATABASES = {
5465
'default': {
@@ -58,82 +69,91 @@ DATABASES = {
5869
```
5970

6071
#### Pool options(optional)
72+
6173
you can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`:
6274

6375
```python
6476
DATABASES = {
6577
'default': {
66-
'POOL_OPTIONS' : {
78+
'POOL_OPTIONS': {
6779
'POOL_SIZE': 10,
6880
'MAX_OVERFLOW': 10,
6981
'RECYCLE': 24 * 60 * 60
7082
}
71-
}
72-
}
83+
}
84+
}
7385
```
7486

75-
`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)
76-
87+
`django-db-connection-pool` has more configuration options
88+
here: [PoolContainer.pool_default_params](https://github.com/altairbow/django-db-connection-pool/blob/master/dj_db_conn_pool/core/__init__.py#L13-L20)
89+
7790
Here's the explanation of these options(from SQLAlchemy's Doc):
7891

7992
* **pool_size**: The size of the pool to be maintained,
80-
defaults to 5. This is the largest number of connections that
81-
will be kept persistently in the pool. Note that the pool
82-
begins with no connections; once this number of connections
83-
is requested, that number of connections will remain.
84-
`pool_size` can be set to 0 to indicate no size limit; to
85-
disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
86-
instead.
93+
defaults to 5. This is the largest number of connections that
94+
will be kept persistently in the pool. Note that the pool
95+
begins with no connections; once this number of connections
96+
is requested, that number of connections will remain.
97+
`pool_size` can be set to 0 to indicate no size limit; to
98+
disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
99+
instead.
87100

88101
* **max_overflow**: The maximum overflow size of the
89-
pool. When the number of checked-out connections reaches the
90-
size set in pool_size, additional connections will be
91-
returned up to this limit. When those additional connections
92-
are returned to the pool, they are disconnected and
93-
discarded. It follows then that the total number of
94-
simultaneous connections the pool will allow is pool_size +
95-
`max_overflow`, and the total number of "sleeping"
96-
connections the pool will allow is pool_size. `max_overflow`
97-
can be set to -1 to indicate no overflow limit; no limit
98-
will be placed on the total number of concurrent
99-
connections. Defaults to 10.
100-
101-
* **recycle**: If set to a value other than -1, number of seconds
102-
between connection recycling, which means upon checkout,
103-
if this timeout is surpassed the connection will be closed
104-
and replaced with a newly opened connection.
105-
Defaults to -1.
102+
pool. When the number of checked-out connections reaches the
103+
size set in pool_size, additional connections will be
104+
returned up to this limit. When those additional connections
105+
are returned to the pool, they are disconnected and
106+
discarded. It follows then that the total number of
107+
simultaneous connections the pool will allow is pool_size +
108+
`max_overflow`, and the total number of "sleeping"
109+
connections the pool will allow is pool_size. `max_overflow`
110+
can be set to -1 to indicate no overflow limit; no limit
111+
will be placed on the total number of concurrent
112+
connections. Defaults to 10.
113+
114+
* **recycle**: If set to a value other than -1, number of seconds
115+
between connection recycling, which means upon checkout,
116+
if this timeout is surpassed the connection will be closed
117+
and replaced with a newly opened connection.
118+
Defaults to -1.
106119

107120
Or, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:
108121

109122
```python
110123
import dj_db_conn_pool
124+
111125
dj_db_conn_pool.setup(pool_size=100, max_overflow=50)
112126
```
113127

114128
#### multiprocessing environment
115-
In a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container` object,
116-
It means that each process has an independent connection pool, for example:
129+
130+
In a multiprocessing environment, such as uWSGI, each process will have its own `dj_db_conn_pool.core:pool_container`
131+
object,
132+
It means that each process has an independent connection pool, for example:
117133
The `POOL_OPTIONS` configuration of database `db1` is`{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 }`,
118134
If uWSGI starts 8 worker processes, then the total connection pool size of `db1` is `8 * 10`,
119135
The maximum number of connections will not exceed `8 * 10 + 8 * 20`
120136

121-
122137
## JDBC
138+
123139
Thanks to [JPype](https://github.com/jpype-project/jpype),
124140
django-db-connection-pool can connect to database by jdbc
125141

126142
### Usage
143+
127144
#### Set Java runtime environment
145+
128146
```bash
129147
export JAVA_HOME=$PATH_TO_JRE;
130148
export CLASSPATH=$PATH_RO_JDBC_DRIVER_JAR
131149
```
132150

133151
#### Update settings.DATABASES
152+
134153
##### Oracle
135154

136155
change `django.db.backends.oracle` to `dj_db_conn_pool.backends.jdbc.oracle`:
156+
137157
```python
138158
DATABASES = {
139159
'default': {
@@ -143,7 +163,9 @@ DATABASES = {
143163
```
144164

145165
##### OceanBase
166+
146167
use `dj_db_conn_pool.backends.jdbc.oceanbase`:
168+
147169
```python
148170
DATABASES = {
149171
'default': {
@@ -153,8 +175,10 @@ DATABASES = {
153175
```
154176

155177
### Performing raw SQL queries
156-
Just like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,
178+
179+
Just like django's built-in backends, all JDBC backends support named parameters in raw SQL queries,
157180
you can execute raw sql queries like this:
181+
158182
```python
159183
from django.db import connections
160184

0 commit comments

Comments
 (0)