Skip to content

Commit b442a0b

Browse files
committed
add aotucommit
1 parent 6604a4d commit b442a0b

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Table of content
1010
- [Requirements](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#requirements)
1111
- [Installation](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#installation)
1212
- [Example](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#example)
13+
- [Parameters](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#parameters)
1314
- [Roadmap](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#roadmap)
1415
- [Resources](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#resources)
1516
- [License](https://github.com/zongzhenh/PyMySQLPool/blob/master/README.md#license)
@@ -49,20 +50,19 @@ mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
4950
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
5051

5152
mysql> INSERT INTO pet
52-
-> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
53+
-> VALUES ("Puffball", "Diane", "hamster", "f", "1999-03-30", NULL);
5354
```
5455

5556
```python
5657
from pymysqlpool.pool import Pool
5758

5859

59-
pool = Pool(host='YOUR_HOST', port='YOUR_PORT', user='YOUR_USER', password='YOUR_PASSWORD',
60-
db='YOUR_DB', min_size=10, max_size=90)
60+
pool = Pool(host=HOST, port=PORT, user=USER, password=PASSWORD, db=DB)
6161
pool.init()
6262

6363
connection = pool.get_conn()
6464
cur = connection.cursor()
65-
cur.execute('SELECT * FROM `pet` WHERE `name`=%s', args=('Puffball', ))
65+
cur.execute('SELECT * FROM `pet` WHERE `name`=%s', args=("Puffball", ))
6666
print(cur.fetchone())
6767

6868
pool.release(connection)
@@ -74,16 +74,41 @@ This example will print:
7474
('Puffball', 'Diane', 'hamster', 'f', datetime.date(1999, 3, 30), None)
7575
```
7676

77+
Support auto-commit mode, as following:
78+
79+
```python
80+
pool = Pool(host=HOST, port=PORT, user=USER, password=PASSWORD, db=DB, autocommit=True)
81+
```
82+
7783
That's all.
7884

85+
## Parameters for the pool initial:
86+
87+
`host`: Host of MySQL server
88+
`port`: Port of MySQL server
89+
`user`: User of MySQL server
90+
`password`: Password of MySQL server
91+
`db`: Database of MySQL server
92+
`charset`: Charset of MySQL server
93+
`cursorclass`: Class of MySQL Cursor
94+
`autocommit`: auto commit mode
95+
`min_size`: Minimum size of connection pool
96+
`max_size`: Maximum size of connection pool
97+
`timeout`: Watting time in the multi-thread environment
98+
`interval`: Statistical cycle time
99+
`stati_mun`: Statistical frequency
100+
`multiple`: Regulation standard
101+
`counter`: Counter
102+
`accumulation`: Statiscal result
103+
79104
## Roadmap
80105

81106
+ [x] Connection Pool
82107
+ [x] Dynamically Create
83108
+ [x] Dynamically Release
84109
+ [ ] Monitor Web Interface
85110

86-
### Resources
111+
## Resources
87112

88113
- [PyMySQL Documenation](https://pymysql.readthedocs.io/en/latest/index.html)
89114
- [MySQL Reference Manuals](https://dev.mysql.com/doc/refman/8.0/en/)

pymysqlpool/pool.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Pool(object):
4646
:param db: Database of MySQL server
4747
:param charset: Charset of MySQL server
4848
:param cursorclass: Class of MySQL Cursor
49+
:param autocommit: auto commit mode
4950
:param min_size: Minimum size of connection pool
5051
:param max_size: Maximum size of connection pool
5152
:param timeout: Watting time in the multi-thread environment
@@ -56,19 +57,31 @@ class Pool(object):
5657
:param accumulation: Statiscal result
5758
"""
5859

59-
def __init__(self, host='localhost', port=3306, user='root',
60-
password=None, db=None, charset='utf8',
60+
def __init__(self,
61+
host='localhost',
62+
port=3306,
63+
user='root',
64+
password=None,
65+
db=None,
66+
charset='utf8',
6167
cursorclass=pymysql.cursors.DictCursor,
62-
min_size=1, max_size=1, timeout=10.0,
63-
interval=600.0, stati_num=3, multiple=4,
64-
counter=0, accumulation=0):
68+
autocommit=False,
69+
min_size=1,
70+
max_size=1,
71+
timeout=10.0,
72+
interval=600.0,
73+
stati_num=3,
74+
multiple=4,
75+
counter=0,
76+
accumulation=0):
6577
self.host = host
6678
self.port = port
6779
self.user = user
6880
self.password = password
6981
self.db = db
7082
self.charset = charset
7183
self.cursorclass = cursorclass
84+
self.autocommit = autocommit
7285

7386
self.min_size = min_size
7487
self.max_size = max_size
@@ -95,7 +108,8 @@ def create_conn(self):
95108
password=self.password,
96109
db=self.db,
97110
charset=self.charset,
98-
cursorclass=self.cursorclass
111+
cursorclass=self.cursorclass,
112+
autocommit=self.autocommit
99113
)
100114
self.unuse_list.add(c)
101115

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pymysql-pooling",
8-
version="0.9.7",
8+
version="0.9.9",
99
author="prprprus",
1010
author_email="[email protected]",
1111
description="pymysql-based database connection pool",

0 commit comments

Comments
 (0)