Skip to content

Commit 0301b71

Browse files
authored
Merge pull request #295 from someoneiscoding/master
MysqlDB#__init__ 增加 set_session 参数
2 parents d84c780 + aa9c681 commit 0301b71

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

feapder/db/mysqldb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def wapper(*args, **kwargs):
4141

4242
class MysqlDB:
4343
def __init__(
44-
self, ip=None, port=None, db=None, user_name=None, user_pass=None, charset="utf8mb4", **kwargs
44+
self, ip=None, port=None, db=None, user_name=None, user_pass=None, charset="utf8mb4", set_session=None, **kwargs
4545
):
4646
# 可能会改setting中的值,所以此处不能直接赋值为默认值,需要后加载赋值
4747
if not ip:
@@ -69,7 +69,9 @@ def __init__(
6969
passwd=user_pass,
7070
db=db,
7171
charset=charset,
72+
setsession=set_session,
7273
cursorclass=cursors.SSCursor,
74+
**kwargs
7375
) # cursorclass 使用服务的游标,默认的在多线程下大批量插入数据会使内存递增
7476

7577
except Exception as e:

tests/test_mysqldb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33

44
db = MysqlDB(
5-
ip="localhost", port=3306, db="feapder", user_name="feapder", user_pass="feapder123"
5+
ip="localhost", port=3306, db="feapder", user_name="feapder", user_pass="feapder123", set_session=["SET time_zone='+08:00'"]
66
)
77

8-
MysqlDB.from_url("mysql://feapder:feapder123@localhost:3306/feapder?charset=utf8mb4")
8+
MysqlDB.from_url("mysql://feapder:feapder123@localhost:3306/feapder?charset=utf8mb4")
9+
10+
result = db.find("SELECT @@global.time_zone, @@session.time_zone, date_format(NOW(), '%Y-%m-%d %H:%i:%s')")
11+
print(f"Database timezone info: {result}")

0 commit comments

Comments
 (0)