comun-aioodbc 0.1__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.
- comun_aioodbc-0.1/PKG-INFO +5 -0
- comun_aioodbc-0.1/comun_aioodbc.egg-info/PKG-INFO +5 -0
- comun_aioodbc-0.1/comun_aioodbc.egg-info/SOURCES.txt +7 -0
- comun_aioodbc-0.1/comun_aioodbc.egg-info/dependency_links.txt +1 -0
- comun_aioodbc-0.1/comun_aioodbc.egg-info/requires.txt +1 -0
- comun_aioodbc-0.1/comun_aioodbc.egg-info/top_level.txt +1 -0
- comun_aioodbc-0.1/comun_aioodbc.py +57 -0
- comun_aioodbc-0.1/setup.cfg +4 -0
- comun_aioodbc-0.1/setup.py +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aioodbc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
comun_aioodbc
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import aioodbc
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SqlAsync:
|
|
5
|
+
def __init__(self, dsn: str, autocommit: bool = True, as_dict: bool = True):
|
|
6
|
+
self.dsn = dsn
|
|
7
|
+
self.autocommit = autocommit
|
|
8
|
+
self.as_dict = as_dict
|
|
9
|
+
self._pool = None
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
async def create(cls, dsn: str, minsize: int = 2, maxsize: int = 10, autocommit: bool = True, as_dict: bool = True):
|
|
13
|
+
instance = cls(dsn, autocommit, as_dict)
|
|
14
|
+
instance._pool = await aioodbc.create_pool(
|
|
15
|
+
dsn=dsn,
|
|
16
|
+
minsize=minsize,
|
|
17
|
+
maxsize=maxsize,
|
|
18
|
+
autocommit=autocommit,
|
|
19
|
+
)
|
|
20
|
+
return instance
|
|
21
|
+
|
|
22
|
+
async def cerrar_conexion(self):
|
|
23
|
+
self._pool.close()
|
|
24
|
+
await self._pool.wait_closed()
|
|
25
|
+
|
|
26
|
+
async def ejecutar(self, texto: str, *parametros):
|
|
27
|
+
try:
|
|
28
|
+
params = parametros[0] if parametros and isinstance(parametros[0], tuple) else parametros
|
|
29
|
+
async with self._pool.acquire() as conn:
|
|
30
|
+
async with conn.cursor() as cur:
|
|
31
|
+
await cur.execute(texto, params or None)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
print(texto)
|
|
34
|
+
print(parametros)
|
|
35
|
+
print(e)
|
|
36
|
+
raise
|
|
37
|
+
|
|
38
|
+
async def ejecutar_varios(self, texto: str, data: list):
|
|
39
|
+
try:
|
|
40
|
+
async with self._pool.acquire() as conn:
|
|
41
|
+
async with conn.cursor() as cur:
|
|
42
|
+
await cur.executemany(texto, data)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
print(texto)
|
|
45
|
+
print(e)
|
|
46
|
+
raise
|
|
47
|
+
|
|
48
|
+
async def consultar(self, consulta: str, params=None, as_dict: bool = None):
|
|
49
|
+
async with self._pool.acquire() as conn:
|
|
50
|
+
async with conn.cursor() as cur:
|
|
51
|
+
await cur.execute(consulta, params)
|
|
52
|
+
if (as_dict is None and self.as_dict) or as_dict:
|
|
53
|
+
columns = [col[0] for col in cur.description]
|
|
54
|
+
rows = await cur.fetchall()
|
|
55
|
+
return [dict(zip(columns, row)) for row in rows]
|
|
56
|
+
else:
|
|
57
|
+
return await cur.fetchall()
|