lesscode-database 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl
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/connect_pool.py +72 -76
- lesscode_database/connection_info.py +3 -1
- lesscode_database/{options.py → db_options.py} +9 -9
- lesscode_database/ds_helper.py +98 -0
- lesscode_database/dynamic_import_package.py +7 -0
- lesscode_database/version.py +1 -1
- {lesscode_database-0.0.4.dist-info → lesscode_database-0.0.6.dist-info}/METADATA +39 -42
- lesscode_database-0.0.6.dist-info/RECORD +12 -0
- lesscode_database-0.0.4.dist-info/RECORD +0 -10
- {lesscode_database-0.0.4.dist-info → lesscode_database-0.0.6.dist-info}/LICENSE +0 -0
- {lesscode_database-0.0.4.dist-info → lesscode_database-0.0.6.dist-info}/WHEEL +0 -0
- {lesscode_database-0.0.4.dist-info → lesscode_database-0.0.6.dist-info}/top_level.txt +0 -0
|
@@ -31,7 +31,7 @@ class Pool:
|
|
|
31
31
|
try:
|
|
32
32
|
elasticsearch = importlib.import_module("elasticsearch")
|
|
33
33
|
except ImportError:
|
|
34
|
-
raise
|
|
34
|
+
raise ImportError(f"elasticsearch is not exist,run:pip install elasticsearch[async]")
|
|
35
35
|
pool = elasticsearch.AsyncElasticsearch(hosts=hosts)
|
|
36
36
|
return pool
|
|
37
37
|
|
|
@@ -54,7 +54,7 @@ class Pool:
|
|
|
54
54
|
try:
|
|
55
55
|
elasticsearch = importlib.import_module("elasticsearch")
|
|
56
56
|
except ImportError:
|
|
57
|
-
raise
|
|
57
|
+
raise ImportError(f"elasticsearch is not exist,run:pip install elasticsearch")
|
|
58
58
|
pool = elasticsearch.Elasticsearch(hosts)
|
|
59
59
|
return pool
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ class Pool:
|
|
|
68
68
|
try:
|
|
69
69
|
motor_asyncio = importlib.import_module("motor.motor_asyncio")
|
|
70
70
|
except ImportError:
|
|
71
|
-
raise
|
|
71
|
+
raise ImportError(f"motor is not exist,run:pip install motor")
|
|
72
72
|
if conn_info.dsn:
|
|
73
73
|
uri = conn_info.dsn
|
|
74
74
|
else:
|
|
@@ -96,7 +96,7 @@ class Pool:
|
|
|
96
96
|
try:
|
|
97
97
|
pymongo = importlib.import_module("pymongo")
|
|
98
98
|
except ImportError:
|
|
99
|
-
raise
|
|
99
|
+
raise ImportError(f"pymongo is not exist,run:pip install pymongo")
|
|
100
100
|
if conn_info.dsn:
|
|
101
101
|
uri = conn_info.dsn
|
|
102
102
|
else:
|
|
@@ -124,7 +124,7 @@ class Pool:
|
|
|
124
124
|
try:
|
|
125
125
|
aiomysql = importlib.import_module("aiomysql")
|
|
126
126
|
except ImportError:
|
|
127
|
-
raise
|
|
127
|
+
raise ImportError(f"aiomysql is not exist,run:pip install aiomysql")
|
|
128
128
|
pool = await aiomysql.create_pool(host=conn_info.host, port=conn_info.port,
|
|
129
129
|
user=conn_info.user,
|
|
130
130
|
password=conn_info.password,
|
|
@@ -132,7 +132,8 @@ class Pool:
|
|
|
132
132
|
if conn_info.params else 3600,
|
|
133
133
|
db=conn_info.db_name, autocommit=True,
|
|
134
134
|
minsize=conn_info.min_size,
|
|
135
|
-
maxsize=conn_info.max_size
|
|
135
|
+
maxsize=conn_info.max_size,
|
|
136
|
+
cursorclass=aiomysql.DictCursor)
|
|
136
137
|
return pool
|
|
137
138
|
|
|
138
139
|
@staticmethod
|
|
@@ -145,11 +146,11 @@ class Pool:
|
|
|
145
146
|
try:
|
|
146
147
|
pymysql = importlib.import_module("pymysql")
|
|
147
148
|
except ImportError:
|
|
148
|
-
raise
|
|
149
|
+
raise ImportError(f"pymysql is not exist,run:pip install pymysql")
|
|
149
150
|
try:
|
|
150
151
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
151
152
|
except ImportError:
|
|
152
|
-
raise
|
|
153
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
153
154
|
pool = pooled_db.PooledDB(creator=pymysql, host=conn_info.host, port=conn_info.port,
|
|
154
155
|
user=conn_info.user,
|
|
155
156
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -169,7 +170,7 @@ class Pool:
|
|
|
169
170
|
try:
|
|
170
171
|
aiosqlite3 = importlib.import_module("aiosqlite3")
|
|
171
172
|
except ImportError:
|
|
172
|
-
raise
|
|
173
|
+
raise ImportError(f"aiosqlite3 is not exist,run:pip install aiosqlite3")
|
|
173
174
|
pool = await aiosqlite3.connect(database=conn_info.dsn)
|
|
174
175
|
return pool
|
|
175
176
|
|
|
@@ -183,18 +184,13 @@ class Pool:
|
|
|
183
184
|
try:
|
|
184
185
|
sqlite3 = importlib.import_module("sqlite3")
|
|
185
186
|
except ImportError:
|
|
186
|
-
raise
|
|
187
|
+
raise ImportError(f"sqlite3 is not exist,run:pip install sqlite3")
|
|
187
188
|
try:
|
|
188
189
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
189
190
|
except ImportError:
|
|
190
|
-
raise
|
|
191
|
-
pool = pooled_db.PooledDB(creator=sqlite3,
|
|
192
|
-
|
|
193
|
-
passwd=conn_info.password, db=conn_info.db_name,
|
|
194
|
-
mincached=conn_info.min_size, blocking=True, maxusage=conn_info.min_size,
|
|
195
|
-
maxshared=conn_info.max_size, maxcached=conn_info.max_size,
|
|
196
|
-
ping=1, maxconnections=conn_info.max_size, charset="utf8mb4", autocommit=True,
|
|
197
|
-
read_timeout=30)
|
|
191
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
192
|
+
pool = pooled_db.PooledDB(creator=sqlite3, database=conn_info.dsn,
|
|
193
|
+
check_same_thread=False)
|
|
198
194
|
return pool
|
|
199
195
|
|
|
200
196
|
@staticmethod
|
|
@@ -207,11 +203,11 @@ class Pool:
|
|
|
207
203
|
try:
|
|
208
204
|
pymssql = importlib.import_module("pymssql")
|
|
209
205
|
except ImportError:
|
|
210
|
-
raise
|
|
206
|
+
raise ImportError(f"pymssql is not exist,run:pip install pymssql")
|
|
211
207
|
try:
|
|
212
208
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
213
209
|
except ImportError:
|
|
214
|
-
raise
|
|
210
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
215
211
|
pool = pooled_db.PooledDB(creator=pymssql, host=conn_info.host, port=conn_info.port,
|
|
216
212
|
user=conn_info.user,
|
|
217
213
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -231,11 +227,11 @@ class Pool:
|
|
|
231
227
|
try:
|
|
232
228
|
cx_oracle = importlib.import_module("cx_Oracle")
|
|
233
229
|
except ImportError:
|
|
234
|
-
raise
|
|
230
|
+
raise ImportError(f"cx_Oracle is not exist,run:pip install cx_Oracle")
|
|
235
231
|
try:
|
|
236
232
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
237
233
|
except ImportError:
|
|
238
|
-
raise
|
|
234
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
239
235
|
pool = pooled_db.PooledDB(creator=cx_oracle, host=conn_info.host, port=conn_info.port,
|
|
240
236
|
user=conn_info.user,
|
|
241
237
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -255,7 +251,7 @@ class Pool:
|
|
|
255
251
|
try:
|
|
256
252
|
aiomysql = importlib.import_module("aiomysql")
|
|
257
253
|
except ImportError:
|
|
258
|
-
raise
|
|
254
|
+
raise ImportError(f"aiomysql is not exist,run:pip install aiomysql")
|
|
259
255
|
pool = await aiomysql.create_pool(host=conn_info.host, port=conn_info.port,
|
|
260
256
|
user=conn_info.user,
|
|
261
257
|
password=conn_info.password,
|
|
@@ -276,11 +272,11 @@ class Pool:
|
|
|
276
272
|
try:
|
|
277
273
|
pymysql = importlib.import_module("pymysql")
|
|
278
274
|
except ImportError:
|
|
279
|
-
raise
|
|
275
|
+
raise ImportError(f"pymysql is not exist,run:pip install pymysql")
|
|
280
276
|
try:
|
|
281
277
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
282
278
|
except ImportError:
|
|
283
|
-
raise
|
|
279
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
284
280
|
pool = pooled_db.PooledDB(creator=pymysql, host=conn_info.host, port=conn_info.port,
|
|
285
281
|
user=conn_info.user,
|
|
286
282
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -300,7 +296,7 @@ class Pool:
|
|
|
300
296
|
try:
|
|
301
297
|
aiomysql = importlib.import_module("aiomysql")
|
|
302
298
|
except ImportError:
|
|
303
|
-
raise
|
|
299
|
+
raise ImportError(f"aiomysql is not exist,run:pip install aiomysql")
|
|
304
300
|
pool = await aiomysql.create_pool(host=conn_info.host, port=conn_info.port,
|
|
305
301
|
user=conn_info.user,
|
|
306
302
|
password=conn_info.password,
|
|
@@ -321,11 +317,11 @@ class Pool:
|
|
|
321
317
|
try:
|
|
322
318
|
pymysql = importlib.import_module("pymysql")
|
|
323
319
|
except ImportError:
|
|
324
|
-
raise
|
|
320
|
+
raise ImportError(f"pymysql is not exist,run:pip install pymysql")
|
|
325
321
|
try:
|
|
326
322
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
327
323
|
except ImportError:
|
|
328
|
-
raise
|
|
324
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
329
325
|
pool = pooled_db.PooledDB(creator=pymysql, host=conn_info.host, port=conn_info.port,
|
|
330
326
|
user=conn_info.user,
|
|
331
327
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -345,7 +341,7 @@ class Pool:
|
|
|
345
341
|
try:
|
|
346
342
|
aiomysql = importlib.import_module("aiomysql")
|
|
347
343
|
except ImportError:
|
|
348
|
-
raise
|
|
344
|
+
raise ImportError(f"aiomysql is not exist,run:pip install aiomysql")
|
|
349
345
|
pool = await aiomysql.create_pool(host=conn_info.host, port=conn_info.port,
|
|
350
346
|
user=conn_info.user,
|
|
351
347
|
password=conn_info.password,
|
|
@@ -366,11 +362,11 @@ class Pool:
|
|
|
366
362
|
try:
|
|
367
363
|
pymysql = importlib.import_module("pymysql")
|
|
368
364
|
except ImportError:
|
|
369
|
-
raise
|
|
365
|
+
raise ImportError(f"pymysql is not exist,run:pip install pymysql")
|
|
370
366
|
try:
|
|
371
367
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
372
368
|
except ImportError:
|
|
373
|
-
raise
|
|
369
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
374
370
|
pool = pooled_db.PooledDB(creator=pymysql, host=conn_info.host, port=conn_info.port,
|
|
375
371
|
user=conn_info.user,
|
|
376
372
|
passwd=conn_info.password, db=conn_info.db_name,
|
|
@@ -391,7 +387,7 @@ class Pool:
|
|
|
391
387
|
nebula3_gclient_net = importlib.import_module("nebula3.gclient.net")
|
|
392
388
|
nebula3_config = importlib.import_module("nebula3.Config")
|
|
393
389
|
except ImportError:
|
|
394
|
-
raise
|
|
390
|
+
raise ImportError(f"nebula3 is not exist,run:pip install nebula3-python")
|
|
395
391
|
config = nebula3_config.Config()
|
|
396
392
|
ssl_conf = None
|
|
397
393
|
config.max_connection_pool_size = conn_info.max_size
|
|
@@ -425,7 +421,7 @@ class Pool:
|
|
|
425
421
|
try:
|
|
426
422
|
neo4j = importlib.import_module("neo4j")
|
|
427
423
|
except ImportError:
|
|
428
|
-
raise
|
|
424
|
+
raise ImportError(f"neo4j is not exist,run:pip install neo4j")
|
|
429
425
|
if conn_info.dsn:
|
|
430
426
|
uri = conn_info.dsn
|
|
431
427
|
else:
|
|
@@ -443,7 +439,7 @@ class Pool:
|
|
|
443
439
|
try:
|
|
444
440
|
neo4j = importlib.import_module("neo4j")
|
|
445
441
|
except ImportError:
|
|
446
|
-
raise
|
|
442
|
+
raise ImportError(f"neo4j is not exist,run:pip install neo4j")
|
|
447
443
|
if conn_info.dsn:
|
|
448
444
|
uri = conn_info.dsn
|
|
449
445
|
else:
|
|
@@ -461,7 +457,7 @@ class Pool:
|
|
|
461
457
|
try:
|
|
462
458
|
aiopg = importlib.import_module("aiopg")
|
|
463
459
|
except ImportError:
|
|
464
|
-
raise
|
|
460
|
+
raise ImportError(f"aiopg is not exist,run:pip install aiopg")
|
|
465
461
|
pool = await aiopg.create_pool(dsn=conn_info.dsn, host=conn_info.host, port=conn_info.port, user=conn_info.user,
|
|
466
462
|
password=conn_info.password,
|
|
467
463
|
database=conn_info.db_name)
|
|
@@ -477,11 +473,11 @@ class Pool:
|
|
|
477
473
|
try:
|
|
478
474
|
psycopg2 = importlib.import_module("psycopg2")
|
|
479
475
|
except ImportError:
|
|
480
|
-
raise
|
|
476
|
+
raise ImportError(f"psycopg2-binary is not exist,run:pip install psycopg2-binary")
|
|
481
477
|
try:
|
|
482
478
|
pooled_db = importlib.import_module("dbutils.pooled_db")
|
|
483
479
|
except ImportError:
|
|
484
|
-
raise
|
|
480
|
+
raise ImportError(f"DBUtils is not exist,run:pip install DBUtils")
|
|
485
481
|
pool = pooled_db.PooledDB(psycopg2, host=conn_info.host, port=conn_info.port,
|
|
486
482
|
user=conn_info.user,
|
|
487
483
|
password=conn_info.password, database=conn_info.db_name)
|
|
@@ -497,7 +493,7 @@ class Pool:
|
|
|
497
493
|
try:
|
|
498
494
|
aioredis = importlib.import_module("aioredis")
|
|
499
495
|
except ImportError:
|
|
500
|
-
raise
|
|
496
|
+
raise ImportError(f"aioredis is not exist,run:pip install aioredis")
|
|
501
497
|
if not conn_info.dsn:
|
|
502
498
|
conn_info.dsn = "redis://"
|
|
503
499
|
pool = aioredis.ConnectionPool.from_url(url=conn_info.dsn, host=conn_info.host, port=conn_info.port,
|
|
@@ -515,7 +511,7 @@ class Pool:
|
|
|
515
511
|
try:
|
|
516
512
|
redis = importlib.import_module("redis")
|
|
517
513
|
except ImportError:
|
|
518
|
-
raise
|
|
514
|
+
raise ImportError(f"redis is not exist,run:pip install redis")
|
|
519
515
|
if not conn_info.dsn:
|
|
520
516
|
conn_info.dsn = "redis://"
|
|
521
517
|
pool = redis.ConnectionPool.from_url(url=conn_info.dsn, host=conn_info.host, port=conn_info.port,
|
|
@@ -533,7 +529,7 @@ class Pool:
|
|
|
533
529
|
try:
|
|
534
530
|
aioredis_cluster = importlib.import_module("aioredis_cluster")
|
|
535
531
|
except ImportError:
|
|
536
|
-
raise
|
|
532
|
+
raise ImportError(f"aioredis is not exist,run:pip install aioredis-cluster")
|
|
537
533
|
params = conn_info.params if conn_info.params else {}
|
|
538
534
|
retry_min_delay = params.get("retry_min_delay")
|
|
539
535
|
retry_max_delay = params.get("retry_max_delay")
|
|
@@ -574,7 +570,7 @@ class Pool:
|
|
|
574
570
|
try:
|
|
575
571
|
rediscluster = importlib.import_module("rediscluster")
|
|
576
572
|
except ImportError:
|
|
577
|
-
raise
|
|
573
|
+
raise ImportError(f"redis is not exist,run:pip install redis-py-cluster")
|
|
578
574
|
params = conn_info.params if conn_info.params else {}
|
|
579
575
|
init_slot_cache = params.get("init_slot_cache", True) if params else True
|
|
580
576
|
max_connections_per_node = params.get("init_slot_cache",
|
|
@@ -600,7 +596,7 @@ class Pool:
|
|
|
600
596
|
try:
|
|
601
597
|
asynch = importlib.import_module("asynch")
|
|
602
598
|
except ImportError:
|
|
603
|
-
raise
|
|
599
|
+
raise ImportError(f"asynch is not exist,run:pip install asynch")
|
|
604
600
|
pool = await asynch.create_pool(minsize=conn_info.min_size, maxsize=conn_info.max_size,
|
|
605
601
|
dsn=conn_info.dsn, host=conn_info.host,
|
|
606
602
|
user=conn_info.user, password=conn_info.password,
|
|
@@ -612,7 +608,7 @@ class Pool:
|
|
|
612
608
|
try:
|
|
613
609
|
clickhouse_driver_dbapi = importlib.import_module("clickhouse_driver.dbapi")
|
|
614
610
|
except ImportError:
|
|
615
|
-
raise
|
|
611
|
+
raise ImportError(f"clickhouse-driver is not exist,run:pip install clickhouse-driver")
|
|
616
612
|
con = clickhouse_driver_dbapi.connect(dsn=conn_info.dsn, host=conn_info.host,
|
|
617
613
|
user=conn_info.user, password=conn_info.password,
|
|
618
614
|
port=conn_info.port, database=conn_info.db_name)
|
|
@@ -653,11 +649,11 @@ class Pool:
|
|
|
653
649
|
conn_info.user, conn_info.password, conn_info.host, conn_info.port,
|
|
654
650
|
conn_info.db_name)
|
|
655
651
|
else:
|
|
656
|
-
raise
|
|
652
|
+
raise ImportError("UNSUPPORTED DB TYPE")
|
|
657
653
|
try:
|
|
658
654
|
sqlalchemy = importlib.import_module("sqlalchemy.ext.asyncio")
|
|
659
655
|
except ImportError:
|
|
660
|
-
raise
|
|
656
|
+
raise ImportError(f"sqlalchemy is not exist,run:pip install sqlalchemy")
|
|
661
657
|
engine = sqlalchemy.create_async_engine(url, echo=conn_info.params.get("echo",
|
|
662
658
|
True) if conn_info.params else True,
|
|
663
659
|
pool_size=conn_info.min_size,
|
|
@@ -716,11 +712,11 @@ class Pool:
|
|
|
716
712
|
conn_info.user, conn_info.password, conn_info.host, conn_info.port,
|
|
717
713
|
conn_info.db_name)
|
|
718
714
|
else:
|
|
719
|
-
raise
|
|
715
|
+
raise ImportError("UNSUPPORTED DB TYPE")
|
|
720
716
|
try:
|
|
721
717
|
sqlalchemy = importlib.import_module("sqlalchemy")
|
|
722
718
|
except ImportError:
|
|
723
|
-
raise
|
|
719
|
+
raise ImportError(f"sqlalchemy is not exist,run:pip install sqlalchemy")
|
|
724
720
|
engine = sqlalchemy.create_engine(url, echo=conn_info.params.get("echo",
|
|
725
721
|
True) if conn_info.params else True,
|
|
726
722
|
pool_size=conn_info.min_size,
|
|
@@ -748,90 +744,90 @@ def run_sync(func_instance):
|
|
|
748
744
|
def get_pool(conn_info: ConnectionInfo):
|
|
749
745
|
if conn_info.dialect == "elasticsearch":
|
|
750
746
|
if conn_info.async_enable:
|
|
751
|
-
return run_sync(Pool.create_es_pool(conn_info))
|
|
747
|
+
return run_sync(Pool.create_es_pool(conn_info)), conn_info
|
|
752
748
|
else:
|
|
753
|
-
return run_sync(Pool.sync_create_es_pool(conn_info))
|
|
749
|
+
return run_sync(Pool.sync_create_es_pool(conn_info)), conn_info
|
|
754
750
|
|
|
755
751
|
elif conn_info.dialect == "mongo":
|
|
756
752
|
if conn_info.async_enable:
|
|
757
|
-
return run_sync(Pool.create_mongo_pool(conn_info))
|
|
753
|
+
return run_sync(Pool.create_mongo_pool(conn_info)), conn_info
|
|
758
754
|
else:
|
|
759
|
-
return run_sync(Pool.sync_create_mongo_pool(conn_info))
|
|
755
|
+
return run_sync(Pool.sync_create_mongo_pool(conn_info)), conn_info
|
|
760
756
|
|
|
761
757
|
elif conn_info.dialect == "mysql":
|
|
762
758
|
if conn_info.async_enable:
|
|
763
|
-
return run_sync(Pool.create_mysql_pool(conn_info))
|
|
759
|
+
return run_sync(Pool.create_mysql_pool(conn_info)), conn_info
|
|
764
760
|
else:
|
|
765
|
-
return run_sync(Pool.sync_create_mysql_pool(conn_info))
|
|
761
|
+
return run_sync(Pool.sync_create_mysql_pool(conn_info)), conn_info
|
|
766
762
|
|
|
767
763
|
elif conn_info.dialect == "doris":
|
|
768
764
|
if conn_info.async_enable:
|
|
769
|
-
return run_sync(Pool.create_doris_pool(conn_info))
|
|
765
|
+
return run_sync(Pool.create_doris_pool(conn_info)), conn_info
|
|
770
766
|
else:
|
|
771
|
-
return run_sync(Pool.sync_create_doris_pool(conn_info))
|
|
767
|
+
return run_sync(Pool.sync_create_doris_pool(conn_info)), conn_info
|
|
772
768
|
|
|
773
769
|
elif conn_info.dialect == "ocean_base":
|
|
774
770
|
if conn_info.async_enable:
|
|
775
|
-
return run_sync(Pool.create_ocean_base_pool(conn_info))
|
|
771
|
+
return run_sync(Pool.create_ocean_base_pool(conn_info)), conn_info
|
|
776
772
|
else:
|
|
777
|
-
return run_sync(Pool.sync_create_ocean_base_pool(conn_info))
|
|
773
|
+
return run_sync(Pool.sync_create_ocean_base_pool(conn_info)), conn_info
|
|
778
774
|
|
|
779
775
|
elif conn_info.dialect == "tidb":
|
|
780
776
|
if conn_info.async_enable:
|
|
781
|
-
return run_sync(Pool.create_tidb_pool(conn_info))
|
|
777
|
+
return run_sync(Pool.create_tidb_pool(conn_info)), conn_info
|
|
782
778
|
else:
|
|
783
|
-
return run_sync(Pool.sync_create_tidb_pool(conn_info))
|
|
779
|
+
return run_sync(Pool.sync_create_tidb_pool(conn_info)), conn_info
|
|
784
780
|
|
|
785
781
|
elif conn_info.dialect == "mssql":
|
|
786
|
-
return run_sync(Pool.sync_create_mssql_pool(conn_info))
|
|
782
|
+
return run_sync(Pool.sync_create_mssql_pool(conn_info)), conn_info
|
|
787
783
|
|
|
788
784
|
elif conn_info.dialect == "oracle":
|
|
789
|
-
return run_sync(Pool.sync_create_oracle_pool(conn_info))
|
|
785
|
+
return run_sync(Pool.sync_create_oracle_pool(conn_info)), conn_info
|
|
790
786
|
|
|
791
787
|
elif conn_info.dialect == "nebula":
|
|
792
|
-
return run_sync(Pool.sync_create_nebula_pool(conn_info))
|
|
788
|
+
return run_sync(Pool.sync_create_nebula_pool(conn_info)), conn_info
|
|
793
789
|
|
|
794
790
|
elif conn_info.dialect == "neo4j":
|
|
795
791
|
if conn_info.async_enable:
|
|
796
|
-
return run_sync(Pool.create_neo4j_pool(conn_info))
|
|
792
|
+
return run_sync(Pool.create_neo4j_pool(conn_info)), conn_info
|
|
797
793
|
else:
|
|
798
|
-
return run_sync(Pool.sync_create_neo4j_pool(conn_info))
|
|
794
|
+
return run_sync(Pool.sync_create_neo4j_pool(conn_info)), conn_info
|
|
799
795
|
|
|
800
796
|
elif conn_info.dialect == "postgresql":
|
|
801
797
|
if conn_info.async_enable:
|
|
802
|
-
return run_sync(Pool.create_postgresql_pool(conn_info))
|
|
798
|
+
return run_sync(Pool.create_postgresql_pool(conn_info)), conn_info
|
|
803
799
|
else:
|
|
804
|
-
return run_sync(Pool.sync_create_postgresql_pool(conn_info))
|
|
800
|
+
return run_sync(Pool.sync_create_postgresql_pool(conn_info)), conn_info
|
|
805
801
|
|
|
806
802
|
elif conn_info.dialect == "sqlite3":
|
|
807
803
|
if conn_info.async_enable:
|
|
808
|
-
return run_sync(Pool.create_sqlite3_pool(conn_info))
|
|
804
|
+
return run_sync(Pool.create_sqlite3_pool(conn_info)), conn_info
|
|
809
805
|
else:
|
|
810
|
-
return run_sync(Pool.sync_create_sqlite3_pool(conn_info))
|
|
806
|
+
return run_sync(Pool.sync_create_sqlite3_pool(conn_info)), conn_info
|
|
811
807
|
|
|
812
808
|
elif conn_info.dialect == "redis":
|
|
813
809
|
if conn_info.async_enable:
|
|
814
|
-
return run_sync(Pool.create_redis_pool(conn_info))
|
|
810
|
+
return run_sync(Pool.create_redis_pool(conn_info)), conn_info
|
|
815
811
|
else:
|
|
816
|
-
return run_sync(Pool.sync_create_redis_pool(conn_info))
|
|
812
|
+
return run_sync(Pool.sync_create_redis_pool(conn_info)), conn_info
|
|
817
813
|
|
|
818
814
|
elif conn_info.dialect == "redis_cluster":
|
|
819
815
|
if conn_info.async_enable:
|
|
820
|
-
return run_sync(Pool.create_redis_cluster_pool(conn_info))
|
|
816
|
+
return run_sync(Pool.create_redis_cluster_pool(conn_info)), conn_info
|
|
821
817
|
else:
|
|
822
|
-
return run_sync(Pool.sync_create_redis_cluster_pool(conn_info))
|
|
818
|
+
return run_sync(Pool.sync_create_redis_cluster_pool(conn_info)), conn_info
|
|
823
819
|
|
|
824
820
|
elif conn_info.dialect == "clickhouse":
|
|
825
821
|
if conn_info.async_enable:
|
|
826
|
-
return run_sync(Pool.create_clickhouse_pool(conn_info))
|
|
822
|
+
return run_sync(Pool.create_clickhouse_pool(conn_info)), conn_info
|
|
827
823
|
else:
|
|
828
|
-
return run_sync(Pool.sync_create_clickhouse_pool(conn_info))
|
|
824
|
+
return run_sync(Pool.sync_create_clickhouse_pool(conn_info)), conn_info
|
|
829
825
|
|
|
830
826
|
elif conn_info.dialect == "sqlalchemy":
|
|
831
827
|
if conn_info.async_enable:
|
|
832
|
-
return run_sync(Pool.create_sqlalchemy_pool(conn_info))
|
|
828
|
+
return run_sync(Pool.create_sqlalchemy_pool(conn_info)), conn_info
|
|
833
829
|
else:
|
|
834
|
-
return run_sync(Pool.sync_create_sqlalchemy_pool(conn_info))
|
|
830
|
+
return run_sync(Pool.sync_create_sqlalchemy_pool(conn_info)), conn_info
|
|
835
831
|
|
|
836
832
|
else:
|
|
837
833
|
raise Exception(f"conn_info.dialect={conn_info.dialect} is not supported")
|
|
@@ -10,7 +10,7 @@ class ConnectionInfo:
|
|
|
10
10
|
def __init__(self, dialect: str, dsn: str = None, host: str = None, port: int = None, user: str = None,
|
|
11
11
|
password: str = None,
|
|
12
12
|
db_name: Any = None, name: str = None, params: dict = None, min_size: int = 3, max_size: int = 10,
|
|
13
|
-
enable: bool = True, async_enable: bool = False):
|
|
13
|
+
enable: bool = True, async_enable: bool = False, connect_keepalive: bool = True):
|
|
14
14
|
# 数据库dialect类型
|
|
15
15
|
self.dialect = dialect
|
|
16
16
|
# 连接池名称
|
|
@@ -40,3 +40,5 @@ class ConnectionInfo:
|
|
|
40
40
|
self.enable = enable
|
|
41
41
|
# 是否启用异步
|
|
42
42
|
self.async_enable = async_enable
|
|
43
|
+
# 是否启用session
|
|
44
|
+
self.connect_keepalive = connect_keepalive
|
|
@@ -4,7 +4,7 @@ from lesscode_database.connect_pool import get_pool
|
|
|
4
4
|
from lesscode_database.connection_info import ConnectionInfo
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class DbOptions:
|
|
8
8
|
_instance = None
|
|
9
9
|
|
|
10
10
|
def __init__(self):
|
|
@@ -47,13 +47,13 @@ class Options:
|
|
|
47
47
|
return cls._instance
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
db_options = DbOptions()
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
53
|
+
def db_define(name: str,
|
|
54
|
+
default: Any = None,
|
|
55
|
+
type_: Optional[type] = None,
|
|
56
|
+
help_: Optional[str] = None,
|
|
57
|
+
callback: Optional[Callable[[Any], None]] = None,
|
|
58
|
+
) -> None:
|
|
59
|
+
return db_options.define(name=name, default=default, type_=type_, help_=help_, callback=callback)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
from asyncio import current_task
|
|
3
|
+
from contextlib import contextmanager, asynccontextmanager
|
|
4
|
+
|
|
5
|
+
from lesscode_database.db_options import db_options
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DsHelper:
|
|
9
|
+
def __init__(self, pool_name):
|
|
10
|
+
self.pool, self.connect_info = getattr(db_options, pool_name)
|
|
11
|
+
|
|
12
|
+
def exec(self, method: str, *args, **kwargs):
|
|
13
|
+
return getattr(self.pool, method)(*args, **kwargs)
|
|
14
|
+
|
|
15
|
+
async def async_exec(self, method: str, *args, **kwargs):
|
|
16
|
+
return await getattr(self.pool, method)(*args, **kwargs)
|
|
17
|
+
|
|
18
|
+
@contextmanager
|
|
19
|
+
def make_sqlalchemy_session(self, **kwargs):
|
|
20
|
+
try:
|
|
21
|
+
sqlalchemy_orm = importlib.import_module("sqlalchemy.orm")
|
|
22
|
+
except ImportError:
|
|
23
|
+
raise Exception(f"sqlalchemy is not exist,run:pip install sqlalchemy==1.4.36")
|
|
24
|
+
session = None
|
|
25
|
+
try:
|
|
26
|
+
db_session = sqlalchemy_orm.scoped_session(sqlalchemy_orm.sessionmaker(bind=self.pool, **kwargs))
|
|
27
|
+
session = db_session()
|
|
28
|
+
yield session
|
|
29
|
+
except Exception:
|
|
30
|
+
if session:
|
|
31
|
+
session.rollback()
|
|
32
|
+
else:
|
|
33
|
+
session.commit()
|
|
34
|
+
finally:
|
|
35
|
+
if session:
|
|
36
|
+
session.close()
|
|
37
|
+
|
|
38
|
+
@asynccontextmanager
|
|
39
|
+
async def async_make_sqlalchemy_session(self, **kwargs):
|
|
40
|
+
try:
|
|
41
|
+
sqlalchemy_asyncio = importlib.import_module("sqlalchemy.ext.asyncio")
|
|
42
|
+
except ImportError:
|
|
43
|
+
raise Exception(f"sqlalchemy is not exist,run:pip install sqlalchemy==1.4.36")
|
|
44
|
+
session = None
|
|
45
|
+
try:
|
|
46
|
+
session = sqlalchemy_asyncio.async_scoped_session(
|
|
47
|
+
sqlalchemy_asyncio.async_sessionmaker(self.pool, **kwargs), current_task)
|
|
48
|
+
yield session
|
|
49
|
+
except Exception:
|
|
50
|
+
if session:
|
|
51
|
+
await session.rollback()
|
|
52
|
+
else:
|
|
53
|
+
await session.commit()
|
|
54
|
+
finally:
|
|
55
|
+
if session:
|
|
56
|
+
await session.close()
|
|
57
|
+
|
|
58
|
+
@contextmanager
|
|
59
|
+
def make_neo4j_session(self, **kwargs):
|
|
60
|
+
session = None
|
|
61
|
+
try:
|
|
62
|
+
session = self.pool.session(database=self.connect_info.db_name, **kwargs)
|
|
63
|
+
yield session
|
|
64
|
+
except Exception as e:
|
|
65
|
+
raise e
|
|
66
|
+
finally:
|
|
67
|
+
if session:
|
|
68
|
+
session.close()
|
|
69
|
+
|
|
70
|
+
@asynccontextmanager
|
|
71
|
+
async def async_make_neo4j_session(self, **kwargs):
|
|
72
|
+
session = None
|
|
73
|
+
try:
|
|
74
|
+
session = self.pool.session(database=self.connect_info.db_name, **kwargs)
|
|
75
|
+
yield session
|
|
76
|
+
except Exception as e:
|
|
77
|
+
raise e
|
|
78
|
+
finally:
|
|
79
|
+
if session:
|
|
80
|
+
await session.close()
|
|
81
|
+
|
|
82
|
+
# @contextmanager
|
|
83
|
+
def make_nebula_session(self, **kwargs):
|
|
84
|
+
try:
|
|
85
|
+
session = self.pool.session_context(user_name=self.connect_info.user, password=self.connect_info.password,
|
|
86
|
+
**kwargs)
|
|
87
|
+
return session
|
|
88
|
+
except Exception as e:
|
|
89
|
+
raise e
|
|
90
|
+
|
|
91
|
+
def exec_nebula_gql(self, sql, space=None):
|
|
92
|
+
space = space if space else self.connect_info.db_name
|
|
93
|
+
if not space:
|
|
94
|
+
raise Exception(f"nebula no selection space")
|
|
95
|
+
with self.make_nebula_session() as session:
|
|
96
|
+
session.execute(f'USE {space}')
|
|
97
|
+
result = session.execute(sql)
|
|
98
|
+
return result
|
lesscode_database/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.6"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lesscode-database
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: lesscode_database是数据库连接工具包
|
|
5
5
|
Author: navysummer
|
|
6
6
|
Author-email: navysummer@yeah.net
|
|
@@ -20,14 +20,13 @@ License-File: LICENSE
|
|
|
20
20
|
```python
|
|
21
21
|
import asyncio
|
|
22
22
|
|
|
23
|
-
from sqlalchemy import select,
|
|
24
|
-
from sqlalchemy.ext.asyncio import async_sessionmaker
|
|
25
|
-
from sqlalchemy.orm import sessionmaker
|
|
23
|
+
from sqlalchemy import select, MetaData, Table, Column, VARCHAR, INTEGER
|
|
26
24
|
|
|
27
25
|
from lesscode_database.connection_info import ConnectionInfo
|
|
28
|
-
from lesscode_database.
|
|
26
|
+
from lesscode_database.db_options import db_options
|
|
27
|
+
from lesscode_database.ds_helper import DsHelper
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
db_options.conn_list = [
|
|
31
30
|
ConnectionInfo(dialect="mysql", name="mysql", host="127.0.0.1", port=3306, user="root",
|
|
32
31
|
password="root", db_name="test", enable=False, params={"pool_recycle": 3600},
|
|
33
32
|
async_enable=True),
|
|
@@ -66,8 +65,9 @@ options.conn_list = [
|
|
|
66
65
|
|
|
67
66
|
]
|
|
68
67
|
|
|
68
|
+
|
|
69
69
|
# mysql 同步测试,async_enable=False
|
|
70
|
-
with
|
|
70
|
+
with DsHelper("mysql").pool.dedicated_connection() as conn:
|
|
71
71
|
conn.ping(reconnect=True)
|
|
72
72
|
with conn.cursor() as cursor:
|
|
73
73
|
cursor.execute("select 1")
|
|
@@ -78,7 +78,7 @@ with options.mysql.dedicated_connection() as conn:
|
|
|
78
78
|
|
|
79
79
|
# mysql 异步测试,async_enable=True
|
|
80
80
|
async def async_mysql_test():
|
|
81
|
-
async with
|
|
81
|
+
async with DsHelper("mysql").pool.acquire() as conn:
|
|
82
82
|
async with conn.cursor() as cursor:
|
|
83
83
|
await cursor.execute("select 1")
|
|
84
84
|
rs = await cursor.fetchone()
|
|
@@ -89,7 +89,7 @@ loop = asyncio.get_event_loop()
|
|
|
89
89
|
loop.run_until_complete(async_mysql_test())
|
|
90
90
|
|
|
91
91
|
# doris 同步测试,async_enable=False
|
|
92
|
-
with
|
|
92
|
+
with DsHelper("doris").pool.dedicated_connection() as conn:
|
|
93
93
|
conn.ping(reconnect=True)
|
|
94
94
|
with conn.cursor() as cursor:
|
|
95
95
|
cursor.execute("select 1")
|
|
@@ -100,7 +100,7 @@ with options.doris.dedicated_connection() as conn:
|
|
|
100
100
|
|
|
101
101
|
# doris 异步测试,async_enable=True
|
|
102
102
|
async def async_doris_test():
|
|
103
|
-
async with
|
|
103
|
+
async with DsHelper("doris").pool.acquire() as conn:
|
|
104
104
|
async with conn.cursor() as cursor:
|
|
105
105
|
await cursor.execute("select 1")
|
|
106
106
|
rs = await cursor.fetchone()
|
|
@@ -111,7 +111,7 @@ loop = asyncio.get_event_loop()
|
|
|
111
111
|
loop.run_until_complete(async_doris_test())
|
|
112
112
|
|
|
113
113
|
# ocean_base 同步测试,async_enable=False
|
|
114
|
-
with
|
|
114
|
+
with DsHelper("ocean_base").pool.dedicated_connection() as conn:
|
|
115
115
|
conn.ping(reconnect=True)
|
|
116
116
|
with conn.cursor() as cursor:
|
|
117
117
|
cursor.execute("select 1")
|
|
@@ -122,7 +122,7 @@ with options.ocean_base.dedicated_connection() as conn:
|
|
|
122
122
|
|
|
123
123
|
# ocean_base 异步测试,async_enable=True
|
|
124
124
|
async def async_ocean_base_test():
|
|
125
|
-
async with
|
|
125
|
+
async with DsHelper("ocean_base").pool.acquire() as conn:
|
|
126
126
|
async with conn.cursor() as cursor:
|
|
127
127
|
await cursor.execute("select 1")
|
|
128
128
|
rs = await cursor.fetchone()
|
|
@@ -133,7 +133,7 @@ loop = asyncio.get_event_loop()
|
|
|
133
133
|
loop.run_until_complete(async_ocean_base_test())
|
|
134
134
|
|
|
135
135
|
# tidb 同步测试,async_enable=False
|
|
136
|
-
with
|
|
136
|
+
with DsHelper("tidb").pool.dedicated_connection() as conn:
|
|
137
137
|
conn.ping(reconnect=True)
|
|
138
138
|
with conn.cursor() as cursor:
|
|
139
139
|
cursor.execute("select 1")
|
|
@@ -144,7 +144,7 @@ with options.tidb.dedicated_connection() as conn:
|
|
|
144
144
|
|
|
145
145
|
# tidb 异步测试,async_enable=True
|
|
146
146
|
async def async_tidb_test():
|
|
147
|
-
async with
|
|
147
|
+
async with DsHelper("tidb").pool.acquire() as conn:
|
|
148
148
|
async with conn.cursor() as cursor:
|
|
149
149
|
await cursor.execute("select 1")
|
|
150
150
|
rs = await cursor.fetchone()
|
|
@@ -157,7 +157,7 @@ loop.run_until_complete(async_tidb_test())
|
|
|
157
157
|
|
|
158
158
|
# sqlite3 异步测试
|
|
159
159
|
async def async_sqlite3_test():
|
|
160
|
-
cur = await
|
|
160
|
+
cur = await DsHelper("sqlite3").pool.cursor()
|
|
161
161
|
await cur.execute("SELECT 1")
|
|
162
162
|
row = await cur.fetchone()
|
|
163
163
|
print(row)
|
|
@@ -167,7 +167,7 @@ loop = asyncio.get_event_loop()
|
|
|
167
167
|
loop.run_until_complete(async_sqlite3_test())
|
|
168
168
|
|
|
169
169
|
# sqlite3 同步测试
|
|
170
|
-
cursor =
|
|
170
|
+
cursor = DsHelper("sqlite3").pool.cursor()
|
|
171
171
|
cursor.execute('select 1')
|
|
172
172
|
row = cursor.fetchone()
|
|
173
173
|
print(row)
|
|
@@ -181,7 +181,7 @@ body = {
|
|
|
181
181
|
},
|
|
182
182
|
"size": 1
|
|
183
183
|
}
|
|
184
|
-
resp =
|
|
184
|
+
resp = DsHelper("es").pool.search(
|
|
185
185
|
index="test",
|
|
186
186
|
body=body
|
|
187
187
|
)
|
|
@@ -190,7 +190,7 @@ print(resp)
|
|
|
190
190
|
|
|
191
191
|
# es异步测试,async_enable=True
|
|
192
192
|
async def async_es_test():
|
|
193
|
-
resp = await
|
|
193
|
+
resp = await DsHelper("es").pool.search(
|
|
194
194
|
index="test",
|
|
195
195
|
body={"query": {"match_all": {}}},
|
|
196
196
|
size=1,
|
|
@@ -202,7 +202,7 @@ loop = asyncio.get_event_loop()
|
|
|
202
202
|
loop.run_until_complete(async_es_test())
|
|
203
203
|
|
|
204
204
|
# sql server同步测试
|
|
205
|
-
cursor =
|
|
205
|
+
cursor = DsHelper("mssql").pool.cursor()
|
|
206
206
|
cursor.execute('SELECT 1')
|
|
207
207
|
row = cursor.fetchone()
|
|
208
208
|
print(row)
|
|
@@ -210,7 +210,7 @@ print(row)
|
|
|
210
210
|
# sql server暂不支持异步测试
|
|
211
211
|
|
|
212
212
|
# oracle 同步测试
|
|
213
|
-
cursor =
|
|
213
|
+
cursor = DsHelper("oracle").pool.cursor()
|
|
214
214
|
cursor.execute('select 1')
|
|
215
215
|
row = cursor.fetchone()
|
|
216
216
|
print(row)
|
|
@@ -219,12 +219,12 @@ print(row)
|
|
|
219
219
|
|
|
220
220
|
|
|
221
221
|
# mongo同步测试,async_enable=False
|
|
222
|
-
print(
|
|
222
|
+
print(DsHelper("mongo").pool.test.test.find_one())
|
|
223
223
|
|
|
224
224
|
|
|
225
225
|
# mongo异步测试,async_enable=True
|
|
226
226
|
async def async_mongo_test():
|
|
227
|
-
resp = await
|
|
227
|
+
resp = await DsHelper("mongo").pool.test.test.find_one()
|
|
228
228
|
print(resp)
|
|
229
229
|
|
|
230
230
|
|
|
@@ -232,15 +232,16 @@ loop = asyncio.get_event_loop()
|
|
|
232
232
|
loop.run_until_complete(async_mongo_test())
|
|
233
233
|
|
|
234
234
|
# nebula同步测试,async_enable=False
|
|
235
|
-
with
|
|
236
|
-
session.execute(f'USE
|
|
237
|
-
result = session.execute("match (
|
|
235
|
+
with DsHelper("nebula").make_nebula_session() as session:
|
|
236
|
+
session.execute(f'USE core')
|
|
237
|
+
result = session.execute("match (c:Company) return c limit 1")
|
|
238
238
|
print(result)
|
|
239
239
|
|
|
240
|
+
print(DsHelper("nebula").exec_nebula_gql("match (c:Company) return c limit 1", "core"))
|
|
240
241
|
# nebula暂不支持异步
|
|
241
242
|
|
|
242
243
|
# postgresql同步测试,async_enable=False
|
|
243
|
-
with
|
|
244
|
+
with DsHelper("postgresql").pool.connection() as conn:
|
|
244
245
|
with conn.cursor() as cursor:
|
|
245
246
|
cursor.execute("select 1")
|
|
246
247
|
rs = cursor.fetchone()
|
|
@@ -249,7 +250,7 @@ with options.postgresql.connection() as conn:
|
|
|
249
250
|
|
|
250
251
|
# postgresql异步测试,async_enable=True
|
|
251
252
|
async def async_pg_test():
|
|
252
|
-
async with
|
|
253
|
+
async with DsHelper("postgresql").pool.acquire() as conn:
|
|
253
254
|
async with conn.cursor() as cur:
|
|
254
255
|
await cur.execute("select 1")
|
|
255
256
|
rs = await cur.fetchone()
|
|
@@ -260,12 +261,12 @@ loop = asyncio.get_event_loop()
|
|
|
260
261
|
loop.run_until_complete(async_pg_test())
|
|
261
262
|
|
|
262
263
|
# redis 同步测试,async_enable=False
|
|
263
|
-
print(
|
|
264
|
+
print(DsHelper("redis").pool.exists("test"))
|
|
264
265
|
|
|
265
266
|
|
|
266
267
|
# redis 异步测试,async_enable=True
|
|
267
268
|
async def async_redis_test():
|
|
268
|
-
rs = await
|
|
269
|
+
rs = await DsHelper("redis").pool.exists("test")
|
|
269
270
|
print(rs)
|
|
270
271
|
|
|
271
272
|
|
|
@@ -279,52 +280,49 @@ t1 = Table("test_user", meta, Column("name", VARCHAR(collation='utf8mb3_bin', le
|
|
|
279
280
|
server_default=None))
|
|
280
281
|
|
|
281
282
|
# sqlalchemy同步测试,async_enable=False
|
|
282
|
-
with
|
|
283
|
+
with DsHelper("sqlalchemy").make_sqlalchemy_session() as session:
|
|
283
284
|
cur = session.execute(select(t1))
|
|
284
285
|
print(cur.fetchall())
|
|
285
286
|
|
|
286
287
|
|
|
287
288
|
# sqlalchemy异步测试,async_enable=True
|
|
288
289
|
async def async_sqlalchemy_test():
|
|
289
|
-
async with
|
|
290
|
+
async with DsHelper("sqlalchemy").async_make_sqlalchemy_session() as session:
|
|
290
291
|
cur = await session.execute(select(t1))
|
|
291
|
-
|
|
292
292
|
print(cur.fetchall())
|
|
293
293
|
|
|
294
294
|
|
|
295
295
|
loop = asyncio.get_event_loop()
|
|
296
296
|
loop.run_until_complete(async_sqlalchemy_test())
|
|
297
297
|
|
|
298
|
-
|
|
299
298
|
# neo4j同步测试
|
|
300
299
|
def query(tx):
|
|
301
|
-
nql = "
|
|
300
|
+
nql = "match (p:Person) return p"
|
|
302
301
|
for record in tx.run(nql):
|
|
303
302
|
print(record)
|
|
304
303
|
|
|
305
304
|
|
|
306
|
-
with
|
|
305
|
+
with DsHelper("neo4j").make_neo4j_session() as session:
|
|
307
306
|
session.execute_read(query)
|
|
308
307
|
|
|
309
|
-
|
|
310
308
|
# neo4j异步测试
|
|
311
309
|
async def query(tx):
|
|
312
|
-
nql = "
|
|
310
|
+
nql = "match (p:Person) return p"
|
|
313
311
|
res = await tx.run(nql)
|
|
314
312
|
async for record in res:
|
|
315
313
|
print(record)
|
|
316
314
|
|
|
317
|
-
|
|
318
315
|
async def async_neo4j_test():
|
|
319
|
-
async with
|
|
316
|
+
async with DsHelper("neo4j").async_make_neo4j_session() as session:
|
|
320
317
|
await session.execute_read(query)
|
|
321
318
|
|
|
322
319
|
|
|
323
320
|
loop = asyncio.get_event_loop()
|
|
324
321
|
loop.run_until_complete(async_neo4j_test())
|
|
325
322
|
|
|
323
|
+
|
|
326
324
|
# clickhouse 同步测试
|
|
327
|
-
with
|
|
325
|
+
with DsHelper("clickhouse").pool.dedicated_connection() as conn:
|
|
328
326
|
with conn.cursor() as cursor:
|
|
329
327
|
cursor.execute('SELECT 1')
|
|
330
328
|
print(cursor.fetchall())
|
|
@@ -332,7 +330,7 @@ with options.clickhouse as conn:
|
|
|
332
330
|
|
|
333
331
|
# clickhouse 异步测试测试
|
|
334
332
|
async def async_clickhouse_test():
|
|
335
|
-
async with
|
|
333
|
+
async with DsHelper("clickhouse").pool.acquire() as conn:
|
|
336
334
|
async with conn.cursor() as cursor:
|
|
337
335
|
await cursor.execute("SELECT 1")
|
|
338
336
|
ret = await cursor.fetchone()
|
|
@@ -342,5 +340,4 @@ async def async_clickhouse_test():
|
|
|
342
340
|
loop = asyncio.get_event_loop()
|
|
343
341
|
loop.run_until_complete(async_clickhouse_test())
|
|
344
342
|
|
|
345
|
-
|
|
346
343
|
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
lesscode_database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
lesscode_database/connect_pool.py,sha256=w6qmo3Zj3aUmw8G83LMoMU3D-sz7rN6_QGcQqy39Y1w,39145
|
|
3
|
+
lesscode_database/connection_info.py,sha256=HMlA-hA0LE7jGUS8crZAgrBMB-o6B9mxrWYEywgqXHg,1307
|
|
4
|
+
lesscode_database/db_options.py,sha256=Z8Iy3pqDYW5YVVfvoFSsAYecK9LfiwRasYc3fzqIBt8,1928
|
|
5
|
+
lesscode_database/ds_helper.py,sha256=MKAh7BUKWmGCnTPExiXQ9bzvSjY_gZU1isjtAkN-3rQ,3324
|
|
6
|
+
lesscode_database/dynamic_import_package.py,sha256=J8hgGRHe6KrprOgOq-xbKHVAYHSjUBcNyTaSPvBmvIk,164
|
|
7
|
+
lesscode_database/version.py,sha256=QiiYsv0kcJaB8wCWyT-FnI2b6be87HA-CrrIUn8LQhg,22
|
|
8
|
+
lesscode_database-0.0.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
lesscode_database-0.0.6.dist-info/METADATA,sha256=HVI7lXSlWpSX51Yg_7MuSYHhbWmXI1FQiQQvmtYsOeE,11059
|
|
10
|
+
lesscode_database-0.0.6.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
11
|
+
lesscode_database-0.0.6.dist-info/top_level.txt,sha256=h6cg13be6kkDfNaX9nWeDcfducTb5bKG5iYRO2JPmAM,18
|
|
12
|
+
lesscode_database-0.0.6.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
lesscode_database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
lesscode_database/connect_pool.py,sha256=TBtr0qWEflTHl2c_5mLYSqVweLrnO0Mm62Ms7j6PnRA,39136
|
|
3
|
-
lesscode_database/connection_info.py,sha256=atUWd3lr8G67ZtNPEA2sw_rlAsxVoz6OJasWVzU8els,1194
|
|
4
|
-
lesscode_database/options.py,sha256=zrXxWXmTg5NpgdfzWoG7nIx259QQ6R-87Q7ZDMyUv7c,1900
|
|
5
|
-
lesscode_database/version.py,sha256=1mptEzQihbdyqqzMgdns_j5ZGK9gz7hR2bsgA_TnjO4,22
|
|
6
|
-
lesscode_database-0.0.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
-
lesscode_database-0.0.4.dist-info/METADATA,sha256=gV9fjgRtugsQdZGbdc2ip3dHjZHJFrLh3n1ksFTSBQA,10787
|
|
8
|
-
lesscode_database-0.0.4.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
9
|
-
lesscode_database-0.0.4.dist-info/top_level.txt,sha256=h6cg13be6kkDfNaX9nWeDcfducTb5bKG5iYRO2JPmAM,18
|
|
10
|
-
lesscode_database-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|