cloudoll 2.3.0__tar.gz → 2.3.2__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.
- {cloudoll-2.3.0 → cloudoll-2.3.2}/PKG-INFO +1 -1
- cloudoll-2.3.2/cloudoll/__init__.py +1 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/__init__.py +24 -79
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/base.py +3 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/model.py +7 -2
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/__init__.py +2 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/PKG-INFO +1 -1
- cloudoll-2.3.0/cloudoll/__init__.py +0 -1
- {cloudoll-2.3.0 → cloudoll-2.3.2}/LICENSE +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/README.md +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/__main__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/cli.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/error/__init__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/error/errors.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/logging/__init__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/mail/__init__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/mail/smtp.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/err.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/field.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/mysql.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/parse.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/orm/postgres.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/robot/__init__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/robot/dingtalk.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/robot/feishu.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/robot/slack.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/__init__.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/cli_main.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/common.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/m2d.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/patch_loop.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/snowflake.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/utils/watch.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/core.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/exception.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/html.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/http.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/jwt.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll/web/settings.py +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/SOURCES.txt +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/dependency_links.txt +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/entry_points.txt +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/requires.txt +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/cloudoll.egg-info/top_level.txt +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/setup.cfg +0 -0
- {cloudoll-2.3.0 → cloudoll-2.3.2}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.3.2"
|
|
@@ -10,9 +10,6 @@ from aiomysql import Pool as MYPool
|
|
|
10
10
|
import aiopg as pg
|
|
11
11
|
from aiopg.pool import Pool as PGPool
|
|
12
12
|
|
|
13
|
-
# import asyncpg as pg
|
|
14
|
-
# from asyncpg.pool import Pool as PGPool
|
|
15
|
-
|
|
16
13
|
__ALL__ = "create_engine"
|
|
17
14
|
|
|
18
15
|
|
|
@@ -55,65 +52,6 @@ class Postgres(MeteBase):
|
|
|
55
52
|
def __call__(self, *args: Any, **kwds: Any) -> Any:
|
|
56
53
|
self.__init__(*args, **kwds)
|
|
57
54
|
|
|
58
|
-
# async def query(self, sql, params=None, query_type: QueryTypes = 2, size: int = 10):
|
|
59
|
-
# sql = sql.replace("?", "%s").replace("`", "")
|
|
60
|
-
# print_info("sql", sql, params)
|
|
61
|
-
# if not self.pool:
|
|
62
|
-
# raise ValueError("must be create_engine first.")
|
|
63
|
-
# if self.pool._closing or self.pool._closed:
|
|
64
|
-
# return None
|
|
65
|
-
|
|
66
|
-
# # async with self.pool.acquire() as conn:
|
|
67
|
-
# async with self.pool.acquire() as conn:
|
|
68
|
-
# # current_cursor = getattr(cursor, 'lastrowid', None)
|
|
69
|
-
# if (
|
|
70
|
-
# query_type == QueryTypes.CREATEBATCH
|
|
71
|
-
# or query_type == QueryTypes.UPDATEBATCH
|
|
72
|
-
# ):
|
|
73
|
-
# result = await conn.executemany(sql, params) # aiopg don't support executemany
|
|
74
|
-
# else:
|
|
75
|
-
# result = await conn.execute(sql, params)
|
|
76
|
-
|
|
77
|
-
# # result = None
|
|
78
|
-
|
|
79
|
-
# return result
|
|
80
|
-
|
|
81
|
-
# if query_type == QueryTypes.ALL:
|
|
82
|
-
# columns = [desc[0] for desc in cursor.description]
|
|
83
|
-
# rows = await cursor.fetchall()
|
|
84
|
-
# result = [dict(zip(columns, row)) for row in rows]
|
|
85
|
-
# return result
|
|
86
|
-
# elif query_type == QueryTypes.ONE:
|
|
87
|
-
# columns = [desc[0] for desc in cursor.description]
|
|
88
|
-
# row = await cursor.fetchone()
|
|
89
|
-
# # print("rows_reuslt", rows)
|
|
90
|
-
# result = dict(zip(columns, row)) if row else {}
|
|
91
|
-
# return result
|
|
92
|
-
# elif query_type == QueryTypes.MANY:
|
|
93
|
-
# columns = [desc[0] for desc in cursor.description]
|
|
94
|
-
# rows = await cursor.fetchmany(size)
|
|
95
|
-
# result = [dict(zip(columns, row)) for row in rows]
|
|
96
|
-
# return result
|
|
97
|
-
# elif query_type == QueryTypes.COUNT:
|
|
98
|
-
# rs = await cursor.fetchone()
|
|
99
|
-
# return rs[0] if row else 0
|
|
100
|
-
# elif query_type == QueryTypes.CREATE:
|
|
101
|
-
# result = cursor.rowcount > 0
|
|
102
|
-
# id = cursor.lastrowid
|
|
103
|
-
# return result, id
|
|
104
|
-
# elif query_type == QueryTypes.CREATEBATCH:
|
|
105
|
-
# count = cursor.rowcount
|
|
106
|
-
# id = cursor.lastrowid
|
|
107
|
-
# return count, id
|
|
108
|
-
# elif query_type == QueryTypes.UPDATE:
|
|
109
|
-
# return cursor.rowcount > 0
|
|
110
|
-
# elif query_type == QueryTypes.UPDATEBATCH:
|
|
111
|
-
# return cursor.rowcount
|
|
112
|
-
# elif query_type == QueryTypes.DELETE:
|
|
113
|
-
# return cursor.rowcount > 0
|
|
114
|
-
|
|
115
|
-
# self.pool.release(cursor)
|
|
116
|
-
|
|
117
55
|
async def query(self, sql, params=None, query_type: QueryTypes = 2, size: int = 10):
|
|
118
56
|
sql = sql.replace("?", "%s").replace("`", '"')
|
|
119
57
|
if not self.pool:
|
|
@@ -132,7 +70,7 @@ class Postgres(MeteBase):
|
|
|
132
70
|
or query_type == QueryTypes.UPDATEBATCH
|
|
133
71
|
):
|
|
134
72
|
# aiopg don't support executemany
|
|
135
|
-
|
|
73
|
+
raise RuntimeError("postgres don't support executemany")
|
|
136
74
|
else:
|
|
137
75
|
await cursor.execute(sql, params)
|
|
138
76
|
|
|
@@ -146,7 +84,6 @@ class Postgres(MeteBase):
|
|
|
146
84
|
elif query_type == QueryTypes.ONE:
|
|
147
85
|
columns = [desc[0] for desc in cursor.description]
|
|
148
86
|
row = await cursor.fetchone()
|
|
149
|
-
# print("rows_reuslt", rows)
|
|
150
87
|
result = dict(zip(columns, row)) if row else {}
|
|
151
88
|
return result
|
|
152
89
|
elif query_type == QueryTypes.MANY:
|
|
@@ -155,8 +92,16 @@ class Postgres(MeteBase):
|
|
|
155
92
|
result = [dict(zip(columns, row)) for row in rows]
|
|
156
93
|
return result
|
|
157
94
|
elif query_type == QueryTypes.COUNT:
|
|
158
|
-
|
|
159
|
-
|
|
95
|
+
result = await cursor.fetchone()
|
|
96
|
+
count = 0
|
|
97
|
+
if rows is None:
|
|
98
|
+
return count
|
|
99
|
+
for row in rows:
|
|
100
|
+
count = rows[row]
|
|
101
|
+
return count
|
|
102
|
+
elif query_type == QueryTypes.GROUP_COUNT:
|
|
103
|
+
result = await cursor.fetchall()
|
|
104
|
+
return 0 if not result else len(result)
|
|
160
105
|
elif query_type == QueryTypes.CREATE:
|
|
161
106
|
result = cursor.rowcount > 0
|
|
162
107
|
id = cursor.lastrowid
|
|
@@ -182,13 +127,13 @@ class Postgres(MeteBase):
|
|
|
182
127
|
password = (str(kw.get("password", "")),)
|
|
183
128
|
db = (kw.get("db"),)
|
|
184
129
|
dsn = f"dbname={db[0]} user={user[0]} password={password[0]} host={host[0]} port={port[0]}" # aiopg
|
|
185
|
-
# dsn = f"postgres://{user[0]}:{password[0]}@{host[0]}:{port[0]}/{db[0]}" #asyncpg
|
|
130
|
+
# dsn = f"postgres://{user[0]}:{password[0]}@{host[0]}:{port[0]}/{db[0]}" # asyncpg
|
|
186
131
|
self.pool = await pg.create_pool(
|
|
187
132
|
dsn=dsn,
|
|
188
133
|
timeout=kw.get("timeout"),
|
|
189
134
|
echo=kw.get("echo", False), # aiopg
|
|
190
|
-
# max_size=kw.get("maxsize", 10), #asyncpg
|
|
191
|
-
# min_size=kw.get("minsize", 5), #asyncpg
|
|
135
|
+
# max_size=kw.get("maxsize", 10), # asyncpg
|
|
136
|
+
# min_size=kw.get("minsize", 5), # asyncpg
|
|
192
137
|
maxsize=kw.get("maxsize", 10), # aiopg
|
|
193
138
|
minsize=kw.get("minsize", 5), # aiopg
|
|
194
139
|
)
|
|
@@ -246,11 +191,7 @@ class Mysql(MeteBase):
|
|
|
246
191
|
else:
|
|
247
192
|
await cursor.execute(sql, params)
|
|
248
193
|
|
|
249
|
-
# if query_type.value > 4:
|
|
250
|
-
# if self.driver == "mysql":
|
|
251
194
|
await conn.commit()
|
|
252
|
-
# elif self.driver == "postgres":
|
|
253
|
-
# columns = [desc[0] for desc in cursor.description]
|
|
254
195
|
|
|
255
196
|
if query_type == QueryTypes.ALL:
|
|
256
197
|
return await cursor.fetchall()
|
|
@@ -259,11 +200,16 @@ class Mysql(MeteBase):
|
|
|
259
200
|
elif query_type == QueryTypes.MANY:
|
|
260
201
|
return await cursor.fetchmany(size)
|
|
261
202
|
elif query_type == QueryTypes.COUNT:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
203
|
+
rows = await cursor.fetchone()
|
|
204
|
+
count = 0
|
|
205
|
+
if rows is None:
|
|
206
|
+
return count
|
|
207
|
+
for row in rows:
|
|
208
|
+
count = rows[row]
|
|
209
|
+
return count
|
|
210
|
+
elif query_type == QueryTypes.GROUP_COUNT:
|
|
211
|
+
result = await cursor.fetchall()
|
|
212
|
+
return 0 if not result else len(result)
|
|
267
213
|
elif query_type == QueryTypes.CREATE:
|
|
268
214
|
result = cursor.rowcount > 0
|
|
269
215
|
id = cursor.lastrowid
|
|
@@ -299,7 +245,6 @@ class Mysql(MeteBase):
|
|
|
299
245
|
)
|
|
300
246
|
print_info(f"Database connection successfuly for mysql/{kw.get('db')}.")
|
|
301
247
|
except Exception as e:
|
|
302
|
-
# print(e)
|
|
303
248
|
# print(traceback.format_exc())
|
|
304
249
|
print_error(
|
|
305
250
|
f"Database connection failed,the instance : mysql/{kw.get('db')}"
|
|
@@ -12,6 +12,7 @@ class QueryTypes(Enum):
|
|
|
12
12
|
DELETE = 7
|
|
13
13
|
CREATEBATCH = 8
|
|
14
14
|
UPDATEBATCH = 9
|
|
15
|
+
GROUP_COUNT = 10
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class MeteBase:
|
|
@@ -60,6 +61,8 @@ class MeteBase:
|
|
|
60
61
|
|
|
61
62
|
async def count(self, sql, params):
|
|
62
63
|
return await self.query(sql, params, QueryTypes.COUNT)
|
|
64
|
+
async def group_count(self, sql, params):
|
|
65
|
+
return await self.query(sql, params, QueryTypes.GROUP_COUNT)
|
|
63
66
|
|
|
64
67
|
async def update(self, sql, params):
|
|
65
68
|
return await self.query(sql, params, QueryTypes.UPDATE)
|
|
@@ -228,7 +228,9 @@ class Model(metaclass=ModelMetaclass):
|
|
|
228
228
|
for item in args:
|
|
229
229
|
if isinstance(item, Model):
|
|
230
230
|
for k in item.__dict__:
|
|
231
|
-
if (
|
|
231
|
+
if (
|
|
232
|
+
action == "u" and item[k].value is not None
|
|
233
|
+
) or action == "i":
|
|
232
234
|
data[k] = item[k]
|
|
233
235
|
|
|
234
236
|
else: # for object
|
|
@@ -458,10 +460,13 @@ class Model(metaclass=ModelMetaclass):
|
|
|
458
460
|
cls = copy.deepcopy(self)
|
|
459
461
|
JOIN = cls._literal("LEFT JOIN", __join__)
|
|
460
462
|
WHERE = cls._literal("WHERE", __where__)
|
|
461
|
-
|
|
463
|
+
GROUPBY = self._literal("GROUP BY", self.__group_by__)
|
|
464
|
+
aft = " ".join([JOIN, WHERE, GROUPBY])
|
|
462
465
|
sql = f"SELECT COUNT(*) FROM {cls.__table__} {aft}"
|
|
463
466
|
args = cls.__params__
|
|
464
467
|
sql = self._exchange_sql(sql)
|
|
468
|
+
if GROUPBY is not None and GROUPBY != "":
|
|
469
|
+
return await cls.__pool__.group_count(sql, args)
|
|
465
470
|
return await cls.__pool__.count(sql, args)
|
|
466
471
|
|
|
467
472
|
|
|
@@ -23,6 +23,7 @@ from .core import (
|
|
|
23
23
|
render_json,
|
|
24
24
|
render_error,
|
|
25
25
|
render_view,
|
|
26
|
+
render,
|
|
26
27
|
middleware,
|
|
27
28
|
redirect,
|
|
28
29
|
)
|
|
@@ -44,6 +45,7 @@ __all__: Tuple[str, ...] = (
|
|
|
44
45
|
"render_json",
|
|
45
46
|
"render_error",
|
|
46
47
|
"render_view",
|
|
48
|
+
"render",
|
|
47
49
|
"middleware",
|
|
48
50
|
"redirect",
|
|
49
51
|
"jwt",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.3.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|