mysqlib 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mysqlib-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: mysqlib
3
+ Version: 0.1.0
4
+ Summary: Personal Mysql toolkit for python
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: mysql-connector-python>=8.0.24
File without changes
@@ -0,0 +1,7 @@
1
+ [project]
2
+ name = "mysqlib"
3
+ version = "0.1.0"
4
+ description = "Personal Mysql toolkit for python"
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ dependencies = ["mysql-connector-python>=8.0.24"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,52 @@
1
+ # simplemysql/core.py
2
+ from contextlib import contextmanager
3
+ from mysql.connector import pooling
4
+
5
+
6
+ class MySQL:
7
+ def __init__(self, config: dict, pool_size: int = 10, pool_name: str = "pool"):
8
+ """
9
+ Args:
10
+ config : host, port, user, password, database, charset
11
+ pool_size: range 1~32
12
+ """
13
+ self.pool = pooling.MySQLConnectionPool(
14
+ pool_name=pool_name,
15
+ pool_size=pool_size,
16
+ pool_reset_session=True,
17
+ **config,
18
+ )
19
+
20
+ @contextmanager
21
+ def _cursor(self, dictionary=False):
22
+ conn = self.pool.get_connection()
23
+ try:
24
+ cursor = conn.cursor(dictionary=dictionary)
25
+ try:
26
+ yield conn, cursor
27
+ finally:
28
+ cursor.close()
29
+ finally:
30
+ conn.close()
31
+
32
+ def query(self, sql, values=None):
33
+ with self._cursor(dictionary=True) as (_, cur):
34
+ cur.execute(sql, values)
35
+ return cur.fetchall()
36
+
37
+ def execute(self, sql, values=None):
38
+ with self._cursor() as (conn, cur):
39
+ cur.execute(sql, values)
40
+ conn.commit()
41
+ return cur.lastrowid, cur.rowcount
42
+
43
+ def transaction(self, statements):
44
+ with self._cursor() as (conn, cur):
45
+ try:
46
+ for sql, values in statements:
47
+ cur.execute(sql, values)
48
+ conn.commit()
49
+ return cur.lastrowid
50
+ except Exception:
51
+ conn.rollback()
52
+ raise
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: mysqlib
3
+ Version: 0.1.0
4
+ Summary: Personal Mysql toolkit for python
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: mysql-connector-python>=8.0.24
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/mysqlib/__init__.py
4
+ src/mysqlib.egg-info/PKG-INFO
5
+ src/mysqlib.egg-info/SOURCES.txt
6
+ src/mysqlib.egg-info/dependency_links.txt
7
+ src/mysqlib.egg-info/requires.txt
8
+ src/mysqlib.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ mysql-connector-python>=8.0.24
@@ -0,0 +1 @@
1
+ mysqlib