lesscode-database 0.0.8__tar.gz → 0.0.10__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.
- lesscode_database-0.0.8/README.md → lesscode_database-0.0.10/PKG-INFO +24 -1
- lesscode_database-0.0.8/PKG-INFO → lesscode_database-0.0.10/README.md +11 -14
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/connect_pool.py +130 -17
- lesscode_database-0.0.10/lesscode_database/version.py +1 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/PKG-INFO +12 -2
- lesscode_database-0.0.8/lesscode_database/version.py +0 -1
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/LICENSE +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/__init__.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/connection_info.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/db_options.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/db_request.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/ds_helper.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/dynamic_import_package.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/mongo_base_model.py +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/SOURCES.txt +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/dependency_links.txt +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/top_level.txt +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/setup.cfg +0 -0
- {lesscode_database-0.0.8 → lesscode_database-0.0.10}/setup.py +0 -0
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lesscode_database
|
|
3
|
+
Version: 0.0.10
|
|
4
|
+
Summary: lesscode_database是数据库连接工具包
|
|
5
|
+
Author: navysummer
|
|
6
|
+
Author-email: navysummer@yeah.net
|
|
7
|
+
Platform: python
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
1
14
|
# lesscode_database
|
|
2
15
|
|
|
3
16
|
数据库连接工具包
|
|
@@ -44,13 +57,15 @@ db_options.conn_list = [
|
|
|
44
57
|
ConnectionInfo(dialect="redis", name="redis", host="127.0.0.1", port=6379, user=None,
|
|
45
58
|
password=None, db_name=1, enable=False, async_enable=True),
|
|
46
59
|
# sqlalchemy 异步支持mysql,postgresql,tidb,ocean_base,doris;
|
|
47
|
-
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle
|
|
60
|
+
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle,dm
|
|
48
61
|
ConnectionInfo(dialect="sqlalchemy", name="sqlalchemy", host="127.0.0.1", port=3306, user="root",
|
|
49
62
|
password="root", db_name="test", enable=False, async_enable=False, params={"db_type": "mysql"}),
|
|
50
63
|
ConnectionInfo(dialect="neo4j", name="neo4j", host="127.0.0.1", port=7687, user="neo4j",
|
|
51
64
|
password="neo4j", db_name=None, enable=False, async_enable=True),
|
|
52
65
|
ConnectionInfo(dialect="clickhouse", name="clickhouse", dsn="clickhouse://localhost", host="127.0.0.1", port=9000,
|
|
53
66
|
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
67
|
+
ConnectionInfo(dialect="dm", name="dm", dsn=None, host="127.0.0.1", port=5236,
|
|
68
|
+
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
54
69
|
|
|
55
70
|
]
|
|
56
71
|
|
|
@@ -345,4 +360,12 @@ async def async_esapi_test():
|
|
|
345
360
|
loop = asyncio.get_event_loop()
|
|
346
361
|
loop.run_until_complete(async_esapi_test())
|
|
347
362
|
|
|
363
|
+
|
|
364
|
+
# 达梦数据库 同步测试
|
|
365
|
+
with DsHelper("dm").pool.dedicated_connection() as conn:
|
|
366
|
+
with conn.cursor() as cursor:
|
|
367
|
+
cursor.execute('SELECT 1')
|
|
368
|
+
print(cursor.fetchall())
|
|
369
|
+
|
|
370
|
+
|
|
348
371
|
```
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: lesscode_database
|
|
3
|
-
Version: 0.0.8
|
|
4
|
-
Summary: lesscode_database是数据库连接工具包
|
|
5
|
-
Author: navysummer
|
|
6
|
-
Author-email: navysummer@yeah.net
|
|
7
|
-
Platform: python
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.6
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE
|
|
13
|
-
|
|
14
1
|
# lesscode_database
|
|
15
2
|
|
|
16
3
|
数据库连接工具包
|
|
@@ -57,13 +44,15 @@ db_options.conn_list = [
|
|
|
57
44
|
ConnectionInfo(dialect="redis", name="redis", host="127.0.0.1", port=6379, user=None,
|
|
58
45
|
password=None, db_name=1, enable=False, async_enable=True),
|
|
59
46
|
# sqlalchemy 异步支持mysql,postgresql,tidb,ocean_base,doris;
|
|
60
|
-
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle
|
|
47
|
+
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle,dm
|
|
61
48
|
ConnectionInfo(dialect="sqlalchemy", name="sqlalchemy", host="127.0.0.1", port=3306, user="root",
|
|
62
49
|
password="root", db_name="test", enable=False, async_enable=False, params={"db_type": "mysql"}),
|
|
63
50
|
ConnectionInfo(dialect="neo4j", name="neo4j", host="127.0.0.1", port=7687, user="neo4j",
|
|
64
51
|
password="neo4j", db_name=None, enable=False, async_enable=True),
|
|
65
52
|
ConnectionInfo(dialect="clickhouse", name="clickhouse", dsn="clickhouse://localhost", host="127.0.0.1", port=9000,
|
|
66
53
|
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
54
|
+
ConnectionInfo(dialect="dm", name="dm", dsn=None, host="127.0.0.1", port=5236,
|
|
55
|
+
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
67
56
|
|
|
68
57
|
]
|
|
69
58
|
|
|
@@ -358,4 +347,12 @@ async def async_esapi_test():
|
|
|
358
347
|
loop = asyncio.get_event_loop()
|
|
359
348
|
loop.run_until_complete(async_esapi_test())
|
|
360
349
|
|
|
350
|
+
|
|
351
|
+
# 达梦数据库 同步测试
|
|
352
|
+
with DsHelper("dm").pool.dedicated_connection() as conn:
|
|
353
|
+
with conn.cursor() as cursor:
|
|
354
|
+
cursor.execute('SELECT 1')
|
|
355
|
+
print(cursor.fetchall())
|
|
356
|
+
|
|
357
|
+
|
|
361
358
|
```
|
|
@@ -657,13 +657,52 @@ class Pool:
|
|
|
657
657
|
@staticmethod
|
|
658
658
|
def sync_create_clickhouse_pool(conn_info: ConnectionInfo):
|
|
659
659
|
try:
|
|
660
|
-
|
|
660
|
+
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
661
|
+
except ImportError:
|
|
662
|
+
raise Exception(f"DBUtils is not exist,run:pip install DBUtils==3.0.2")
|
|
663
|
+
try:
|
|
664
|
+
clickhouse_driver = importlib.import_module("clickhouse_driver")
|
|
665
|
+
except ImportError:
|
|
666
|
+
raise Exception(f"clickhouse_driver is not exist,run:pip install clickhouse_driver")
|
|
667
|
+
params = conn_info.params
|
|
668
|
+
if not isinstance(params, dict):
|
|
669
|
+
params = dict()
|
|
670
|
+
|
|
671
|
+
pool = pooled_db.PooledDB(creator=clickhouse_driver.connect, host=conn_info.host, port=conn_info.port,
|
|
672
|
+
user=conn_info.user,
|
|
673
|
+
password=conn_info.password, database=conn_info.db_name or "default",
|
|
674
|
+
**params)
|
|
675
|
+
return pool
|
|
676
|
+
|
|
677
|
+
@staticmethod
|
|
678
|
+
def sync_create_dm_pool(conn_info: ConnectionInfo):
|
|
679
|
+
try:
|
|
680
|
+
dmPython = importlib.import_module("dmPython")
|
|
681
|
+
except ImportError:
|
|
682
|
+
raise Exception(f"dmPython is not exist,run:pip install dmPython")
|
|
683
|
+
try:
|
|
684
|
+
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
661
685
|
except ImportError:
|
|
662
|
-
raise
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
686
|
+
raise Exception(f"DBUtils is not exist,run:pip install DBUtils==3.0.2")
|
|
687
|
+
params = conn_info.params
|
|
688
|
+
if not isinstance(params, dict):
|
|
689
|
+
params = dict()
|
|
690
|
+
blocking = params.pop("blocking", True)
|
|
691
|
+
mincached = params.pop("mincached", conn_info.min_size)
|
|
692
|
+
maxusage = params.pop("maxusage", conn_info.min_size)
|
|
693
|
+
maxshared = params.pop("maxshared", conn_info.max_size)
|
|
694
|
+
maxcached = params.pop("maxcached", conn_info.max_size)
|
|
695
|
+
ping = params.pop("ping", 1)
|
|
696
|
+
autocommit = params.pop("autocommit", True)
|
|
697
|
+
pool = pooled_db.PooledDB(creator=dmPython, host=conn_info.host, port=conn_info.port,
|
|
698
|
+
user=conn_info.user,
|
|
699
|
+
password=conn_info.password, schema=conn_info.db_name,
|
|
700
|
+
mincached=mincached, blocking=blocking, maxusage=maxusage,
|
|
701
|
+
maxshared=maxshared, maxcached=maxcached,
|
|
702
|
+
ping=ping, maxconnections=conn_info.max_size,
|
|
703
|
+
autoCommit=autocommit,
|
|
704
|
+
**params)
|
|
705
|
+
return pool
|
|
667
706
|
|
|
668
707
|
@staticmethod
|
|
669
708
|
def create_sqlalchemy_pool(conn_info: ConnectionInfo):
|
|
@@ -725,10 +764,10 @@ class Pool:
|
|
|
725
764
|
:param conn_info: 连接信息
|
|
726
765
|
:return:
|
|
727
766
|
"""
|
|
767
|
+
db_type = "mysql"
|
|
728
768
|
if conn_info.dsn:
|
|
729
769
|
url = conn_info.dsn
|
|
730
770
|
else:
|
|
731
|
-
db_type = "mysql"
|
|
732
771
|
if conn_info.params:
|
|
733
772
|
if conn_info.params.get("db_type"):
|
|
734
773
|
db_type = conn_info.params.pop("db_type")
|
|
@@ -762,25 +801,87 @@ class Pool:
|
|
|
762
801
|
url = "oracle+cx_oracle://{}:{}@{}:{}/{}?charset=utf8mb4".format(
|
|
763
802
|
conn_info.user, conn_info.password, conn_info.host, conn_info.port,
|
|
764
803
|
conn_info.db_name)
|
|
804
|
+
elif db_type == "dm":
|
|
805
|
+
url = 'dm+dmPython://{}:{}@{}:{}'.format(
|
|
806
|
+
conn_info.user, conn_info.password, conn_info.host, conn_info.port)
|
|
765
807
|
else:
|
|
766
808
|
raise ImportError("UNSUPPORTED DB TYPE")
|
|
767
809
|
try:
|
|
768
810
|
sqlalchemy = importlib.import_module("sqlalchemy")
|
|
769
811
|
except ImportError:
|
|
770
812
|
raise ImportError(f"sqlalchemy is not exist,run:pip install sqlalchemy")
|
|
771
|
-
|
|
772
|
-
|
|
813
|
+
params = conn_info.params
|
|
814
|
+
if not params:
|
|
815
|
+
params = dict()
|
|
816
|
+
echo = params.pop("echo", True)
|
|
817
|
+
pool_recycle = params.pop("pool_recycle", 3600)
|
|
818
|
+
max_overflow = params.pop("max_overflow", 0)
|
|
819
|
+
pool_timeout = params.pop("pool_timeout", 10)
|
|
820
|
+
pool_pre_ping = params.pop("pool_pre_ping", False)
|
|
821
|
+
if conn_info.db_name and db_type=="dm":
|
|
822
|
+
if "connect_args" not in params:
|
|
823
|
+
params["connect_args"] = {"schema": conn_info.db_name}
|
|
824
|
+
else:
|
|
825
|
+
params["connect_args"]["schema"] = conn_info.db_name
|
|
826
|
+
|
|
827
|
+
engine = sqlalchemy.create_engine(url, echo=echo,
|
|
773
828
|
pool_size=conn_info.min_size,
|
|
774
|
-
pool_recycle=
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
pool_timeout=conn_info.params.get("pool_timeout",
|
|
779
|
-
10) if conn_info.params else 10,
|
|
780
|
-
pool_pre_ping=conn_info.params.get("pool_pre_ping",
|
|
781
|
-
True) if conn_info.params else True)
|
|
829
|
+
pool_recycle=pool_recycle,
|
|
830
|
+
max_overflow=max_overflow,
|
|
831
|
+
pool_timeout=pool_timeout,
|
|
832
|
+
pool_pre_ping=pool_pre_ping)
|
|
782
833
|
return engine
|
|
783
834
|
|
|
835
|
+
@staticmethod
|
|
836
|
+
def sync_create_dbutils_pool(conn_info: ConnectionInfo):
|
|
837
|
+
params = conn_info.params
|
|
838
|
+
if not isinstance(params, dict):
|
|
839
|
+
params = dict()
|
|
840
|
+
creator = params.pop("creator")
|
|
841
|
+
try:
|
|
842
|
+
generic = importlib.import_module(creator)
|
|
843
|
+
except ImportError:
|
|
844
|
+
raise Exception(f"{creator} is not exist,run:pip install {creator}")
|
|
845
|
+
try:
|
|
846
|
+
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
847
|
+
steady_db = importlib.import_module("dbutils.steady_db")
|
|
848
|
+
simple_pooled_db = importlib.import_module("dbutils.simple_pooled_db")
|
|
849
|
+
persistent_db = importlib.import_module("dbutils.persistent_db")
|
|
850
|
+
except ImportError:
|
|
851
|
+
raise Exception(f"DBUtils is not exist,run:pip install DBUtils==3.0.2")
|
|
852
|
+
pool_type = params.pop("pool_type", "PooledDB")
|
|
853
|
+
if pool_type not in ["SimplePooledDB", "SteadyDBConnection", "PersistentDB", "PooledDB"]:
|
|
854
|
+
pool_type = "PooledDB"
|
|
855
|
+
|
|
856
|
+
mincached = params.pop("mincached", conn_info.min_size)
|
|
857
|
+
maxusage = params.pop("maxusage", conn_info.min_size)
|
|
858
|
+
maxshared = params.pop("maxshared", conn_info.max_size)
|
|
859
|
+
maxcached = params.pop("maxcached", conn_info.max_size)
|
|
860
|
+
blocking = params.pop("blocking", True)
|
|
861
|
+
reset = params.pop("reset", True)
|
|
862
|
+
setsession = params.pop("setsession", None)
|
|
863
|
+
failures = params.pop("failures", None)
|
|
864
|
+
ping = params.pop("ping", 1)
|
|
865
|
+
threadlocal = params.pop("threadlocal", None)
|
|
866
|
+
closeable = params.pop("closeable", True)
|
|
867
|
+
maxconnections = params.pop("maxconnections", None)
|
|
868
|
+
if pool_type == "SimplePooledDB":
|
|
869
|
+
pool = simple_pooled_db.PooledDB(dbapi=creator, maxconnections=maxconnections, **params)
|
|
870
|
+
elif pool_type == "SteadyDBConnection":
|
|
871
|
+
pool = steady_db.SteadyDBConnection(creator=creator, maxusage=maxusage, setsession=setsession,
|
|
872
|
+
failures=failures,
|
|
873
|
+
ping=ping, closeable=closeable, **params)
|
|
874
|
+
elif pool_type == "PersistentDB":
|
|
875
|
+
pool = persistent_db.PersistentDB(creator=creator, maxusage=maxusage, setsession=setsession,
|
|
876
|
+
failures=failures, ping=ping,
|
|
877
|
+
closeable=closeable, threadlocal=threadlocal, **params)
|
|
878
|
+
else:
|
|
879
|
+
pool = pooled_db.PooledDB(creator=generic, mincached=mincached, maxcached=maxcached,
|
|
880
|
+
maxshared=maxshared, maxconnections=conn_info.max_size, blocking=blocking,
|
|
881
|
+
maxusage=maxusage, setsession=setsession, reset=reset,
|
|
882
|
+
failures=failures, ping=ping, **params)
|
|
883
|
+
return pool
|
|
884
|
+
|
|
784
885
|
|
|
785
886
|
def run_sync(func_instance):
|
|
786
887
|
if iscoroutine(func_instance):
|
|
@@ -880,11 +981,23 @@ def get_pool(conn_info: ConnectionInfo):
|
|
|
880
981
|
else:
|
|
881
982
|
return run_sync(Pool.sync_create_clickhouse_pool(conn_info)), conn_info
|
|
882
983
|
|
|
984
|
+
elif conn_info.dialect == "dm":
|
|
985
|
+
if conn_info.async_enable:
|
|
986
|
+
return run_sync(Pool.sync_create_dm_pool(conn_info)), conn_info
|
|
987
|
+
else:
|
|
988
|
+
return run_sync(Pool.sync_create_dm_pool(conn_info)), conn_info
|
|
989
|
+
|
|
883
990
|
elif conn_info.dialect == "sqlalchemy":
|
|
884
991
|
if conn_info.async_enable:
|
|
885
992
|
return run_sync(Pool.create_sqlalchemy_pool(conn_info)), conn_info
|
|
886
993
|
else:
|
|
887
994
|
return run_sync(Pool.sync_create_sqlalchemy_pool(conn_info)), conn_info
|
|
888
995
|
|
|
996
|
+
elif conn_info.dialect == "dbutils":
|
|
997
|
+
if conn_info.async_enable:
|
|
998
|
+
return run_sync(Pool.sync_create_dbutils_pool(conn_info)), conn_info
|
|
999
|
+
else:
|
|
1000
|
+
return run_sync(Pool.sync_create_dbutils_pool(conn_info)), conn_info
|
|
1001
|
+
|
|
889
1002
|
else:
|
|
890
1003
|
raise Exception(f"conn_info.dialect={conn_info.dialect} is not supported")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.10"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lesscode-database
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.10
|
|
4
4
|
Summary: lesscode_database是数据库连接工具包
|
|
5
5
|
Author: navysummer
|
|
6
6
|
Author-email: navysummer@yeah.net
|
|
@@ -57,13 +57,15 @@ db_options.conn_list = [
|
|
|
57
57
|
ConnectionInfo(dialect="redis", name="redis", host="127.0.0.1", port=6379, user=None,
|
|
58
58
|
password=None, db_name=1, enable=False, async_enable=True),
|
|
59
59
|
# sqlalchemy 异步支持mysql,postgresql,tidb,ocean_base,doris;
|
|
60
|
-
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle
|
|
60
|
+
# 同步支持mysql,postgresql,tidb,ocean_base,doris,sqlite3,mssql,oracle,dm
|
|
61
61
|
ConnectionInfo(dialect="sqlalchemy", name="sqlalchemy", host="127.0.0.1", port=3306, user="root",
|
|
62
62
|
password="root", db_name="test", enable=False, async_enable=False, params={"db_type": "mysql"}),
|
|
63
63
|
ConnectionInfo(dialect="neo4j", name="neo4j", host="127.0.0.1", port=7687, user="neo4j",
|
|
64
64
|
password="neo4j", db_name=None, enable=False, async_enable=True),
|
|
65
65
|
ConnectionInfo(dialect="clickhouse", name="clickhouse", dsn="clickhouse://localhost", host="127.0.0.1", port=9000,
|
|
66
66
|
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
67
|
+
ConnectionInfo(dialect="dm", name="dm", dsn=None, host="127.0.0.1", port=5236,
|
|
68
|
+
user="default", password="", db_name='', enable=True, async_enable=False),
|
|
67
69
|
|
|
68
70
|
]
|
|
69
71
|
|
|
@@ -358,4 +360,12 @@ async def async_esapi_test():
|
|
|
358
360
|
loop = asyncio.get_event_loop()
|
|
359
361
|
loop.run_until_complete(async_esapi_test())
|
|
360
362
|
|
|
363
|
+
|
|
364
|
+
# 达梦数据库 同步测试
|
|
365
|
+
with DsHelper("dm").pool.dedicated_connection() as conn:
|
|
366
|
+
with conn.cursor() as cursor:
|
|
367
|
+
cursor.execute('SELECT 1')
|
|
368
|
+
print(cursor.fetchall())
|
|
369
|
+
|
|
370
|
+
|
|
361
371
|
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database/dynamic_import_package.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{lesscode_database-0.0.8 → lesscode_database-0.0.10}/lesscode_database.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|